public static function getMethodBeforeHandlers(ReflectionMethod $reflMethod) { $ret = array(); foreach ($reflMethod->getAnnotations() as $annotation) { $clazz = null; $aclass = get_class($annotation); if (array_key_exists($aclass, self::$beforeHandlers)) { $clazz = self::$beforeHandlers[$aclass]; } if (!$clazz) { $bclass = \explode(self::NAMESPACE_SEPARATOR, $aclass); $bclass = end($bclass); //die(); foreach (self::$annotationHandlerNamespaces as $ns) { $class = trim($ns, self::NAMESPACE_SEPARATOR) . self::NAMESPACE_SEPARATOR . $bclass . 'Handler'; try { if (class_exists($class)) { $clazz = $class; self::$beforeHandlers[$aclass] = $class; break; } } catch (Exception $e) { //do nothing } } } if ($clazz) { $ret[] = ClassInvoker::getNewInstance($clazz, array('annotation' => $annotation)); } } return $ret; }
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); }
public function getInstance() { if ($this->getReflClass()->hasMethod('getInstance')) { $type = $this->getReflClass()->getName(); $service = $type::getInstance(); } else { $service = ClassInvoker::getNewInstanceByRefl($this->getReflClass()); } Collection::add($this->getName(), $service); return $service; }
public static function getAnnotationHandler($annotationType) { if (is_object($annotationType)) { $annotationType = get_class($annotationType); } $annotationType = substr($annotationType, strrpos($annotationType, '\\') + 1); $found = false; ApplicationTimer::start(); foreach (self::$annotationHandlerNamespaces as $ns) { $handler = $ns . '\\' . $annotationType . 'Handler'; if (class_exists($handler)) { $found = $handler; break; } } ApplicationTimer::stop(); if ($found !== false) { return ClassInvoker::getNewInstance($found); } else { return null; } }
/** * @test * @expectedException RuntimeException * @expectedExceptionMessage The className parameter must be string or instanceof ReflectionClass */ public function invokeWithObject() { ClassInvoker::getNewInstance(new ClassInvokerFixture()); }
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); }
private function fillForm($form, $request = null) { $class = new ReflectionClass($form); /* @var $property ReflectionProperty */ foreach ($class->getProperties() as $property) { $value = array_key_exists($property->getName(), (array) $request) ? $request[$property->getName()] : null; $type = Helper::getPropertyType($property); if (!$this->isPrimitive($type)) { $value = $this->fillForm(ClassInvoker::getNewInstance($type), $value); } $this->setFormFieldValue($property, $form, $value); } return $form; }
public function getInstance() { return ClassInvoker::getNewInstanceByRefl($this->getReflClass()); }