コード例 #1
0
ファイル: Item.php プロジェクト: appsco/component-firi
 /**
  * {@inheritDoc}
  */
 public function addChild(IItem $item)
 {
     if ($item->equals($this)) {
         throw new Exception('Item can\'t be a child to itself');
     }
     $this->children[] = $item;
     $item->setParent($this);
     if ($this instanceof OrderedItemInterface) {
         usort($this->children, function ($a, $b) {
             if ($a->getOrder() == $b->getOrder()) {
                 return 0;
             }
             return $a->getOrder() > $b->getOrder() ? 1 : -1;
         });
     }
     return $this;
 }