Create an event / plugin for Composer [closed]

1

I've developed a WebServer Portable and I'm also creating a portable console to use Composer.

I have a problem. I need to create a plugin for Composer.

I need you to download any package with Composer, it will edit the compositor.json "scripts" of that package, so that it works on the portable console.

When you download Laravel, for example:

original composer.json:

{
    "name": "laravel/laravel",
    ...
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        ...
    },
    ...
}

composer.json edited by the plugin:

{
    "name": "laravel/laravel",
    ...
    "scripts": {
        "post-root-package-install": [
            "F:/portable_php_path/php.exe -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        ...
    },
    ...
}
  • Note that a physical path was generated for php.exe, because in the portable version, it could be in any path.

(My question is about creating the plugin for Composer. I have no problem editing the compositor.json with PHP)

I read the tutorial to create a plugin on the Composer site, but I was confused. ( link )

If you have another way of doing this, it's also interesting. I accept other suggestions and ideas.

Thanks to anyone who can help.

    
asked by anonymous 26.07.2017 / 20:26

1 answer

1

When you run the composer via the command line, PHP is probably already in the % wizard variable, so it is not necessary to pass the entire PHP path:

"F:/portable_php_path/php.exe -r \"file_exists('.env') || copy('.env.example', '.env');\""

Just call it like this:

 "php -r \"file_exists('.env') || copy('.env.example', '.env');\""

This is because the composer is written in PHP and depends on it, so the CLI interface will always be available when using composer

To create composite PACKAGES see this answer:

Of course you can use other types of repositories, such as Bitbucket and even repositories, but if so, specify that it will be easier to explain in the response.

PSR-0, PSR-4 and autoload

I recommend that before learning how to create a composer package to learn about PSR-4 and PSR-0 (this is deprecated, but there are still packages that use it):

27.07.2017 / 05:01