本文整理汇总了PHP中NodeInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getName方法的具体用法?PHP NodeInterface::getName怎么用?PHP NodeInterface::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromNode
public function createFromNode(NodeInterface $node)
{
$item = $this->createItem($node->getName(), $node->getOptions());
foreach ($node->getChildren() as $childNode) {
$item->addChild($this->createFromNode($childNode));
}
return $item;
}
示例2: createFromNode
/**
* Create a menu item from a NodeInterface
*
* @param NodeInterface $node
* @return MenuItem
*/
public function createFromNode(NodeInterface $node)
{
$item = new MenuItem($node->getName(), $this->getUriFromNode($node), $node->getAttributes());
$item->setLabel($node->getLabel());
foreach ($node->getChildren() as $childNode) {
$item->addChild($this->createFromNode($childNode));
}
return $item;
}
示例3: registerChild
public function registerChild(NodeInterface $node, $overwrite = false, $prepend = false)
{
$this->registerAdopters();
if ($node->getParent() !== $this) {
throw new \RuntimeException('Nodes being registered must return this node from their getParentNode method.');
}
$name = $node->getName();
if (!$overwrite && isset($this->childNodes[$name])) {
throw new \RuntimeException(sprintf('Node name %s is already registered.', $name));
}
if ($prepend) {
$this->childNodes = array_merge([$name => null], $this->getChildren(), [$name => $node]);
} else {
$this->childNodes[$name] = $node;
}
}
示例4: writeNode
/**
* @param int $depth
*/
private function writeNode(NodeInterface $node, $depth = 0)
{
$comments = array();
$default = '';
$defaultArray = null;
$children = null;
$example = $node->getExample();
// defaults
if ($node instanceof ArrayNode) {
$children = $node->getChildren();
if ($node instanceof PrototypedArrayNode) {
$prototype = $node->getPrototype();
if ($prototype instanceof ArrayNode) {
$children = $prototype->getChildren();
}
// check for attribute as key
if ($key = $node->getKeyAttribute()) {
$keyNode = new ArrayNode($key, $node);
$keyNode->setInfo('Prototype');
// add children
foreach ($children as $childNode) {
$keyNode->addChild($childNode);
}
$children = array($key => $keyNode);
}
}
if (!$children) {
if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
$default = '';
} elseif (!is_array($example)) {
$default = '[]';
}
}
} else {
$default = '~';
if ($node->hasDefaultValue()) {
$default = $node->getDefaultValue();
if (true === $default) {
$default = 'true';
} elseif (false === $default) {
$default = 'false';
} elseif (null === $default) {
$default = '~';
}
}
}
// required?
if ($node->isRequired()) {
$comments[] = 'Required';
}
// example
if ($example && !is_array($example)) {
$comments[] = 'Example: '.$example;
}
$default = (string) $default != '' ? ' '.$default : '';
$comments = count($comments) ? '# '.implode(', ', $comments) : '';
$text = sprintf('%-20s %s %s', $node->getName().':', $default, $comments);
if ($info = $node->getInfo()) {
$this->writeLine('');
$this->writeLine('# '.$info, $depth * 4);
}
$this->writeLine($text, $depth * 4);
// output defaults
if ($defaultArray) {
$this->writeLine('');
$message = count($defaultArray) > 1 ? 'Defaults' : 'Default';
$this->writeLine('# '.$message.':', $depth * 4 + 4);
$this->writeArray($defaultArray, $depth + 1);
}
if (is_array($example)) {
$this->writeLine('');
$message = count($example) > 1 ? 'Examples' : 'Example';
$this->writeLine('# '.$message.':', $depth * 4 + 4);
$this->writeArray($example, $depth + 1);
}
//.........这里部分代码省略.........
示例5: addChild
public function addChild(NodeInterface $node)
{
if ($this->isTerminal()) {
throw new \LogicException("I am terminal");
}
$node->setParent($this);
$this->children[$node->getName()] = $node;
}