{"action":"created","comment":{"url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/comments/23763576","id":23763576,"diff_hunk":"@@ -0,0 +1,134 @@\n+<?php\n+\n+/*\n+ * This file is part of the Symfony CMF package.\n+ *\n+ * (c) 2011-2014 Symfony CMF\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ */\n+\n+namespace Symfony\\Cmf\\Bundle\\RoutingBundle\\Resource;\n+\n+use Puli\\Repository\\Api\\ResourceRepository;\n+use Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Puli\\Repository\\Assert\\Assert;\n+use Symfony\\Component\\Routing\\RouteCollection;\n+use Symfony\\Component\\Routing\\Route;\n+\n+/**\n+ * Route provider which uses a CMF resource repository.\n+ *\n+ * Routes can potentially be sourced from PHPCR, PHPCR-ODM, ORM, standard\n+ * routing system, etc.\n+ *\n+ * @author Daniel Leech <daniel@dantleech.com>\n+ */\n+class ResourceProvider implements RouteProviderInterface\n+{\n+    /**\n+     * @var ResourceRepository\n+     */\n+    private $resourceRepository;\n+\n+    /**\n+     * @param ResourceRepository $resourceRepository\n+     */\n+    public function __construct(ResourceRepository $resourceRepository)\n+    {\n+        $this->resourceRepository = $resourceRepository;\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public function getRouteCollectionForRequest(Request $request)\n+    {\n+        $path = $request->getPathInfo();\n+\n+        // assert absolutness and pathliness of path\n+        Assert::path($path);\n+\n+        $collection = new RouteCollection();\n+\n+        foreach ($this->getPaths($path) as $targetPath) {\n+            $this->findRoutes($targetPath, $collection);\n+        }\n+\n+        return $collection;\n+    }\n+\n+    /**\n+     * Return a list of candidate glob paths in order\n+     * of longest to shortest urls, example:\n+     *\n+     *   array(\n+     *      '/test/foo/*',\n+     *      '/test/*',\n+     *      '/*',\n+     *      '/',\n+     *   );\n+     *\n+     * @param string\n+     *\n+     * @return array\n+     */\n+    private function getPaths($path)\n+    {\n+        // get the URL parts (excluding the first /)\n+        $parts = explode('/', substr($path, 1));\n+        array_pop($parts);\n+\n+        $paths = array('/', '/*');\n+        $pathStack = array();\n+\n+        foreach ($parts as $i => $part) {\n+            $pathStack[] = $part;\n+            $paths[] = '/'.implode('/', $pathStack).'/*';\n+        }\n+\n+        $paths = array_reverse($paths);\n+\n+        return $paths;\n+    }\n+\n+    /**\n+     * Find routes for the given glob path and\n+     * add to the RouteCollection\n+     *\n+     * @param string          $path\n+     * @param RouteCollection $collection\n+     */\n+    private function findRoutes($path, $collection)\n+    {\n+        $resources = $this->resourceRepository->find($path);","path":"Resource/ResourceProvider.php","position":106,"original_position":106,"commit_id":"c98f1a8b989de5fae44b053c2f93742bd8e98386","original_commit_id":"56716ff9dfd41e82c2c6494d3d71e046910bcb50","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"But I guess PHPCR-ODM adds a descendant selector?\r\n\r\nUsing the literal URLs without the wildcard would be more efficient, but at the cost of pattern matching - which people rarely need (right?). Good candidate for a strategy.","created_at":"2015-01-29T12:14:48Z","updated_at":"2015-01-29T12:14:48Z","html_url":"https://github.com/symfony-cmf/RoutingBundle/pull/288#discussion_r23763576","pull_request_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288","_links":{"self":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/comments/23763576"},"html":{"href":"https://github.com/symfony-cmf/RoutingBundle/pull/288#discussion_r23763576"},"pull_request":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288"}}},"pull_request":{"url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288","id":28272903,"html_url":"https://github.com/symfony-cmf/RoutingBundle/pull/288","diff_url":"https://github.com/symfony-cmf/RoutingBundle/pull/288.diff","patch_url":"https://github.com/symfony-cmf/RoutingBundle/pull/288.patch","issue_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/288","number":288,"state":"open","locked":false,"title":"CMF Resource provider","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"This PR introduces a route provider for Puli resources via. the CMF\r\nResourceBundle.","created_at":"2015-01-29T11:53:53Z","updated_at":"2015-01-29T12:14:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c30c5cd62e0be5314c9fe9fb8cfb1548775d2918","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288/commits","review_comments_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288/comments","review_comment_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/288/comments","statuses_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/statuses/c98f1a8b989de5fae44b053c2f93742bd8e98386","head":{"label":"symfony-cmf:resource_provider","ref":"resource_provider","sha":"c98f1a8b989de5fae44b053c2f93742bd8e98386","user":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"repo":{"id":4221277,"name":"RoutingBundle","full_name":"symfony-cmf/RoutingBundle","owner":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony-cmf/RoutingBundle","description":"Integrate the CMF Routing component as a Symfony2 bundle: Have the chain router and the dynamic router available in Symfony2","fork":false,"url":"https://api.github.com/repos/symfony-cmf/RoutingBundle","forks_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/forks","keys_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/teams","hooks_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/hooks","issue_events_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/events{/number}","events_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/events","assignees_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/assignees{/user}","branches_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/branches{/branch}","tags_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/tags","blobs_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/languages","stargazers_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/stargazers","contributors_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/contributors","subscribers_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/subscribers","subscription_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/subscription","commits_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/contents/{+path}","compare_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/merges","archive_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/downloads","issues_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues{/number}","pulls_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/labels{/name}","releases_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/releases{/id}","created_at":"2012-05-04T03:25:52Z","updated_at":"2015-01-26T11:06:34Z","pushed_at":"2015-01-29T12:02:48Z","git_url":"git://github.com/symfony-cmf/RoutingBundle.git","ssh_url":"git@github.com:symfony-cmf/RoutingBundle.git","clone_url":"https://github.com/symfony-cmf/RoutingBundle.git","svn_url":"https://github.com/symfony-cmf/RoutingBundle","homepage":"","size":3102,"stargazers_count":43,"watchers_count":43,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":47,"mirror_url":null,"open_issues_count":21,"forks":47,"open_issues":21,"watchers":43,"default_branch":"master"}},"base":{"label":"symfony-cmf:master","ref":"master","sha":"5318a503bdae8e699ae30ae73a678006f8f2dc65","user":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"repo":{"id":4221277,"name":"RoutingBundle","full_name":"symfony-cmf/RoutingBundle","owner":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony-cmf/RoutingBundle","description":"Integrate the CMF Routing component as a Symfony2 bundle: Have the chain router and the dynamic router available in Symfony2","fork":false,"url":"https://api.github.com/repos/symfony-cmf/RoutingBundle","forks_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/forks","keys_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/teams","hooks_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/hooks","issue_events_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/events{/number}","events_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/events","assignees_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/assignees{/user}","branches_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/branches{/branch}","tags_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/tags","blobs_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/languages","stargazers_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/stargazers","contributors_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/contributors","subscribers_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/subscribers","subscription_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/subscription","commits_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/contents/{+path}","compare_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/merges","archive_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/downloads","issues_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues{/number}","pulls_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/labels{/name}","releases_url":"https://api.github.com/repos/symfony-cmf/RoutingBundle/releases{/id}","created_at":"2012-05-04T03:25:52Z","updated_at":"2015-01-26T11:06:34Z","pushed_at":"2015-01-29T12:02:48Z","git_url":"git://github.com/symfony-cmf/RoutingBundle.git","ssh_url":"git@github.com:symfony-cmf/RoutingBundle.git","clone_url":"https://github.com/symfony-cmf/RoutingBundle.git","svn_url":"https://github.com/symfony-cmf/RoutingBundle","homepage":"","size":3102,"stargazers_count":43,"watchers_count":43,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":47,"mirror_url":null,"open_issues_count":21,"forks":47,"open_issues":21,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288"},"html":{"href":"https://github.com/symfony-cmf/RoutingBundle/pull/288"},"issue":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/288"},"comments":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/issues/288/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/pulls/288/commits"},"statuses":{"href":"https://api.github.com/repos/symfony-cmf/RoutingBundle/statuses/c98f1a8b989de5fae44b053c2f93742bd8e98386"}}}}