Nette\DI\Extensions\InjectExtension::getInjectMethods PHP Method

getInjectMethods() public static method

Generates list of inject methods.
public static getInjectMethods ( $class ) : array
return array
    public static function getInjectMethods($class)
    {
        $res = [];
        foreach (get_class_methods($class) as $name) {
            if (substr($name, 0, 6) === 'inject') {
                $res[$name] = (new \ReflectionMethod($class, $name))->getDeclaringClass()->getName();
            }
        }
        uksort($res, function ($a, $b) use($res) {
            return $res[$a] === $res[$b] ? strcmp($a, $b) : (is_a($res[$a], $res[$b], TRUE) ? 1 : -1);
        });
        return array_keys($res);
    }

Usage Example

 /**
  * @param Presenter $presenter
  */
 private function injectByMethods(Presenter $presenter)
 {
     if (class_exists(InjectExtension::class)) {
         /** @noinspection PhpInternalEntityUsedInspection */
         $methods = InjectExtension::getInjectMethods($presenter);
         // Nette 2.3+
     } else {
         $methods = [];
         foreach (get_class_methods($presenter) as $method) {
             if (substr($method, 0, 6) === 'inject') {
                 $methods[] = $method;
             }
         }
     }
     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]);
         }
     }
 }
All Usage Examples Of Nette\DI\Extensions\InjectExtension::getInjectMethods