示例#1
0
 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;
 }
示例#2
0
 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;
     }
 }
示例#3
0
 /**
  * @test
  * @expectedException RuntimeException
  * @expectedExceptionMessage The className parameter must be string or instanceof ReflectionClass
  */
 public function invokeWithObject()
 {
     ClassInvoker::getNewInstance(new ClassInvokerFixture());
 }
示例#4
0
 public function createBean($bean)
 {
     switch (true) {
         case is_string($bean) && class_exists($bean):
             if (method_exists($bean, 'getInstance')) {
                 $this->add($bean, $bean::getInstance());
             } else {
                 $this->add($bean, ClassInvoker::getNewInstance($bean));
             }
             break;
         default:
             break;
     }
 }
 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;
 }