當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ItemInterface::copy方法代碼示例

本文整理匯總了PHP中Knp\Menu\ItemInterface::copy方法的典型用法代碼示例。如果您正苦於以下問題:PHP ItemInterface::copy方法的具體用法?PHP ItemInterface::copy怎麽用?PHP ItemInterface::copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Knp\Menu\ItemInterface的用法示例。


在下文中一共展示了ItemInterface::copy方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: slice

 /**
  * Get slice of menu as another menu.
  *
  * If offset and/or length are numeric, it works like in array_slice function:
  *
  *   If offset is non-negative, slice will start at the offset.
  *   If offset is negative, slice will start that far from the end.
  *
  *   If length is null, slice will have all elements.
  *   If length is positive, slice will have that many elements.
  *   If length is negative, slice will stop that far from the end.
  *
  * It's possible to mix names/object/numeric, for example:
  *   slice("child1", 2);
  *   slice(3, $child5);
  * Note: when using a child as limit, it will not be included in the returned menu.
  * the slice is done before this menu.
  *
  * @param ItemInterface $item
  * @param mixed         $offset Name of child, child object, or numeric offset.
  * @param mixed         $length Name of child, child object, or numeric length.
  *
  * @return ItemInterface
  */
 public function slice(ItemInterface $item, $offset, $length = null)
 {
     $names = array_keys($item->getChildren());
     if ($offset instanceof ItemInterface) {
         $offset = $offset->getName();
     }
     if (!is_numeric($offset)) {
         $offset = array_search($offset, $names);
     }
     if (null !== $length) {
         if ($length instanceof ItemInterface) {
             $length = $length->getName();
         }
         if (!is_numeric($length)) {
             $index = array_search($length, $names);
             $length = $index < $offset ? 0 : $index - $offset;
         }
     }
     $slicedItem = $item->copy();
     $children = array_slice($slicedItem->getChildren(), $offset, $length);
     $slicedItem->setChildren($children);
     return $slicedItem;
 }
開發者ID:andrewkrug,項目名稱:repucaution,代碼行數:47,代碼來源:MenuManipulator.php


注:本文中的Knp\Menu\ItemInterface::copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。