{"action":"created","issue":{"url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/78","labels_url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/78/comments","events_url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/78/events","html_url":"https://github.com/mitchellvanw/laravel-doctrine/issues/78","id":53357485,"number":78,"title":"Double class definitions when generating schema with files already autoloaded","user":{"login":"rizqidjamaluddin","id":1274731,"avatar_url":"https://avatars.githubusercontent.com/u/1274731?v=3","gravatar_id":"","url":"https://api.github.com/users/rizqidjamaluddin","html_url":"https://github.com/rizqidjamaluddin","followers_url":"https://api.github.com/users/rizqidjamaluddin/followers","following_url":"https://api.github.com/users/rizqidjamaluddin/following{/other_user}","gists_url":"https://api.github.com/users/rizqidjamaluddin/gists{/gist_id}","starred_url":"https://api.github.com/users/rizqidjamaluddin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rizqidjamaluddin/subscriptions","organizations_url":"https://api.github.com/users/rizqidjamaluddin/orgs","repos_url":"https://api.github.com/users/rizqidjamaluddin/repos","events_url":"https://api.github.com/users/rizqidjamaluddin/events{/privacy}","received_events_url":"https://api.github.com/users/rizqidjamaluddin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-01-05T01:57:31Z","updated_at":"2015-01-07T08:43:13Z","closed_at":"2015-01-05T02:12:44Z","body":"So doctrine's schema tool is meant to scan certain folders for files to parse as entities, and generate schemas thereof. A problem occurs when using commands such as `php artisan doctrine:schema:create` in an environment where the classes it scans are already loaded, in my case by service provider setups.\r\n\r\nFor instance, in doctrine.php:\r\n\r\n```\r\n    'metadata' => [\r\n        base_path('NS/Users')\r\n    ],\r\n```\r\n\r\nIf there exists a class `NS\\Users\\UserServiceProvider`, and it's included in the config service provider listing, this class is initiated by laravel as soon as the app is booted up. When doctrine goes through the files to parse for entities, the service provider is already loaded into PHP and PHP refuses the double declaration:\r\n\r\n```\r\n$ php artisan doctrine:schema:update\r\nChecking if database needs updating....\r\nPHP Fatal error:  Cannot redeclare class NS\\Users\\UserServiceProvider in /NS/Users/UserServiceProvider.php\r\n```\r\n\r\nOne cheap way to fix this is by moving entities into their own namespace, but this isn't very ideal (I would prefer to just use my namespace root instead of having to specify each subfolder) and isn't foolproof either; sometimes a service provider would autoload an entity as well, e.g. to provide an IoC binding. This would throw the error in any situation as long as the service provider was invoked.\r\n\r\nThe only real solution would be to execute the schema generation in some way such that other service providers aren't loaded, but this is likely out of the package's control.\r\n\r\nAm I missing a different obvious solution somewhere?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/comments/68993096","html_url":"https://github.com/mitchellvanw/laravel-doctrine/issues/78#issuecomment-68993096","issue_url":"https://api.github.com/repos/mitchellvanw/laravel-doctrine/issues/78","id":68993096,"user":{"login":"rizqidjamaluddin","id":1274731,"avatar_url":"https://avatars.githubusercontent.com/u/1274731?v=3","gravatar_id":"","url":"https://api.github.com/users/rizqidjamaluddin","html_url":"https://github.com/rizqidjamaluddin","followers_url":"https://api.github.com/users/rizqidjamaluddin/followers","following_url":"https://api.github.com/users/rizqidjamaluddin/following{/other_user}","gists_url":"https://api.github.com/users/rizqidjamaluddin/gists{/gist_id}","starred_url":"https://api.github.com/users/rizqidjamaluddin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rizqidjamaluddin/subscriptions","organizations_url":"https://api.github.com/users/rizqidjamaluddin/orgs","repos_url":"https://api.github.com/users/rizqidjamaluddin/repos","events_url":"https://api.github.com/users/rizqidjamaluddin/events{/privacy}","received_events_url":"https://api.github.com/users/rizqidjamaluddin/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T08:43:13Z","updated_at":"2015-01-07T08:43:13Z","body":"Okay, I found my actual problem. Schema tool uses `require_once`, so it's not supposed to double-load the same files. It turns out, my PSR-4 autoloading under composer.json was in _lowercase_:\r\n\r\n```\r\n        \"psr-4\": {\r\n            \"Acme\\\\\": \"acme\"\r\n        }\r\n```\r\n\r\nWhile the actual folder was properly uppercased (`Acme`). So composer did an initial load of `Acme\\Users\\UserServiceProvider` from `/acme/Users/UserServiceProvider` (lowercase because this was what was given in the composer.json file) - which properly resolved. Then the Schema Tool, in its file iteration, tried to `require_once /Acme/Users/UserServiceProvider` - which PHP though it _had not_ loaded, because of the different capitalization. Fixing the line in composer.json to match the real directory capitalization fixed it.\r\n\r\nSo yea, it was my fault all along, naming the folder incorrectly in the composer.json file.\r\n\r\nLet this be a lesson to children and filesystems everywhere."}}