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


PHP Helpers::getInjectProperties方法代码示例

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


在下文中一共展示了Helpers::getInjectProperties方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: injectByProperties

 private function injectByProperties(Presenter $presenter)
 {
     if (class_exists(InjectExtension::class)) {
         /** @noinspection PhpInternalEntityUsedInspection */
         $properties = InjectExtension::getInjectProperties(get_class($presenter));
         // Nette 2.3+
     } else {
         $properties = Helpers::getInjectProperties(new ClassType($presenter));
         // Nette 2.2
     }
     foreach ($properties as $property => $type) {
         if (isset($this->dependencies['@' . $property])) {
             $presenter->{$property} = $this->dependencies['@' . $property];
         } elseif (isset($this->dependencies[$property])) {
             $presenter->{$property} = $this->dependencies[$property];
         }
     }
 }
开发者ID:instante,项目名称:php-test-suite,代码行数:18,代码来源:DependencyContainer.php

示例2: updateDefinition

 private function updateDefinition($def)
 {
     $injects = array();
     $properties = DI\Helpers::getInjectProperties(new \ReflectionClass($def->getClass()), $this->getContainerBuilder());
     foreach ($properties as $property => $type) {
         $injects[] = new DI\Statement('$' . $property, array('@\\' . ltrim($type, '\\')));
     }
     foreach (get_class_methods($def->getClass()) as $method) {
         if (substr($method, 0, 6) === 'inject') {
             $injects[] = new DI\Statement($method);
         }
     }
     $setups = $def->getSetup();
     foreach ($injects as $inject) {
         foreach ($setups as $key => $setup) {
             if ($setup->getEntity() === $inject->getEntity()) {
                 $inject = $setup;
                 unset($setups[$key]);
             }
         }
         array_unshift($setups, $inject);
     }
     $def->setSetup($setups);
 }
开发者ID:vladimirslevercz,项目名称:alena,代码行数:24,代码来源:InjectExtension.php

示例3: callInjects

 /**
  * Calls all methods starting with with "inject" using autowiring.
  * @param  object
  * @return void
  */
 public function callInjects($service)
 {
     if (!is_object($service)) {
         throw new Nette\InvalidArgumentException(sprintf('Service must be object, %s given.', gettype($service)));
     }
     foreach (array_reverse(get_class_methods($service)) as $method) {
         if (substr($method, 0, 6) === 'inject') {
             $this->callMethod(array($service, $method));
         }
     }
     foreach (Helpers::getInjectProperties(Nette\Reflection\ClassType::from($service), $this) as $property => $type) {
         $service->{$property} = $this->getByType($type);
     }
 }
开发者ID:pdostal,项目名称:nette-blog,代码行数:19,代码来源:Container.php

示例4: generateService

 /**
  * Generates body of service method.
  * @return string
  */
 private function generateService($name)
 {
     $this->currentService = NULL;
     $def = $this->definitions[$name];
     $serviceRef = $this->getServiceName($def->factory->entity);
     $factory = $serviceRef && !$def->factory->arguments && !$def->setup && $def->implementType !== 'create' ? new Statement(array('@' . ContainerBuilder::THIS_CONTAINER, 'getService'), array($serviceRef)) : $def->factory;
     $code = '$service = ' . $this->formatStatement($factory) . ";\n";
     $this->currentService = $name;
     if ($def->class && $def->class !== $def->factory->entity && !$serviceRef) {
         $code .= PhpHelpers::formatArgs("if (!\$service instanceof {$def->class}) {\n" . "\tthrow new Nette\\UnexpectedValueException(?);\n}\n", array("Unable to create service '{$name}', value returned by factory is not {$def->class} type."));
     }
     $setups = (array) $def->setup;
     if ($def->inject && $def->class) {
         $injects = array();
         foreach (Helpers::getInjectProperties(Reflection\ClassType::from($def->class)) as $property => $type) {
             $injects[] = new Statement('$' . $property, array('@\\' . ltrim($type, '\\')));
         }
         foreach (get_class_methods($def->class) as $method) {
             if (substr($method, 0, 6) === 'inject') {
                 $injects[] = new Statement($method);
             }
         }
         foreach ($injects as $inject) {
             foreach ($setups as $key => $setup) {
                 if ($setup->entity === $inject->entity) {
                     $inject = $setup;
                     unset($setups[$key]);
                 }
             }
             array_unshift($setups, $inject);
         }
     }
     foreach ($setups as $setup) {
         if (is_string($setup->entity) && strpbrk($setup->entity, ':@?') === FALSE) {
             // auto-prepend @self
             $setup->entity = array('@self', $setup->entity);
         }
         $code .= $this->formatStatement($setup) . ";\n";
     }
     $code .= 'return $service;';
     if (!$def->implement) {
         return $code;
     }
     $factoryClass = $this->generatedClasses[] = new Nette\PhpGenerator\ClassType();
     $factoryClass->setName(str_replace(array('\\', '.'), '_', "{$this->generatedClasses[0]->name}_{$def->implement}Impl_{$name}"))->addImplement($def->implement)->setFinal(TRUE);
     $factoryClass->addProperty('container')->setVisibility('private');
     $factoryClass->addMethod('__construct')->addBody('$this->container = $container;')->addParameter('container')->setTypeHint('Nette\\DI\\Container');
     $factoryClass->addMethod($def->implementType)->setParameters($this->convertParameters($def->parameters))->setBody(str_replace('$this', '$this->container', $code));
     return "return new {$factoryClass->name}(\$this);";
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:54,代码来源:ContainerBuilder.php


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