{"action":"closed","issue":{"url":"https://api.github.com/repos/Roave/BetterReflection/issues/36","labels_url":"https://api.github.com/repos/Roave/BetterReflection/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/Roave/BetterReflection/issues/36/comments","events_url":"https://api.github.com/repos/Roave/BetterReflection/issues/36/events","html_url":"https://github.com/Roave/BetterReflection/issues/36","id":92918623,"number":36,"title":"Implement \"autoloading\" source locator","user":{"login":"asgrim","id":496145,"avatar_url":"https://avatars.githubusercontent.com/u/496145?v=3","gravatar_id":"","url":"https://api.github.com/users/asgrim","html_url":"https://github.com/asgrim","followers_url":"https://api.github.com/users/asgrim/followers","following_url":"https://api.github.com/users/asgrim/following{/other_user}","gists_url":"https://api.github.com/users/asgrim/gists{/gist_id}","starred_url":"https://api.github.com/users/asgrim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asgrim/subscriptions","organizations_url":"https://api.github.com/users/asgrim/orgs","repos_url":"https://api.github.com/users/asgrim/repos","events_url":"https://api.github.com/users/asgrim/events{/privacy}","received_events_url":"https://api.github.com/users/asgrim/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Roave/BetterReflection/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/Roave/BetterReflection/labels/question","name":"question","color":"cc317c"},{"url":"https://api.github.com/repos/Roave/BetterReflection/labels/reflection%20compatibility","name":"reflection compatibility","color":"fbca04"}],"state":"closed","locked":false,"assignee":{"login":"asgrim","id":496145,"avatar_url":"https://avatars.githubusercontent.com/u/496145?v=3","gravatar_id":"","url":"https://api.github.com/users/asgrim","html_url":"https://github.com/asgrim","followers_url":"https://api.github.com/users/asgrim/followers","following_url":"https://api.github.com/users/asgrim/following{/other_user}","gists_url":"https://api.github.com/users/asgrim/gists{/gist_id}","starred_url":"https://api.github.com/users/asgrim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asgrim/subscriptions","organizations_url":"https://api.github.com/users/asgrim/orgs","repos_url":"https://api.github.com/users/asgrim/repos","events_url":"https://api.github.com/users/asgrim/events{/privacy}","received_events_url":"https://api.github.com/users/asgrim/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Roave/BetterReflection/milestones/1","html_url":"https://github.com/Roave/BetterReflection/milestones/1.0.0","labels_url":"https://api.github.com/repos/Roave/BetterReflection/milestones/1/labels","id":1187129,"number":1,"title":"1.0.0","description":"","creator":{"login":"asgrim","id":496145,"avatar_url":"https://avatars.githubusercontent.com/u/496145?v=3","gravatar_id":"","url":"https://api.github.com/users/asgrim","html_url":"https://github.com/asgrim","followers_url":"https://api.github.com/users/asgrim/followers","following_url":"https://api.github.com/users/asgrim/following{/other_user}","gists_url":"https://api.github.com/users/asgrim/gists{/gist_id}","starred_url":"https://api.github.com/users/asgrim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asgrim/subscriptions","organizations_url":"https://api.github.com/users/asgrim/orgs","repos_url":"https://api.github.com/users/asgrim/repos","events_url":"https://api.github.com/users/asgrim/events{/privacy}","received_events_url":"https://api.github.com/users/asgrim/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":16,"state":"open","created_at":"2015-06-30T13:57:38Z","updated_at":"2015-07-09T08:28:18Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-07-03T18:16:04Z","updated_at":"2015-07-09T08:28:18Z","closed_at":"2015-07-09T08:28:18Z","body":"In order to automatically reflect using the exact same API as the core `Reflection*` classes, we need to be able to essentially ignore the whole `SourceLocator` concept, despite it's flexibility.\r\n\r\nSo, I think it's possible to implement a new `AutoloadingSourceLocator` that takes no constructor dependencies, which, funnily enough, would probably need to rely on the internal `ReflectionClass` API, e.g.:\r\n\r\n```php\r\n// if it's a class we're loading...\r\n$reflectionClass = new \\ReflectionClass($identifier->getName());\r\n$filename = $reflectionClass->getFileName();\r\n$source = file_get_contents($filename);\r\n// use these to make the LocatedSource...\r\n```\r\n\r\nAdditionally, we'd need to create a \"static\" reflector, which would be something like:\r\n\r\n```php\r\nclass StaticReflector\r\n{\r\n    public static function reflect(...)\r\n    {\r\n        return (new Reflector(new AutoloadingSourceLocator()))->reflect($identifier);\r\n    }\r\n}\r\n```\r\n\r\nThen we can use this reflector in the constructors or something to reflect (still a bit hazy on how to actually implement this). The downside of this is it means we do have to LOAD the classes. So I also propose making a `LoadSafeSourceLocator` interface, which doesn't have any methods, but purely indicates that it \"by design\" does NOT load up classes into memory. Then in the `..\\Reflector\\Generic` class, we can check if `$reflection implements LoadSafeSourceLocator`, and ensure that the class is not loaded beforehand, and is not loaded after reflection, to ensure the contract is obeyed.\r\n\r\n### TL;DR\r\n\r\n* Create new `AutoloadingSourceLocator` that uses core refleciton API to locate source code filename\r\n* Cleanup constructors so they are empty\r\n* Create `StaticReflector` that uses `AutoloadingSourceLocator`\r\n* Update `Reflection*` classes to use `AutoloadingSourceLocator`\r\n* Create `LoadSafeSourceLocator` interface, any source locator that implements this interface MUST ensure the class does not get loaded ever. These would be the `Composer`, `SingleFile` and `String` source locators, as these do not load file. `AutoloadingSourceLocator` would load the file, so MUST NOT implement the `LoadSafeSourceLocator` interface.\r\n* This allows us to do the following (i.e. replicate almost _exactly_ the core reflection API instantiation technique):\r\n\r\n```php\r\n$reflectionClass = new \\BetterReflection\\Reflection\\ReflectionClass('My\\Foo\\Bar');\r\n```"}}