Reputation: 2955
Whenever I do composer.phar install it clears the dev cache of Symfony.
Is there some way I can make it clear another environments cache, like say production? I know I can always run app/console cache:clear --env=prod. But I would like Composer to handle that after grabbing the dependencies.
Upvotes: 5
Views: 7710
Reputation: 17166
In your composer.json you will find a section "scripts", which should look something like this:
"scripts": {
"post-install-cmd": [
"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": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
}
As you can see all commands are stored in a single file, Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache() is what you are looking for.
As these scripts are meant to be run without user intervention, you are not intended to add arguments. But, you can easily add your own scripts or replace the existing ones.
edit: The last paragraph I should rephrase. You can have arguments, but they are statically defined in your composer.json. The values defined in the extra-section, e.g. "symfony-web-dir", are arguments used by the ScriptHandler. They can be retrieved from composer's CommandEvent as can be seen in ScriptHandler::getOptions(). So you could for example define an array of environments to be cleared on each install/update in "extra"
, retrieve it in your script and then call the clear cache-command for each specified environment. It might be possible to provide the values via environment variables which probably makes more sense in your scenario, but this will require digging into composer as the config does not explain how to for example override values in the extra-section.
Upvotes: 6
Reputation: 1795
I found this answer while looking for how to set the assets symlink option after a composer update.
You can do it adding a "symfony-assets-install" entry in the extra node of your composer.json file
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "symlink"
}
src: Updating Vendors
Upvotes: 1