{"action":"created","issue":{"url":"https://api.github.com/repos/composer/composer/issues/6315","repository_url":"https://api.github.com/repos/composer/composer","labels_url":"https://api.github.com/repos/composer/composer/issues/6315/labels{/name}","comments_url":"https://api.github.com/repos/composer/composer/issues/6315/comments","events_url":"https://api.github.com/repos/composer/composer/issues/6315/events","html_url":"https://github.com/composer/composer/issues/6315","id":218649299,"number":6315,"title":"Plugins vs Scripts. Autoload issue.","user":{"login":"neomerx","id":10420662,"avatar_url":"https://avatars3.githubusercontent.com/u/10420662?v=3","gravatar_id":"","url":"https://api.github.com/users/neomerx","html_url":"https://github.com/neomerx","followers_url":"https://api.github.com/users/neomerx/followers","following_url":"https://api.github.com/users/neomerx/following{/other_user}","gists_url":"https://api.github.com/users/neomerx/gists{/gist_id}","starred_url":"https://api.github.com/users/neomerx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neomerx/subscriptions","organizations_url":"https://api.github.com/users/neomerx/orgs","repos_url":"https://api.github.com/users/neomerx/repos","events_url":"https://api.github.com/users/neomerx/events{/privacy}","received_events_url":"https://api.github.com/users/neomerx/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-04-01T00:21:44Z","updated_at":"2017-04-03T09:15:38Z","closed_at":"2017-04-03T08:15:13Z","body":"[Scripts](https://getcomposer.org/doc/articles/scripts.md#defining-scripts) defined in `composer.json` enjoy application code and external dependencies loaded on execution while [plugins](https://getcomposer.org/doc/articles/plugins.md) don't. Thus the following code works in scripts but not in plugins\r\n```php\r\n    $appClass = '\\\\App\\\\Application';\r\n    $stuff = (new $appClass())->getSomeGreatStuff();\r\n```\r\nWhat is the proper way to make it work in plugins?\r\n\r\nI tried  the following `PluginInterface::activate` (basically load `autoload.php` as we usually do)\r\n```php\r\npublic function activate(Composer $composer, IOInterface $ioInterface)\r\n{\r\n    // use application auto loader otherwise no app classes will be visible for us\r\n    $autoLoaderPath = $composer->getConfig()->get('vendor-dir') . DIRECTORY_SEPARATOR . 'autoload.php';\r\n    if (file_exists($autoLoaderPath) === true) {\r\n        require_once $autoLoaderPath;\r\n    }\r\n}\r\n```\r\nAnd the command works. BUT\r\n\r\nWhen I run this command:\r\n\r\n```\r\ncomposer list -vvv\r\n```\r\n\r\nI get the following output:\r\n\r\n```\r\n\r\nComposer version 1.4.1 2017-03-10 09:29:45\r\n\r\n        ...\r\n\r\n[Symfony\\Component\\Debug\\Exception\\FatalThrowableError]\r\nCall to undefined method Composer\\Command\\ScriptAliasCommand::isHidden()\r\n\r\n\r\nException trace:\r\n() at /..../vendor/symfony/console/Descriptor/ApplicationDescription.php:115\r\nSymfony\\Component\\Console\\Descriptor\\ApplicationDescription->inspectApplication() at /..../vendor/symfony/console/Descriptor/ApplicationDescription.php:82\r\nSymfony\\Component\\Console\\Descriptor\\ApplicationDescription->getCommands() at /..../vendor/symfony/console/Descriptor/TextDescriptor.php:194\r\nSymfony\\Component\\Console\\Descriptor\\TextDescriptor->describeApplication() at /..../vendor/symfony/console/Descriptor/Descriptor.php:55\r\nSymfony\\Component\\Console\\Descriptor\\Descriptor->describe() at /..../vendor/symfony/console/Helper/DescriptorHelper.php:72\r\nSymfony\\Component\\Console\\Helper\\DescriptorHelper->describe() at phar:///usr/bin/composer/vendor/symfony/console/Command/ListCommand.php:81\r\nSymfony\\Component\\Console\\Command\\ListCommand->execute() at phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php:267\r\nSymfony\\Component\\Console\\Command\\Command->run() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:846\r\nSymfony\\Component\\Console\\Application->doRunCommand() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:191\r\nSymfony\\Component\\Console\\Application->doRun() at phar:///usr/bin/composer/src/Composer/Console/Application.php:227\r\nComposer\\Console\\Application->doRun() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:122\r\nSymfony\\Component\\Console\\Application->run() at phar:///usr/bin/composer/src/Composer/Console/Application.php:100\r\nComposer\\Console\\Application->run() at phar:///usr/bin/composer/bin/composer:54\r\nrequire() at /usr/bin/composer:24\r\n```\r\n\r\nAs you can see some of the classes are taken from `vendor` and some from `phar`.\r\n\r\nSo back to my question. What is the proper way to get application classes in plugins just like in scripts?"},"comment":{"url":"https://api.github.com/repos/composer/composer/issues/comments/291089920","html_url":"https://github.com/composer/composer/issues/6315#issuecomment-291089920","issue_url":"https://api.github.com/repos/composer/composer/issues/6315","id":291089920,"user":{"login":"stof","id":439401,"avatar_url":"https://avatars3.githubusercontent.com/u/439401?v=3","gravatar_id":"","url":"https://api.github.com/users/stof","html_url":"https://github.com/stof","followers_url":"https://api.github.com/users/stof/followers","following_url":"https://api.github.com/users/stof/following{/other_user}","gists_url":"https://api.github.com/users/stof/gists{/gist_id}","starred_url":"https://api.github.com/users/stof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stof/subscriptions","organizations_url":"https://api.github.com/users/stof/orgs","repos_url":"https://api.github.com/users/stof/repos","events_url":"https://api.github.com/users/stof/events{/privacy}","received_events_url":"https://api.github.com/users/stof/received_events","type":"User","site_admin":false},"created_at":"2017-04-03T09:15:38Z","updated_at":"2017-04-03T09:15:38Z","body":"Plugins are running at a time where the application code is not yet available (other dependencies are not yet installed). So calling your application would not work"}}
{"actor":{"display_login":"stof"}}