{"action":"created","issue":{"url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/16","repository_url":"https://api.github.com/repos/Becklyn/BecklynRadBundle","labels_url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/16/comments","events_url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/16/events","html_url":"https://github.com/Becklyn/BecklynRadBundle/issues/16","id":177366645,"number":16,"title":"Provide a base class for CompilerPasses that automate common workflows","user":{"login":"cH40z-Lord","id":439899,"avatar_url":"https://avatars.githubusercontent.com/u/439899?v=3","gravatar_id":"","url":"https://api.github.com/users/cH40z-Lord","html_url":"https://github.com/cH40z-Lord","followers_url":"https://api.github.com/users/cH40z-Lord/followers","following_url":"https://api.github.com/users/cH40z-Lord/following{/other_user}","gists_url":"https://api.github.com/users/cH40z-Lord/gists{/gist_id}","starred_url":"https://api.github.com/users/cH40z-Lord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cH40z-Lord/subscriptions","organizations_url":"https://api.github.com/users/cH40z-Lord/orgs","repos_url":"https://api.github.com/users/cH40z-Lord/repos","events_url":"https://api.github.com/users/cH40z-Lord/events{/privacy}","received_events_url":"https://api.github.com/users/cH40z-Lord/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-16T08:04:35Z","updated_at":"2016-09-16T17:37:09Z","closed_at":null,"body":"Just like our custom `Bundle`, `BundleConfiguration` and `BundleExtension` it'd enhance productivity and reduce code duplication if we can provide a common `CompilerPass` class that does something along the line like this:\r\n\r\n```php\r\nclass RandomCompilerPass implements CompilerPassInterface\r\n{\r\n    /**\r\n     * @inheritdoc\r\n     */\r\n    public function process (ContainerBuilder $container)\r\n    {\r\n        // collect all registered AppSettingsProviders\r\n        $this->collectTagsAndAddToService($container, \"service.tag\", \"service.collection.something\", \"collectMethodName\");\r\n    }\r\n\r\n\r\n    /**\r\n     * Collects the services with a given tag (and id) and adds them to a collection\r\n     *\r\n     * @param ContainerBuilder $container\r\n     * @param string           $tag\r\n     * @param string           $collectionTag\r\n     * @param string           $collectionMethod\r\n     */\r\n    private function collectTagsAndAddToService (ContainerBuilder $container, $tag, $collectionTag, $collectionMethod)\r\n    {\r\n        $taggedServices = $container->findTaggedServiceIds($tag);\r\n        $handlerCollectionDefinition = $container->getDefinition($collectionTag);\r\n\r\n        foreach ($taggedServices as $serviceId => $tags)\r\n        {\r\n            $handlerCollectionDefinition->addMethodCall($collectionMethod, [new Reference($serviceId)]);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nIn every Compiler Pass we're duplicating the logic to collect and register tagged services with another service. \r\n\r\nPersonally I'd at least provide two implementations for the `collectTagsAndAddToService` method. One as the example above and one for the cases where we want to collect services that may have multiple tags. One example for that can be seen at http://symfony.com/doc/current/service_container/tags.html#adding-additional-attributes-on-tags"},"comment":{"url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/comments/247661132","html_url":"https://github.com/Becklyn/BecklynRadBundle/issues/16#issuecomment-247661132","issue_url":"https://api.github.com/repos/Becklyn/BecklynRadBundle/issues/16","id":247661132,"user":{"login":"cH40z-Lord","id":439899,"avatar_url":"https://avatars.githubusercontent.com/u/439899?v=3","gravatar_id":"","url":"https://api.github.com/users/cH40z-Lord","html_url":"https://github.com/cH40z-Lord","followers_url":"https://api.github.com/users/cH40z-Lord/followers","following_url":"https://api.github.com/users/cH40z-Lord/following{/other_user}","gists_url":"https://api.github.com/users/cH40z-Lord/gists{/gist_id}","starred_url":"https://api.github.com/users/cH40z-Lord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cH40z-Lord/subscriptions","organizations_url":"https://api.github.com/users/cH40z-Lord/orgs","repos_url":"https://api.github.com/users/cH40z-Lord/repos","events_url":"https://api.github.com/users/cH40z-Lord/events{/privacy}","received_events_url":"https://api.github.com/users/cH40z-Lord/received_events","type":"User","site_admin":false},"created_at":"2016-09-16T17:37:08Z","updated_at":"2016-09-16T17:37:08Z","body":"Would work as well, yeah, however I'm not so entirely sure how much we've saved then since we'd have to call the methods manually instead of letting the RadBundle do it for us.\r\n\r\nI'm thinking about some arbitrary mapping like this\r\n\r\n```php\r\n[\r\n    \"service.tag\" => [\"service.collection\", \"registerTaggedService\"],\r\n    \"another_service.tag\" => [\"another_service.collection\", \"registerSomeAwesomeService\"],\r\n    \"manual.tagging\" => [function (ContainerBuilder $container, $serviceId, $serviceTags) { /** do some manual work with the tagged service */ }],\r\n]\r\n```\r\n\r\nwhich is returned by a getter, which would be the only thing that you'd have to implement for the entire `CompilerPass`. Still trivial to implement, both from our side (the implementors) and the using developers, and yet flexible enough to do whatever you want.\r\n\r\nUltimately you could still roll your own `process` method and call a `protected` base method if you want."}}
{"actor":{"display_login":"cH40z-Lord"}}