本文整理汇总了PHP中Nette\DI\ContainerBuilder::literal方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::literal方法的具体用法?PHP ContainerBuilder::literal怎么用?PHP ContainerBuilder::literal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::literal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatPhp
/**
* Formats PHP statement.
* @return string
* @internal
*/
public function formatPhp($statement, $args)
{
$that = $this;
array_walk_recursive($args, function (&$val) use($that) {
if ($val instanceof Statement) {
$val = ContainerBuilder::literal($that->formatStatement($val));
} elseif ($val === $that) {
$val = ContainerBuilder::literal('$this');
} elseif ($val instanceof ServiceDefinition) {
$val = '@' . current(array_keys($that->getDefinitions(), $val, TRUE));
}
if (!is_string($val)) {
return;
} elseif (substr($val, 0, 2) === '@@') {
$val = substr($val, 1);
} elseif (substr($val, 0, 1) === '@' && strlen($val) > 1) {
$pair = explode('::', $val, 2);
$name = $that->getServiceName($pair[0]);
if (isset($pair[1]) && preg_match('#^[A-Z][A-Z0-9_]*\\z#', $pair[1], $m)) {
$val = $that->getDefinition($name)->getClass() . '::' . $pair[1];
} else {
if ($name === ContainerBuilder::THIS_CONTAINER) {
$val = '$this';
} elseif ($name === $that->currentService) {
$val = '$service';
} else {
$val = $that->formatStatement(new Statement(array('@' . ContainerBuilder::THIS_CONTAINER, 'getService'), array($name)));
}
$val .= isset($pair[1]) ? PhpHelpers::formatArgs('->?', array($pair[1])) : '';
}
$val = ContainerBuilder::literal($val);
}
});
return PhpHelpers::formatArgs($statement, $args);
}
示例2: filterArguments
/**
* Removes ... and process constants recursively.
* @return array
*/
public static function filterArguments(array $args)
{
foreach ($args as $k => $v) {
if ($v === '...') {
unset($args[$k]);
} elseif (is_string($v) && preg_match('#^[\\w\\\\]*::[A-Z][A-Z0-9_]*\\z#', $v, $m)) {
$args[$k] = ContainerBuilder::literal(ltrim($v, ':'));
} elseif (is_array($v)) {
$args[$k] = self::filterArguments($v);
} elseif ($v instanceof Statement) {
$tmp = self::filterArguments(array($v->getEntity()));
$args[$k] = new Statement($tmp[0], self::filterArguments($v->arguments));
}
}
return $args;
}