当前位置: 首页>>代码示例>>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;未经允许,请勿转载。