Exemplo n.º 1
0
 /**
  * @param \ReflectionMethod $method
  * @param string $type
  * @return BeforeActionFilter[]|\Facilius\AfterActionFilter[]
  */
 private function getActionFilters(ReflectionMethod $method, $type)
 {
     $docCommentValues = ReflectionUtil::getDocCommentValues($method);
     $filterNames = @$docCommentValues[$type . '-filter'] ?: array();
     $filters = array();
     foreach ($filterNames as $filterName) {
         $filters[] = $this->actionFilterFactory->create($filterName);
     }
     return $filters;
 }
Exemplo n.º 2
0
 private function bindComplexModel(BindingContext $context)
 {
     $type = $context->type;
     if (!class_exists($type)) {
         return null;
     }
     $class = new ReflectionClass($type);
     $ctor = $class->getConstructor();
     if ($ctor && count($params = $ctor->getParameters()) > 0) {
         if (!array_reduce($params, function ($current, $next) {
             return $current && $next->isOptional();
         }, true)) {
             //constructor has non-optional parameters, so we can't instantiate this without some inside knowledge
             return null;
         }
     }
     $object = $class->newInstance();
     $properties = $class->getProperties(ReflectionProperty::IS_PUBLIC);
     foreach ($properties as $property) {
         $name = $property->getName();
         $propertyType = ReflectionUtil::getPropertyType($property, $nullable);
         $propertyBinder = $context->actionContext->modelBinders->getBinderOrDefault($propertyType);
         $potentialValues = $context->values;
         if (ReflectionUtil::isComplexType($propertyType)) {
             $lowerName = strtolower($name);
             foreach ($potentialValues as $key => $value) {
                 if (strpos(strtolower($key), $lowerName . '.') === 0) {
                     $potentialValues[substr($key, strlen($lowerName) + 1)] = $value;
                 } else {
                     unset($potentialValues[$key]);
                 }
             }
         }
         $newContext = new BindingContext($potentialValues, $context->actionContext, $name, $propertyType);
         $property->setValue($object, $propertyBinder->bindModel($newContext));
     }
     return $object;
 }
Exemplo n.º 3
0
 public function testDetectTypeHintedParameterTypes()
 {
     $params = $this->class->getMethod('foo')->getParameters();
     self::assertEquals('ReflectionClass', ReflectionUtil::getParameterType($params[3]));
 }