/**
  * @param string $id
  * @param bool $extractView
  * @return PartInterface|ViewComponentInterface|Part|null
  */
 public function getComponent($id, $extractView = true)
 {
     $this->buildTree();
     /** @var PartInterface|Part $part */
     $part = $this->componentCollection->findByProperty('id', $id, true);
     return $extractView && $part instanceof Part ? $part->getView() : $part;
 }
Example #2
0
 /**
  * Returns collection containing all descendant nodes.
  * 
  * @return CollectionInterface|ObjectCollection|ChildNodeInterface[]
  */
 public function getChildrenRecursive()
 {
     $res = new ObjectCollection();
     foreach ($this->children() as $child) {
         $res->add($child);
         if ($child instanceof ParentNodeInterface) {
             $res->addMany($child->getChildrenRecursive());
         }
     }
     return $res;
 }
Example #3
0
 /**
  * @return ObjectCollection
  */
 public function parents()
 {
     $parents = new ObjectCollection();
     $current = $this->parent();
     while ($current instanceof ParentNodeInterface) {
         $parents->add($current);
         if (!$current instanceof ChildNodeInterface) {
             break;
         }
         $current = $current->parent();
     }
     return $parents;
 }
Example #4
0
 public function clear()
 {
     /** @var ChildNodeInterface $item */
     foreach ($this->items() as $item) {
         $this->checkUnlocked($item);
         $item->internalUnsetParent();
     }
     return parent::clear();
 }
 public function test()
 {
     $i1 = (object) ['test_prop' => 1];
     $i2 = new ObjWithGetter(2);
     $i3 = (object) ['other_prop' => 2];
     $i4 = new ObjWithGetter(1);
     $i5 = (object) ['test_prop' => 2];
     $i6 = (object) ['test_prop' => 2, 'other' => 3];
     $collection = new ObjectCollection([$i1, $i2, $i3, $i4, $i5, $i6]);
     $res = $collection->findByProperty('test_prop', 2);
     self::assertEquals($i5, $res);
     $res = $collection->findByProperty('test_prop', 2, true);
     self::assertEquals($i2, $res);
     $res = $collection->findByProperty('test_prop', 3, true);
     self::assertEquals(null, $res);
     $res = $collection->findByProperty('test_prop', '2', true);
     self::assertEquals(null, $res);
     $res = $collection->filterByProperty('test_prop', 2, true);
     self::assertEquals(3, count($res));
     $res = $collection->filterByProperty('test_prop', 2, false);
     self::assertEquals(2, count($res));
 }