Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node
- {
- /** [...]
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /** [...]
- * @ORMColumn(name="name", type="string", length=100, nullable=false)
- */
- private $name;
- /** [...]
- * @ORMManyToOne(targetEntity="Node", inversedBy="children")
- */
- private $parent;
- /** [...]
- * @ORMOneToMany(targetEntity="Node", mappedBy="parent")
- */
- private $children;
- // ...
- public function addChild(Node $child)
- {
- $this->children[] = $child;
- $child->setParent($this);
- return $this;
- }
- public function removeChild(Node $child)
- {
- $this->children->removeElement($child);
- $child->setParent(null);
- }
- // ...
- AppBundleEntityNode:
- Node-0:
- name: 'Trunk'
- Node-1:
- name: 'Branch 1'
- parent: '@Node-0'
- Node-2:
- name: 'Branch 2'
- parent: '@Node-0'
- $loader = new NativeLoader();
- $fixtures = $loader->loadFile('node.yml')->getObjects();
- echo $fixtures['Node-1']->getParent()->getName();
- echo count($fixtures['Node-0']->getChildren());
- AppBundleEntityNode:
- Node-0:
- name: 'Trunk'
- children: ['@Node-1', '@Node-2']
- Node-1:
- name: 'Branch 1'
- Node-2:
- name: 'Branch 2'
- public function addChild(Node $child)
- {
- $this->children[] = $child;
- $child->setParent($this);
- return $this;
- }
- public function removeChild(Node $child)
- {
- $this->children->removeElement($child);
- $child->setParent(null);
- }
- AppBundleEntityNode:
- Node-0:
- name: 'Trunk'
- Node-1:
- name: 'Branch 1'
- parent: '@Node-0'
- Node-2:
- name: 'Branch 2'
- parent: '@Node-0'
- public function setParent(Node $parent)
- {
- $parent->addChild($this);
- $this->parent = $parent;
- return $this;
- }
Add Comment
Please, Sign In to add comment