{"action":"created","comment":{"url":"https://api.github.com/repos/php-http/discovery/pulls/comments/68425825","id":68425825,"diff_hunk":"@@ -2,126 +2,117 @@\n \n namespace Http\\Discovery;\n \n-use Puli\\Discovery\\Api\\Discovery;\n+use Http\\Discovery\\Exception\\DiscoveryFailedException;\n+use Http\\Discovery\\Exception\\StrategyUnavailableException;\n \n /**\n  * Registry that based find results on class existence.\n  *\n  * @author David de Boer <david@ddeboer.nl>\n  * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>\n+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>\n  */\n abstract class ClassDiscovery\n {\n     /**\n-     * @var GeneratedPuliFactory\n+     * A list of strategies to find classes.\n+     *\n+     * @var array\n      */\n-    private static $puliFactory;\n+    public static $strategies = [\n+        Strategy\\Puli::class,\n+        Strategy\\HttpClients::class,\n+        Strategy\\GuzzleFactory::class,\n+        Strategy\\DiactorosFactory::class,\n+    ];\n \n     /**\n-     * @var Discovery\n+     * Discovery cache to make the second time we use discovery faster.\n+     *\n+     * @var array\n      */\n-    private static $puliDiscovery;\n+    private static $cache = [];\n \n     /**\n-     * @return GeneratedPuliFactory\n+     * Finds a class.\n+     *\n+     * @param string $type\n+     *\n+     * @return string\n+     *\n+     * @throws DiscoveryFailedException\n      */\n-    public static function getPuliFactory()\n+    protected static function findOneByType($type)\n     {\n-        if (null === self::$puliFactory) {\n-            if (!defined('PULI_FACTORY_CLASS')) {\n-                throw new \\RuntimeException('Puli Factory is not available');\n-            }\n-\n-            $puliFactoryClass = PULI_FACTORY_CLASS;\n+        // Look in the cache\n+        if (null !== $class = self::getFromCache($type)) {","path":"src/ClassDiscovery.php","position":60,"original_position":60,"commit_id":"cb35b5904126bed07c2d754b045d6993bc994b33","original_commit_id":"cb35b5904126bed07c2d754b045d6993bc994b33","user":{"login":"sagikazarmark","id":1226384,"avatar_url":"https://avatars.githubusercontent.com/u/1226384?v=3","gravatar_id":"","url":"https://api.github.com/users/sagikazarmark","html_url":"https://github.com/sagikazarmark","followers_url":"https://api.github.com/users/sagikazarmark/followers","following_url":"https://api.github.com/users/sagikazarmark/following{/other_user}","gists_url":"https://api.github.com/users/sagikazarmark/gists{/gist_id}","starred_url":"https://api.github.com/users/sagikazarmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagikazarmark/subscriptions","organizations_url":"https://api.github.com/users/sagikazarmark/orgs","repos_url":"https://api.github.com/users/sagikazarmark/repos","events_url":"https://api.github.com/users/sagikazarmark/events{/privacy}","received_events_url":"https://api.github.com/users/sagikazarmark/received_events","type":"User","site_admin":false},"body":"Although not necessary, I would use this: `null !== ($class = self::getFromCache($type))` More readable I think","created_at":"2016-06-24T16:43:10Z","updated_at":"2016-06-24T16:43:10Z","html_url":"https://github.com/php-http/discovery/pull/59#discussion_r68425825","pull_request_url":"https://api.github.com/repos/php-http/discovery/pulls/59","_links":{"self":{"href":"https://api.github.com/repos/php-http/discovery/pulls/comments/68425825"},"html":{"href":"https://github.com/php-http/discovery/pull/59#discussion_r68425825"},"pull_request":{"href":"https://api.github.com/repos/php-http/discovery/pulls/59"}}},"pull_request":{"url":"https://api.github.com/repos/php-http/discovery/pulls/59","id":73500067,"html_url":"https://github.com/php-http/discovery/pull/59","diff_url":"https://github.com/php-http/discovery/pull/59.diff","patch_url":"https://github.com/php-http/discovery/pull/59.patch","issue_url":"https://api.github.com/repos/php-http/discovery/issues/59","number":59,"state":"open","locked":false,"title":"Flexible discovery","user":{"login":"Nyholm","id":1275206,"avatar_url":"https://avatars.githubusercontent.com/u/1275206?v=3","gravatar_id":"","url":"https://api.github.com/users/Nyholm","html_url":"https://github.com/Nyholm","followers_url":"https://api.github.com/users/Nyholm/followers","following_url":"https://api.github.com/users/Nyholm/following{/other_user}","gists_url":"https://api.github.com/users/Nyholm/gists{/gist_id}","starred_url":"https://api.github.com/users/Nyholm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nyholm/subscriptions","organizations_url":"https://api.github.com/users/Nyholm/orgs","repos_url":"https://api.github.com/users/Nyholm/repos","events_url":"https://api.github.com/users/Nyholm/events{/privacy}","received_events_url":"https://api.github.com/users/Nyholm/received_events","type":"User","site_admin":false},"body":"I was not too happy about #58. We treat Puli in a special manner which feels weird. Also, I was not too happy about the logic in the fallback strategies. \r\n\r\nThis PR continues the work and replaces #58. The user has now the possibility to select what strategies to use and also add some more custom if there is a need for it. \r\n\r\n## Changes\r\n* Introduced `Stratiegies` that do the discovery. We try the strategies one by one until we find what we're looking for\r\n* many public functions are moved from `ClassDiscovery` to `Strategy\\Puli`. \r\n* I've also created some new exceptions. \r\n* Added a simple cache mechanism\r\n* When Puli is missing we will not throw a \\RuntimeException anymore. There will be a NotFoundException which has previous exception so you can see that Puli was missing. \r\n* The NotFoundException is moved from Http\\Discovery to Http\\Discovery\\Exception\r\n\r\n\r\n## TODO\r\nThis is just a proof of concept. Do we like to go this way?\r\n\r\n* [x] Add tests\r\n* [ ] Update documentation","created_at":"2016-06-12T16:12:38Z","updated_at":"2016-06-24T16:43:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b7825d2edca45afe5badb23ab12df83c27c64cd7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/php-http/discovery/pulls/59/commits","review_comments_url":"https://api.github.com/repos/php-http/discovery/pulls/59/comments","review_comment_url":"https://api.github.com/repos/php-http/discovery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/php-http/discovery/issues/59/comments","statuses_url":"https://api.github.com/repos/php-http/discovery/statuses/cb35b5904126bed07c2d754b045d6993bc994b33","head":{"label":"php-http:flexible-discovery","ref":"flexible-discovery","sha":"cb35b5904126bed07c2d754b045d6993bc994b33","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":36755218,"name":"discovery","full_name":"php-http/discovery","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/discovery","description":"Finds installed clients and message factories","fork":false,"url":"https://api.github.com/repos/php-http/discovery","forks_url":"https://api.github.com/repos/php-http/discovery/forks","keys_url":"https://api.github.com/repos/php-http/discovery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/discovery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/discovery/teams","hooks_url":"https://api.github.com/repos/php-http/discovery/hooks","issue_events_url":"https://api.github.com/repos/php-http/discovery/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/discovery/events","assignees_url":"https://api.github.com/repos/php-http/discovery/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/discovery/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/discovery/tags","blobs_url":"https://api.github.com/repos/php-http/discovery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/discovery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/discovery/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/discovery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/discovery/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/discovery/languages","stargazers_url":"https://api.github.com/repos/php-http/discovery/stargazers","contributors_url":"https://api.github.com/repos/php-http/discovery/contributors","subscribers_url":"https://api.github.com/repos/php-http/discovery/subscribers","subscription_url":"https://api.github.com/repos/php-http/discovery/subscription","commits_url":"https://api.github.com/repos/php-http/discovery/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/discovery/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/discovery/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/discovery/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/discovery/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/discovery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/discovery/merges","archive_url":"https://api.github.com/repos/php-http/discovery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/discovery/downloads","issues_url":"https://api.github.com/repos/php-http/discovery/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/discovery/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/discovery/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/discovery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/discovery/labels{/name}","releases_url":"https://api.github.com/repos/php-http/discovery/releases{/id}","deployments_url":"https://api.github.com/repos/php-http/discovery/deployments","created_at":"2015-06-02T19:03:26Z","updated_at":"2016-04-09T20:37:12Z","pushed_at":"2016-06-16T14:47:30Z","git_url":"git://github.com/php-http/discovery.git","ssh_url":"git@github.com:php-http/discovery.git","clone_url":"https://github.com/php-http/discovery.git","svn_url":"https://github.com/php-http/discovery","homepage":"http://php-http.org","size":484,"stargazers_count":4,"watchers_count":4,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":7,"forks":6,"open_issues":7,"watchers":4,"default_branch":"master"}},"base":{"label":"php-http:master","ref":"master","sha":"fac1240e8a070b3e2f0e38606941de80c849fa53","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":36755218,"name":"discovery","full_name":"php-http/discovery","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/discovery","description":"Finds installed clients and message factories","fork":false,"url":"https://api.github.com/repos/php-http/discovery","forks_url":"https://api.github.com/repos/php-http/discovery/forks","keys_url":"https://api.github.com/repos/php-http/discovery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/discovery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/discovery/teams","hooks_url":"https://api.github.com/repos/php-http/discovery/hooks","issue_events_url":"https://api.github.com/repos/php-http/discovery/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/discovery/events","assignees_url":"https://api.github.com/repos/php-http/discovery/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/discovery/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/discovery/tags","blobs_url":"https://api.github.com/repos/php-http/discovery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/discovery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/discovery/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/discovery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/discovery/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/discovery/languages","stargazers_url":"https://api.github.com/repos/php-http/discovery/stargazers","contributors_url":"https://api.github.com/repos/php-http/discovery/contributors","subscribers_url":"https://api.github.com/repos/php-http/discovery/subscribers","subscription_url":"https://api.github.com/repos/php-http/discovery/subscription","commits_url":"https://api.github.com/repos/php-http/discovery/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/discovery/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/discovery/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/discovery/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/discovery/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/discovery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/discovery/merges","archive_url":"https://api.github.com/repos/php-http/discovery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/discovery/downloads","issues_url":"https://api.github.com/repos/php-http/discovery/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/discovery/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/discovery/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/discovery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/discovery/labels{/name}","releases_url":"https://api.github.com/repos/php-http/discovery/releases{/id}","deployments_url":"https://api.github.com/repos/php-http/discovery/deployments","created_at":"2015-06-02T19:03:26Z","updated_at":"2016-04-09T20:37:12Z","pushed_at":"2016-06-16T14:47:30Z","git_url":"git://github.com/php-http/discovery.git","ssh_url":"git@github.com:php-http/discovery.git","clone_url":"https://github.com/php-http/discovery.git","svn_url":"https://github.com/php-http/discovery","homepage":"http://php-http.org","size":484,"stargazers_count":4,"watchers_count":4,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":7,"forks":6,"open_issues":7,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/php-http/discovery/pulls/59"},"html":{"href":"https://github.com/php-http/discovery/pull/59"},"issue":{"href":"https://api.github.com/repos/php-http/discovery/issues/59"},"comments":{"href":"https://api.github.com/repos/php-http/discovery/issues/59/comments"},"review_comments":{"href":"https://api.github.com/repos/php-http/discovery/pulls/59/comments"},"review_comment":{"href":"https://api.github.com/repos/php-http/discovery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/php-http/discovery/pulls/59/commits"},"statuses":{"href":"https://api.github.com/repos/php-http/discovery/statuses/cb35b5904126bed07c2d754b045d6993bc994b33"}}}}
{"actor":{"display_login":"sagikazarmark"}}