本文整理汇总了PHP中Nette\Utils\Strings::expand方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::expand方法的具体用法?PHP Strings::expand怎么用?PHP Strings::expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::expand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: expand
/**
* Expands %placeholders% in string.
* @param mixed
* @return mixed
*/
public function expand($s)
{
return is_string($s) ? Nette\Utils\Strings::expand($s, $this->params) : $s;
}
示例2: addDefinitions
/**
* Adds new services from list of definitions. Expands %param% and @service values.
* Format:
* serviceName => array(
* class => 'ClassName' or factory => 'Factory::create'
* arguments => array(...)
* methods => array(
* array(methodName, array(...))
* ...
* )
* tags => array(...)
* alias => 'Service'
* )
*/
public function addDefinitions(IContainer $container, array $definitions)
{
foreach ($definitions as $name => $definition) {
if (is_scalar($definition)) {
if (substr($definition, 0, 1) === '@') {
$definition = array('alias' => substr($definition, 1));
} else {
$definition = array('class' => $definition);
}
}
$arguments = isset($definition['arguments']) ? $definition['arguments'] : array();
$expander = function (&$val) use($container) {
if (substr($val, 0, 1) === '@') {
$val = $container->getService(substr($val, 1));
} elseif (is_string($val)) {
$val = Nette\Utils\Strings::expand($val, $container->params);
}
};
if (isset($definition['class']) || isset($definition['factory'])) {
if (isset($definition['class'])) {
$class = $definition['class'];
} else {
$class = NULL;
array_unshift($arguments, $definition['factory']);
}
$methods = isset($definition['methods']) ? $definition['methods'] : array();
$factory = function ($container) use($class, $arguments, $methods, $expander) {
array_walk_recursive($arguments, $expander);
if ($class) {
$class = Nette\Utils\Strings::expand($class, $container->params);
if ($arguments) {
$service = Nette\Reflection\ClassType::from($class)->newInstanceArgs($arguments);
} else {
$service = new $class();
}
} else {
$factory = $arguments[0];
$arguments[0] = $container;
$service = call_user_func_array($factory, $arguments);
}
array_walk_recursive($methods, $expander);
foreach ($methods as $method) {
call_user_func_array(array($service, $method[0]), isset($method[1]) ? $method[1] : array());
}
return $service;
};
} elseif (isset($definition['alias'])) {
$factory = function ($container) use($definition) {
return $container->getService($definition['alias']);
};
} else {
throw new Nette\InvalidStateException("The definition of service '{$name}' is missing factory method.");
}
if (isset($definition['tags'])) {
$tags = (array) $definition['tags'];
array_walk_recursive($tags, $expander);
} else {
$tags = NULL;
}
$container->addService($name, $factory, $tags);
}
}