Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer.phar Symfony clear cache

Tags:

symfony

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.

like image 289
James Cowhen Avatar asked Feb 20 '13 18:02

James Cowhen


1 Answers

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.

like image 55
dbrumann Avatar answered Sep 19 '22 19:09

dbrumann