当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::complete方法代码示例

本文整理汇总了PHP中Nette\DI\ContainerBuilder::complete方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::complete方法的具体用法?PHP ContainerBuilder::complete怎么用?PHP ContainerBuilder::complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\DI\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::complete方法的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;
 }
开发者ID:nette,项目名称:di,代码行数:38,代码来源:PhpGenerator.php


注:本文中的Nette\DI\ContainerBuilder::complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。