本文整理汇总了PHP中Nette\DI\ContainerBuilder::getAliases方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getAliases方法的具体用法?PHP ContainerBuilder::getAliases怎么用?PHP ContainerBuilder::getAliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getAliases方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Generates PHP classes. First class is the container.
* @return Nette\PhpGenerator\ClassType[]
*/
public function generate($className)
{
$this->builder->complete();
$this->generatedClasses = [];
$this->className = $className;
$containerClass = $this->generatedClasses[] = new Nette\PhpGenerator\ClassType($this->className);
$containerClass->setExtends(Container::class);
$containerClass->addMethod('__construct')->addBody('parent::__construct(?);', [$this->builder->parameters]);
$definitions = $this->builder->getDefinitions();
ksort($definitions);
$meta = $containerClass->addProperty('meta')->setVisibility('protected')->setValue([Container::TYPES => $this->builder->getClassList()]);
foreach ($definitions as $name => $def) {
$meta->value[Container::SERVICES][$name] = $def->getClass() ?: NULL;
foreach ($def->getTags() as $tag => $value) {
$meta->value[Container::TAGS][$tag][$name] = $value;
}
}
foreach ($definitions as $name => $def) {
try {
$name = (string) $name;
$methodName = Container::getMethodName($name);
if (!PhpHelpers::isIdentifier($methodName)) {
throw new ServiceCreationException('Name contains invalid characters.');
}
$containerClass->addMethod($methodName)->addComment('@return ' . ($def->getImplement() ?: $def->getClass()))->setBody($name === ContainerBuilder::THIS_CONTAINER ? 'return $this;' : $this->generateService($name))->setParameters($def->getImplement() ? [] : $this->convertParameters($def->parameters));
} catch (\Exception $e) {
throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), 0, $e);
}
}
$aliases = $this->builder->getAliases();
ksort($aliases);
$meta->value[Container::ALIASES] = $aliases;
return $this->generatedClasses;
}