Question

I want to load an package over composer.

I created the composer.json in the root level of the package. Looks like this:

{
"name": "platform/pollbundle",
"description": {
  "text" :   "This is the poll bundle"
},
"type": "symfony-bundle",
"authors": [
    {
        "name": "NAME",
        "email": "EMAIL"
    }
],
"autoload": {
    "psr-0": {
        "Platform\\Bundle\\PollBundle": ""
    }
},
"extra": {
    "servicePath": "odwawdadwa",
    "branch-alias": {
        "dev-master": "0.1.x-dev"
    }
}

}

For handling the data i start to write an scripthandler which call this function:

$event->getComposer()->getPackage()->getDescription();

After the install of course. The output of this function is the description text from the project composer.json :

The "Symfony Standard Edition" distribution

But what i want is the description text of the package (This is the poll bundle).

So my question is: how do i get it?

Was it helpful?

Solution

I assume you are now registered to the post-install event. That only applies to the root package. You should register to the post-package-install event instead.

Using this event, you get a PackageEvent instance, which gives you access to the current operation (using PackageEvent#getOperation()). The operation contains the current installed package:

use Composer\Script\PackageEvent;

class YourInstaller
{
    public static function postPackageUpdate(PackageEvent $event)
    {
        $packageName = $event->getOperation()->getPackage()->getName();

        // ... do something great
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top