getInjectProperties() public static method

Generates list of properties with annotation @inject.
public static getInjectProperties ( $class ) : array
return array
 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];
         }
     }
 }
Example #2
0
 private function doInjects(Presenter $presenter)
 {
     $properties = InjectExtension::getInjectProperties(get_class($presenter));
     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];
         }
     }
     $methods = InjectExtension::getInjectMethods($presenter);
     unset($methods['injectPrimary']);
     foreach (array_reverse($methods) as $method) {
         $injectName = lcfirst(substr($method, 6));
         if (isset($this->dependencies[$injectName])) {
             if (!is_array($this->dependencies[$injectName])) {
                 $this->dependencies[$injectName] = [$this->dependencies[$injectName]];
             }
             call_user_func_array($presenter->{$method}, $this->dependencies[$injectName]);
         }
     }
 }