{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/18563","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/18563/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/18563/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/18563/events","html_url":"https://github.com/symfony/symfony/issues/18563","id":148840014,"number":18563,"title":"Serializer and Validator mappings don't use Bundle#getPath()","user":{"login":"WouterJ","id":749025,"avatar_url":"https://avatars.githubusercontent.com/u/749025?v=3","gravatar_id":"","url":"https://api.github.com/users/WouterJ","html_url":"https://github.com/WouterJ","followers_url":"https://api.github.com/users/WouterJ/followers","following_url":"https://api.github.com/users/WouterJ/following{/other_user}","gists_url":"https://api.github.com/users/WouterJ/gists{/gist_id}","starred_url":"https://api.github.com/users/WouterJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WouterJ/subscriptions","organizations_url":"https://api.github.com/users/WouterJ/orgs","repos_url":"https://api.github.com/users/WouterJ/repos","events_url":"https://api.github.com/users/WouterJ/events{/privacy}","received_events_url":"https://api.github.com/users/WouterJ/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-16T10:25:00Z","updated_at":"2016-04-18T12:58:46Z","closed_at":null,"body":"Description\r\n---\r\n\r\nThe bundle class has a `getPath()` method, allowing you to override the path of the bundle. However, inside the FrameworkExtension, `$reflection->getFileName()` is used to get the path to the bundle. This means that `getPath()` is ignored.\r\n\r\nUse-case\r\n---\r\n\r\nIn my case, my bundle directory structure looks like:\r\n```php\r\nMyBundle/\r\n  src/\r\n    MyBundle.php\r\n    ...\r\n  Resources/\r\n    config/\r\n      serializer.yml\r\n      validator.yml\r\n```\r\n\r\nIn the `MyBundle` class, I override `getPath()` to return `MyBundle/`. This way, I would expect the serializer and validator configuration to be loaded. However, since they use reflection they're looking for `MyBundle/src/Resources/config/serializer.yml`.\r\n\r\nPossible Solution\r\n---\r\n\r\nThe auto-discovery of config files should be moved to a compiler pass. These have access to the bundle class instance (instead of FQCN) and can call `->getPath()` on this instance instead of simulating the default behaviour of this method."},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/211370366","html_url":"https://github.com/symfony/symfony/issues/18563#issuecomment-211370366","issue_url":"https://api.github.com/repos/symfony/symfony/issues/18563","id":211370366,"user":{"login":"chalasr","id":7502063,"avatar_url":"https://avatars.githubusercontent.com/u/7502063?v=3","gravatar_id":"","url":"https://api.github.com/users/chalasr","html_url":"https://github.com/chalasr","followers_url":"https://api.github.com/users/chalasr/followers","following_url":"https://api.github.com/users/chalasr/following{/other_user}","gists_url":"https://api.github.com/users/chalasr/gists{/gist_id}","starred_url":"https://api.github.com/users/chalasr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chalasr/subscriptions","organizations_url":"https://api.github.com/users/chalasr/orgs","repos_url":"https://api.github.com/users/chalasr/repos","events_url":"https://api.github.com/users/chalasr/events{/privacy}","received_events_url":"https://api.github.com/users/chalasr/received_events","type":"User","site_admin":false},"created_at":"2016-04-18T12:58:46Z","updated_at":"2016-04-18T12:58:46Z","body":"@iltar @WouterJ To get around this I added the following method to the FrameworkExtension:\r\n\r\n```php\r\nprivate function getBundlePath($fqcn)\r\n{\r\n    $reflection = new \\ReflectionClass($fqcn);\r\n    $getPathReflection = new \\ReflectionMethod($fqcn, 'getPath');\r\n    $path = $getPathReflection->invoke(new $fqcn()) ?: dirname($reflection->getFilename());\r\n\r\n    return $path;\r\n}\r\n```\r\n\r\nThen I use it like\r\n\r\n```php\r\n$dirname = $this->getBundlePath($class);\r\n````\r\n\r\nInstead of \r\n\r\n```php\r\n$reflection = new \\ReflectionClass($fqcn);\r\n$dirname = dirname($reflection->getFilename());\r\n```\r\n\r\nThe logic is repeated 3 times in the extension.\r\nWhat do you think about this?\r\n\r\nIt would be cleaner in a compiler pass using the instances directly, but I can't access `$container->get('kernel')->getBundles()` because the service is synthetic, same in the extension (tried with the SerializerPass for instance). I would like to have your suggestions.\r\n\r\nOtherwise, if my workaround sounds good for you, should I submit a patch on master?\r\nThank's."}}