Beispiel #1
0
 private static function addSingleton(ReflectionClass $reflClass)
 {
     if ($reflClass->hasMethod('getInstance')) {
         $type = $reflClass->getName();
         $service = $type::getInstance();
     } else {
         $service = ClassInvoker::getNewInstanceByRefl($reflClass);
     }
     Collection::add(self::getName($reflClass), $service);
 }
Beispiel #2
0
 public static function invoke($instance, $methodName, $args = array())
 {
     $className = get_class($instance);
     $reflClass = new ReflectionClass($className);
     if (!$reflClass->hasMethod($methodName)) {
         throw new BadMethodCallException("The '{$methodName}' method is not exists in {$className}");
     }
     $reflMethod = $reflClass->getMethod($methodName);
     $annotations = $reflMethod->getAnnotations();
     foreach (InvokerConfig::getMethodBeforeHandlers($reflMethod) as $methodAnnotationHandler) {
         $methodAnnotationHandler->run($reflMethod, $instance);
     }
     $expectedParameterSize = sizeof($reflMethod->getParameters());
     $invokeParams = (new InvokeParameterHandler($annotations, $reflMethod, $args))->run();
     if ($expectedParameterSize > sizeof($invokeParams)) {
         throw new BadMethodCallException("Not found all expected method parameter: {$className}::{$methodName}()");
     }
     return $reflMethod->invokeArgs($instance, $invokeParams);
 }
Beispiel #3
0
 private function addSingleton(ReflectionClass $reflClass, $name = null)
 {
     if ($reflClass->hasMethod('getInstance')) {
         $type = $reflClass->getName();
         $service = $type::getInstance();
     } else {
         $service = ClassInvoker::getNewInstanceByRefl($reflClass);
     }
     $this->add($this->getName($reflClass, $name), $service);
 }