{"action":"created","issue":{"url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/1741","repository_url":"https://api.github.com/repos/ezsystems/ezpublish-kernel","labels_url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/1741/labels{/name}","comments_url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/1741/comments","events_url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/1741/events","html_url":"https://github.com/ezsystems/ezpublish-kernel/pull/1741","id":167396476,"number":1741,"title":"Rest embedding prototype v2","user":{"login":"bdunogier","id":235928,"avatar_url":"https://avatars.githubusercontent.com/u/235928?v=3","gravatar_id":"","url":"https://api.github.com/users/bdunogier","html_url":"https://github.com/bdunogier","followers_url":"https://api.github.com/users/bdunogier/followers","following_url":"https://api.github.com/users/bdunogier/following{/other_user}","gists_url":"https://api.github.com/users/bdunogier/gists{/gist_id}","starred_url":"https://api.github.com/users/bdunogier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdunogier/subscriptions","organizations_url":"https://api.github.com/users/bdunogier/orgs","repos_url":"https://api.github.com/users/bdunogier/repos","events_url":"https://api.github.com/users/bdunogier/events{/privacy}","received_events_url":"https://api.github.com/users/bdunogier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-07-25T15:35:12Z","updated_at":"2016-07-27T23:07:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/pulls/1741","html_url":"https://github.com/ezsystems/ezpublish-kernel/pull/1741","diff_url":"https://github.com/ezsystems/ezpublish-kernel/pull/1741.diff","patch_url":"https://github.com/ezsystems/ezpublish-kernel/pull/1741.patch"},"body":"> Alternative to #1739\r\n\r\nAlternative implementation that does not require HrefGenerator nor ValueLoader objects.\r\n\r\nHref generation is left untouched, in each visitor. The drawback is that route names are hardcoded/scattered all over the visitors, but it was already like that. Href generation can still be refactored the way it is done in #1739.\r\n\r\nValue object loading is done using the generated REST href (`/api/ezp/v2/content/objects/1`). The Loader uses the router and controller resolver to identify and execute the controller method that loads this object in the REST server. Since REST controllers return a Value Object (later visited to a Response), they can be used to load the value. This prevents us from having to reimplement value object loading one more time. It also ensures that all value objects handled  by the REST API can be embedded.\r\n\r\n### TODO\r\n\r\n- [x] Rename the value loader, with an interface (`HrefRestResourceLoader` ?)\r\n- [ ] Cover multi media-type (example: `Location.Content` loads a `ContentInfo`. The media-type attribute must be used for the value load request. \r\n- [ ] Apply to other visitors once approved\r\n- [ ] Update specification\r\n- [ ] Design and implement Request format\r\n- [x] Add unit test for the loader\r\n- [ ] Add unit test for the visitor\r\n- [ ] Update existing tests that break"},"comment":{"url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/comments/235748808","html_url":"https://github.com/ezsystems/ezpublish-kernel/pull/1741#issuecomment-235748808","issue_url":"https://api.github.com/repos/ezsystems/ezpublish-kernel/issues/1741","id":235748808,"user":{"login":"ezrobot","id":681611,"avatar_url":"https://avatars.githubusercontent.com/u/681611?v=3","gravatar_id":"","url":"https://api.github.com/users/ezrobot","html_url":"https://github.com/ezrobot","followers_url":"https://api.github.com/users/ezrobot/followers","following_url":"https://api.github.com/users/ezrobot/following{/other_user}","gists_url":"https://api.github.com/users/ezrobot/gists{/gist_id}","starred_url":"https://api.github.com/users/ezrobot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezrobot/subscriptions","organizations_url":"https://api.github.com/users/ezrobot/orgs","repos_url":"https://api.github.com/users/ezrobot/repos","events_url":"https://api.github.com/users/ezrobot/events{/privacy}","received_events_url":"https://api.github.com/users/ezrobot/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T23:07:28Z","updated_at":"2016-07-27T23:07:28Z","body":"This Pull Request does not respect [PSR-2 Coding Standards](http://www.php-fig.org/psr/psr-2/), please, see the suggested diff below:\n\n```diff\nLoaded config from \"/jenkins/jenkins.std/jobs/PAPI-Pull-Request-code-sniffer/workspace/.php_cs\"\n................................................................F.......F...F................................\nLegend: ?-unknown, I-invalid file syntax, file ignored, .-no changes, F-fixed, E-error\n   1) eZ/Publish/Core/REST/Server/Tests/ValueLoaders/ControllerUriValueLoaderTest.php (new_with_braces, function_declaration)\n      ---------- begin diff ----------\n      --- Original\n      +++ New\n      @@ @@\n       \n      -        $valueObject = new \\stdClass;\n      +        $valueObject = new \\stdClass();\n      \n      @@ @@\n                   ->will($this->returnValue(\n      -                function() use ($valueObject) { return $valueObject; }\n      +                function () use ($valueObject) { return $valueObject; }\n      \n      @@ @@\n       \n      -        $valueObject = new Response;\n      +        $valueObject = new Response();\n      \n      @@ @@\n                   ->will($this->returnValue(\n      -                function() use ($valueObject) { return $valueObject; }\n      +                function () use ($valueObject) { return $valueObject; }\n                   ));\n       \n               $this->controllerResolverMock\n                   ->expects($this->once())\n                   ->method('getArguments')\n                   ->will($this->returnValue(['id' => 1]));\n       \n               $this->loader->load('/api/ezp/v2/resource/1');\n           }\n       }\n       \n      \n      ---------- end diff ----------\n\n   2) eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestLocation.php (unused_use)\n      ---------- begin diff ----------\n      --- Original\n      +++ New\n      @@ @@\n       use eZ\\Publish\\Core\\REST\\Common\\Output\\Visitor;\n      -use eZ\\Publish\\Core\\REST\\Server\\Values\\ResourceLink;\n       use eZ\\Publish\\Core\\REST\\Server\\Values\\ResourceRouteReference;\n       \n       /**\n        * RestLocation value object visitor.\n        */\n       class RestLocation extends ValueObjectVisitor\n       {\n           /**\n            * Visit struct returned by controllers.\n            *\n            * @param \\eZ\\Publish\\Core\\REST\\Common\\Output\\Visitor $visitor\n            * @param \\eZ\\Publish\\Core\\REST\\Common\\Output\\Generator $generator\n            * @param \\eZ\\Publish\\Core\\REST\\Server\\Values\\RestLocation $data\n            */\n           public function visit(Visitor $visitor, Generator $generator, $data)\n           {\n               $generator->startObjectElement('Location');\n               $visitor->setHeader('Content-Type', $generator->getMediaType('Location'));\n               $visitor->setHeader('Accept-Patch', $generator->getMediaType('LocationUpdate'));\n       \n               $location = $data->location;\n               $contentInfo = $location->getContentInfo();\n       \n               $visitor->visitValueObject(\n                   new ResourceRouteReference(\n                       'ezpublish_rest_loadLocation',\n                       ['locationPath' => trim($location->pathString, '/')]\n                   )\n               );\n       \n               $generator->startValueElement('id', $location->id);\n               $generator->endValueElement('id');\n       \n               $generator->startValueElement('priority', $location->priority);\n               $generator->endValueElement('priority');\n       \n               $generator->startValueElement(\n                   'hidden',\n                   $this->serializeBool($generator, $location->hidden)\n               );\n               $generator->endValueElement('hidden');\n       \n               $generator->startValueElement(\n                   'invisible',\n                   $this->serializeBool($generator, $location->invisible)\n               );\n               $generator->endValueElement('invisible');\n       \n               $generator->startObjectElement('ParentLocation', 'Location');\n               if (trim($location->pathString, '/') !== '1') {\n                   $visitor->visitValueObject(\n                       new ResourceRouteReference(\n                           'ezpublish_rest_loadLocation',\n                           ['locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1))]\n                       )\n                   );\n               }\n               $generator->endObjectElement('ParentLocation');\n       \n               $generator->startValueElement('pathString', $location->pathString);\n               $generator->endValueElement('pathString');\n       \n               $generator->startValueElement('depth', $location->depth);\n               $generator->endValueElement('depth');\n       \n               $generator->startValueElement('childCount', $data->childCount);\n               $generator->endValueElement('childCount');\n       \n               $generator->startValueElement('remoteId', $location->remoteId);\n               $generator->endValueElement('remoteId');\n       \n               $generator->startObjectElement('Children', 'LocationList');\n               $visitor->visitValueObject(\n                   new ResourceRouteReference(\n                       'ezpublish_rest_loadLocationChildren',\n                       ['locationPath' => trim($location->pathString, '/')]\n                   )\n               );\n               $generator->endObjectElement('Children');\n       \n               $generator->startObjectElement('Content');\n               $visitor->visitValueObject(\n                   new ResourceRouteReference(\n                       'ezpublish_rest_loadContent',\n                       ['contentId' => $contentInfo->id]\n                   )\n               );\n               $generator->endObjectElement('Content');\n       \n               $generator->startValueElement('sortField', $this->serializeSortField($location->sortField));\n               $generator->endValueElement('sortField');\n       \n               $generator->startValueElement('sortOrder', $this->serializeSortOrder($location->sortOrder));\n               $generator->endValueElement('sortOrder');\n       \n               $generator->startObjectElement('UrlAliases', 'UrlAliasRefList');\n               $visitor->visitValueObject(\n                   new ResourceRouteReference(\n                       'ezpublish_rest_listLocationURLAliases',\n                       ['locationPath' => trim($location->pathString, '/')]\n                   )\n               );\n               $generator->endObjectElement('UrlAliases');\n       \n               $generator->startObjectElement('ContentInfo', 'ContentInfo');\n               $visitor->visitValueObject(\n                   new ResourceRouteReference(\n                       'ezpublish_rest_loadContent',\n                       ['contentId' => $contentInfo->id]\n                   )\n               );\n       \n               $generator->endObjectElement('ContentInfo');\n       \n               $generator->endObjectElement('Location');\n           }\n       }\n       \n      \n      ---------- end diff ----------\n\n   3) eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroup.php (trim_array_spaces)\n      ---------- begin diff ----------\n      --- Original\n      +++ New\n      @@ @@\n                       'ezpublish_rest_loadUserGroup',\n      -                [ 'groupPath' => implode('/', array_slice($mainLocation->path, 0, count($mainLocation->path) - 1))]\n      +                ['groupPath' => implode('/', array_slice($mainLocation->path, 0, count($mainLocation->path) - 1))]\n                   )\n               );\n               $generator->endAttribute('href');\n               $generator->endObjectElement('ParentUserGroup');\n       \n               $generator->startObjectElement('Subgroups', 'UserGroupList');\n               $generator->startAttribute(\n                   'href',\n                   $this->router->generate(\n                       'ezpublish_rest_loadSubUserGroups',\n                       array(\n                           'groupPath' => $mainLocationPath,\n                       )\n                   )\n               );\n               $generator->endAttribute('href');\n               $generator->endObjectElement('Subgroups');\n       \n               $generator->startObjectElement('Users', 'UserList');\n               $generator->startAttribute(\n                   'href',\n                   $this->router->generate(\n                       'ezpublish_rest_loadUsersFromGroup',\n                       array(\n                           'groupPath' => $mainLocationPath,\n                       )\n                   )\n               );\n               $generator->endAttribute('href');\n               $generator->endObjectElement('Users');\n       \n               $generator->startObjectElement('Roles', 'RoleAssignmentList');\n               $generator->startAttribute(\n                   'href',\n                   $this->router->generate(\n                       'ezpublish_rest_loadRoleAssignmentsForUserGroup',\n                       array(\n                           'groupPath' => $mainLocationPath,\n                       )\n                   )\n               );\n               $generator->endAttribute('href');\n               $generator->endObjectElement('Roles');\n       \n               $generator->endObjectElement('UserGroup');\n           }\n       }\n       \n      \n      ---------- end diff ----------\n\nFixed all files in 45.357 seconds, 25.000 MB memory used\n```\n"}}
{"actor":{"display_login":"ezrobot"}}