本文整理汇总了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;
}