Search code examples
symfonycomposer-phppost-updatepost-install

Symfony2 Composer post-install-cmd


I need to install an symfony2 bundle over the composer and do some stuff after the install process. So for the "stuff" after the install i add one line to the "post-install-cmd" in the composer.json

ServiceBundle\\Core\\Platform::registerService

and it calls the function, everything fine

    public static function registerService(Event $event) {
       //some stuff
       exit;
    }

The command I use:

php composer.phar update serviceplatform/bundles/poll

Now my question: Is it possible to get the name "serviceplatform/bundles/poll" or pass any arguments to the statement? I need the path from the bundle after the install.


Solution

  • extra node is what you're looking for - https://getcomposer.org/doc/04-schema.md#extra

    In your composer.json:

    "extra": {
        "your-parameter": "serviceplatform/bundles/poll"
    }
    

    Then, in your ServiceBundle\Core\Platform::registerService:

    public static function registerService(Event $event) 
    {
        $extras = $event->getComposer()->getPackage()->getExtra();
        $yourParameter = $extras['your-parameter'];
        //do your stuff
    }
    

    It should do the trick.