Ejemplo n.º 1
0
 public function call($className, $methodName, array $arguments = [])
 {
     $class = $this->container->get($className);
     if (A7::methodExists($class, $methodName)) {
         $reflectorMethod = ReflectionUtils::getInstance()->getMethodReflection($className, $methodName);
         foreach ($reflectorMethod->getParameters() as $param) {
             if (isset($arguments[$param->name])) {
                 $paramRefClass = $param->getClass();
                 if ($paramRefClass instanceof \ReflectionClass) {
                     $parentClass = $paramRefClass->getParentClass();
                     if ($parentClass && $parentClass->name == 'MD\\Helpers\\Model') {
                         if (!$arguments[$param->name] instanceof Model) {
                             $arguments[$param->name] = new $paramRefClass->name($arguments[$param->name]);
                         }
                     } elseif ($paramRefClass->name == 'DateTime') {
                         if (!$arguments[$param->name] instanceof \DateTime) {
                             $arguments[$param->name] = new \DateTime($arguments[$param->name]);
                         }
                     }
                 }
             }
         }
     } else {
         throw new UndefinedMethodException();
     }
     return $this->container->call($class, $methodName, $arguments);
 }
Ejemplo n.º 2
0
 public function getMethodsAnnotations($className)
 {
     $key = 'A7-MA-' . $className;
     if (!$this->inCache($key)) {
         $reflectionMethods = ReflectionUtils::getInstance()->getMethodsReflection($className);
         $methodsAnnotations = [];
         foreach ($reflectionMethods as $reflectionMethod) {
             $methodsAnnotations[$reflectionMethod->getName()] = self::toAssoc($this->annotationReader->getMethodAnnotations($reflectionMethod));
         }
         $this->setCache($key, $methodsAnnotations);
     }
     return $this->getCache($key);
 }
Ejemplo n.º 3
0
 /**
  * @param $instance
  * @param $class
  * @param PostProcessInterface[] $postProcessors
  * @param null|Proxy $proxyInstance
  * @return mixed
  */
 public function doPostProcessors($instance, $class, array $postProcessors, $proxyInstance = null)
 {
     foreach ($postProcessors as $postProcessor) {
         $instance = $postProcessor->postProcessBeforeInitialization($instance, $class);
     }
     $className = get_class($instance);
     $methodsAnnotations = $this->annotationManager->getMethodsAnnotations($className);
     foreach ($methodsAnnotations as $method => $annotations) {
         if (isset($annotations['Init'])) {
             $methodReflection = ReflectionUtils::getInstance()->getMethodReflection($className, $method);
             $methodReflection->setAccessible(true);
             $methodReflection->invoke($instance);
         }
     }
     foreach ($postProcessors as $postProcessor) {
         if (isset($proxyInstance)) {
             $postProcessor->postProcessAfterInitialization($proxyInstance, $class);
         } else {
             $instance = $postProcessor->postProcessAfterInitialization($instance, $class);
         }
     }
     return $instance;
 }