Symfony2 : Replace parameters.php for PAAS (Heroku) - symfony

I use Symfony2 App. I would like to replace parameters.php auto-generated by parameters.heroku.php to have environment variables. This file must be replaced before Symfony2 actions (dumping assets, database update, etc).
What are best practices please ?
I tried to put this action in the composer.json, but this action will launch at each update composing, even outside of Heroku.
My actual composer.json :
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": {
"": "src/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Evolunium/IvoryCKEditorBundle"
}
],
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.7",
...
},
"scripts": {
"post-install-cmd": [
"./composer_script.sh",
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"cp parameters.heroku.php.dist app/config/parameters.php", // Correct ?
"./composer_script.sh",
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"compile": [
"rm web/app_dev.php",
"app/console assetic:dump"
]
},
"config": {
"bin-dir": "bin",
"component-dir": "web/components",
"component-baseurl": "/components"
},
"minimum-stability": "stable",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
},
"config": {
"bin-dir": "bin",
"component-dir": "web/components",
"component-baseurl": "/components"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "~1.0#dev"
}
}
}
Regards,
Johnny

Related

Ignore packagist.org and specify path for one bundle

I modified a symfony 4 bundle to fix some bug. I now want to deploy my project through https://deployer.org/.
So I added this bundle not ignored in the .gitignore so that the folder of the bundle with my modifications is available on my github repo.
When executing the "deploy" command of deployer, it executes the command "/composer.phar install --verbose --prefer -dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest" so that the folder of my bundle edit is overwritten by the original bundle folder from https://packagist.org/.
I would like to modify my composer.json to define the path of my modified bundle and that it is not overwritten.
Here is what I tried in the composer.json of my main project:
{
"type": "my-project",
"license": "proprietary",
"repositories": [
{
"type": "path",
"url": "/vendor/my/modifiedBundle",
"packagist.org": false,
}
],
"require": {
......
"my/modifiedBundle": "0.6.1",
......
},
"require-dev": {
.....
},
"config": {
"preferred-install": {
"my/modifiedBundle": "source",
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
....
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": true,
"require": "4.3.*"
}
}
}
Here is the composer.json of my modified bundle:
{
"name": "my/modifiedBundle",
"type": "symfony-bundle",
"license": "MIT",
"require": {
...
},
"require-dev": {
...
},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"my\\modifiedBundle\\": ""
}
},
"autoload-dev": {
"psr-4": {
"my\\modifiedBundle\\Tests\\": "tests/"
}
}
}
But after my modifications, the modified bundle is still overwritten by the original bundle, do you have any idea?
#Skros2 solved his problem on:
Fork the bundle to its own repository
Edit the fork
Refer his fork on his composer.jsonproject
how to refer a fork.
{
"repositories": [
{
"type": "git",
"url": "https://github.com/foobar/intermediate.git"
},
{
"type": "pear",
"url": "http://pear.foobar.repo",
"vendor-alias": "foobar"
}
],
"require": {
"foobar/TopLevelPackage1": "*",
"foobar/TopLevelPackage2": "*"
}
}

How to remove twbs folder in my Laravel project?

I don't know how to use twbs in my Laravel project. So how can I delete this folder?
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"twbs/bootstrap": "4.0.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
The good idea is to use composer remove command without updating all other packages:
composer remove twbs/bootstrap
Remove "twbs/bootstrap": "4.0.0" line from composer.json and then run command:
composer update
Run This command For Remove any package
composer remove twbs/bootstrap

Symfony fork a bundle

I forked this bundle "[egeloen/ivory-google-map][1]"
[1]: https://github.com/egeloen/ivory-google-map/ to this [repository][1]
[1]: https://github.com/spinoza123/ivory-google-map and i changed the original url in composer.json to my forked repository, but when i do composer update i have this error
[InvalidArgumentException]
Could not find a matching version of package spinoza123/google-map. Check the package spelling, your version constr
aint and that the package is available in a stability which matches your minimum-stability (stable).
Must i publish it in pakagist, if yes is it free and how to do that ?
my composer.json
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"autoload-dev": {
"psr-4": { "Tests\\": "tests/" },
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
}
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0",
"spinoza123/ivory-google-map": "dev-master"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"platform": {
"php": "5.5.9"
},
"sort-packages": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "3.4-dev"
}
}
}
Thanks
Use VCS in your composer.json
There are a few use cases for this. The most common one is maintaining your own fork of a third party library. If you are using a certain library for your project and you decide to change something in the library, you will want your project to use the patched version. If the library is on GitHub (this is the case most of the time), you can simply fork it there and push your changes to your fork.
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/spinoza123/ivory-google-map"
}
],
"require": {
"egeloen/ivory-google-map": "dev-master"
}
}

composer set a git repository as type component

I'm trying to install some external JS libraries located in Github in a SF2 project with composer.json.
composer.json:
{
"name": "myproject",
"license": "my project",
"type": "project",
"description": "my project",
"autoload": {
"psr-0": { "": "src/" }
},
"repositories": {
"medium-editor" : {
"type": "package",
"package": {
"name": "daviferreira/medium-editor",
"type": "component",
"version": "master",
"source": {
"url": "git://github.com/daviferreira/medium-editor.git",
"type": "git",
"reference": "master"
},
"extra": {
"component": {
"scripts": [
"dist/js/medium-editor.min.js"
],
"styles": [
"dist/css/medium-editor.min.css",
"dist/css/themes/*.min.css"
]
}
},
"require": {
"robloach/component-installer": "*"
}
}
},
"classList" : {
"type": "package",
"package": {
"name": "eligrey/classList.js",
"type": "component",
"version": "master",
"source": {
"url": "git://github.com/eligrey/classList.js.git",
"type": "git",
"reference": "master"
},
"extra": {
"component": {
"scripts": [
"classList.min.js"
]
}
},
"require": {
"robloach/component-installer": "*"
}
}
}
},
"require": {
...
"daviferreira/medium-editor" : "dev-master",
"eligrey/classList.js" : "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin",
"component-dir": "web/components"
},
"minimum-stability": "stable",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "symlink",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
}
}
}
The libraries are downloaded but...
I'm expecting that composer will create, with the "robloach/component-installer" dependency, a copy of the files specified in "extra" of the "component" type package to the "web/component" directory, but it doesn't.
What's wrong with my config? Thanks!
After reading more carefully the robloach plugin documentation, I've tried again and finally found a solution. The problem was that I probably had made a lot of "composer update" with different configs and was obliged to remove / reinstall the packages to make it work! So the original config post in the question is the good one...
I put it again to be sure!
"medium-editor" : {
"type": "package",
"package": {
"require": {
"robloach/component-installer": "*"
},
"name": "daviferreira/medium-editor",
"type": "component",
"version": "master",
"source": {
"url": "git://github.com/daviferreira/medium-editor.git",
"type": "git",
"reference": "master"
},
"extra": {
"component": {
"scripts": [
"dist/js/medium-editor.min.js"
],
"styles": [
"dist/css/medium-editor.min.css",
"dist/css/themes/*.min.css"
]
}
}
}
},
And for sure, don't forget to add the Robloach component in the "require" libraries:
"robloach/component-installer": "dev-master",
I would suggest to use bower for fetching frontend libraries. Composer was created for managing php libs dependencies. It is importand to separate this layers because it's the easiest solution to implement.
Try PHP Composer Asset Manager package with composer if the problem persist i think you should execute the command manualy:
app/console assets:install .

have composer install wordpress and symfony2

Using Composer, i am trying to get symfony2 installed in a directory, and wordpress in another.
Using info found here http://roots.io/using-composer-with-wordpress/ i figured i could just edit my sf2 composer.json and add the required info, but no luck.
Is this possible, or should i create another composer.json file in the subdirectory ?
For reference, here is the (simplified) json:
{
"repositories": [
{
"type": "package",
"package": {
"name": "wordpress",
"type": "webroot",
"version": "3.8",
"dist": {
"type": "zip",
"url": "https://github.com/WordPress/WordPress/archive/3.8.zip"
},
"require" : {
"fancyguy/webroot-installer": "1.0.0"
}
}
}
],
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"wordpress": "3.8",
"fancyguy/webroot-installer": "1.0.0"
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.4-dev"
},
"webroot-dir": "wp",
"webroot-package": "wordpress"
}
}
The error i get is:
symfony/framework-standard-edition 2.4.x-dev requires wordpress 3.8 -> no matching package found
Thanks for taking the time to read this !

Resources