GitHub PullRequestReviewCommentEvent at 2014-04-15 15:37:22
Repository: zfc-rbac
Actor: Ocramius
Payload: {"comment":{"url":"https://api.github.com/repos/ZF-Commons/zfc-rbac/pulls/comments/11640472","id":11640472,"diff_hunk":"@@ -454,7 +454,149 @@ class MustBeAuthorAssertion implements AssertionInterface\n \n ## Using ZfcRbac with Doctrine ORM\n \n-TBD\n+First your User entity class must implement `ZfcRbac\\Identity\\IdentityInterface` :\n+\n+```php\n+class User implements IdentityInterface\n+{\n+    /**\n+     * @var Collection\n+     * @ORM\\ManyToMany(targetEntity=\"HierarchicalRole\")\n+     */\n+    private $roles;\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public function getRoles()\n+    {\n+        return $this->roles;\n+    }\n+\n+    /**\n+     * Set the list of roles\n+     * @param Collection $roles\n+     */\n+    public function setRoles(Collection $roles = null)\n+    {\n+        $this->roles = $roles;\n+    }\n+\n+    /**\n+     * Add one role to roles list\n+     * @param \\Rbac\\Role\\RoleInterface $role\n+     */\n+    public function addRole(RoleInterface $role)\n+    {\n+        $this->roles->add($role);\n+    }\n+}\n+```\n+For this example we will use the more complex situation by using `Rbac\\Role\\HierarchicalRoleInterface` so the second step is to create HierarchicalRole entity class\n+\n+```php\n+class HierarchicalRole implements HierarchicalRoleInterface\n+{\n+    /**\n+     * @var HierarchicalRoleInterface[]|\\Doctrine\\Common\\Collections\\Collection\n+     *\n+     * @ORM\\ManyToMany(targetEntity=\"HierarchicalRole\")\n+     */\n+    protected $children = [];\n+\n+    /**\n+     * @var PermissionInterface[]|\\Doctrine\\Common\\Collections\\Collection\n+     *\n+     * @ORM\\ManyToMany(targetEntity=\"Permission\", indexBy=\"name\", fetch=\"EAGER\")\n+     */\n+    protected $permissions;\n+\n+    /**\n+     * Init the Doctrine collection\n+     */\n+    public function __construct()\n+    {\n+        $this->children    = new ArrayCollection();\n+        $this->permissions = new ArrayCollection();\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public function addChild(HierarchicalRoleInterface $child)\n+    {\n+        $this->children[] = $child;\n+    }\n+\n+    /*\n+     * Set the list of permission\n+     * @param Collection $permissions\n+     */\n+    public function setPermissions(Collection $permissions)","path":"docs/07. Cookbook.md","position":83,"original_position":83,"commit_id":"b2aeca341d966828075474e6b203a6f980d15f24","original_commit_id":"b2aeca341d966828075474e6b203a6f980d15f24","user":{"login":"Ocramius","id":154256,"avatar_url":"https://avatars.githubusercontent.com/u/154256?","gravatar_id":"3cf7a8ab0bccee5b65d39b50a170a555","url":"https://api.github.com/users/Ocramius","html_url":"https://github.com/Ocramius","followers_url":"https://api.github.com/users/Ocramius/followers","following_url":"https://api.github.com/users/Ocramius/following{/other_user}","gists_url":"https://api.github.com/users/Ocramius/gists{/gist_id}","starred_url":"https://api.github.com/users/Ocramius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ocramius/subscriptions","organizations_url":"https://api.github.com/users/Ocramius/orgs","repos_url":"https://api.github.com/users/Ocramius/repos","events_url":"https://api.github.com/users/Ocramius/events{/privacy}","received_events_url":"https://api.github.com/users/Ocramius/received_events","type":"User","site_admin":false},"body":"Replacing the collection should NOT be allowed","created_at":"2014-04-15T15:37:22Z","updated_at":"2014-04-15T15:37:22Z","html_url":"https://github.com/ZF-Commons/zfc-rbac/pull/218#discussion_r11640472","pull_request_url":"https://api.github.com/repos/ZF-Commons/zfc-rbac/pulls/218","_links":{"self":{"href":"https://api.github.com/repos/ZF-Commons/zfc-rbac/pulls/comments/11640472"},"html":{"href":"https://github.com/ZF-Commons/zfc-rbac/pull/218#discussion_r11640472"},"pull_request":{"href":"https://api.github.com/repos/ZF-Commons/zfc-rbac/pulls/218"}}}}