예제 #1
0
 /**
  * Builds a ModelDefinition from a method's argument
  * 
  * @param ReflectionMethod $method
  * @param array $additionalAnnotations
  * @param array $excludeParams
  * @return ModelDefinition
  */
 protected function buildModelFromMethod(ReflectionMethod $method, array $additionalAnnotations = array(), array $excludeParams = array())
 {
     $model = new ModelDefinition();
     $model->setValidator(Validation::createValidator());
     $paramComments = array();
     if (preg_match_all('/@param ([a-zA-Z\\\\]+) \\$([a-zA-Z_0-9]+)( .+)?$/m', $method->getDocComment(), $results)) {
         for ($i = 0, $c = count($results[0]); $i < $c; $i++) {
             $paramComments[$results[2][$i]] = array('type' => $results[1][$i], 'description' => trim($results[3][$i]));
         }
     }
     foreach ($method->getParameters() as $param) {
         if (in_array($param->getName(), $excludeParams)) {
             continue;
         }
         $com = isset($paramComments[$param->getName()]) ? $paramComments[$param->getName()] : null;
         $annotation = null;
         foreach ($additionalAnnotations as $anno) {
             if ($anno instanceof \Nucleus\IService\Dashboard\ModelField && $anno->property == $param->getName()) {
                 $annotation = $anno;
                 break;
             }
         }
         if (!$com) {
             if ($param->isArray()) {
                 $type = 'array';
             } else {
                 if ($type = $param->getClass()) {
                     $type = $type->getName();
                 }
             }
         } else {
             $type = $com['type'];
         }
         if (in_array($type, array('Symfony\\Component\\HttpFoundation\\Request', 'Symfony\\Component\\HttpFoundation\\Response', 'Nucleus\\Dashboard\\Dashboard'))) {
             continue;
         }
         if ($annotation) {
             $field = $this->buildField($annotation);
         } else {
             $field = new FieldDefinition();
         }
         $field->setProperty($param->getName())->setType($type ?: 'string')->setDescription($com ? $com['description'] : null)->setOptional($param->isOptional());
         if (class_exists($type)) {
             $field->setRelatedModel($this->buildModel($type));
         }
         $validateAnnotations = array_filter($additionalAnnotations, function ($a) use($param) {
             return $a instanceof \Nucleus\IService\Dashboard\Validate && $a->property == $param->getName();
         });
         $this->applyFieldConstraintsFromAnnotations($field, $validateAnnotations);
         $model->addField($field);
     }
     return $model;
 }
예제 #2
0
 /**
  * Returns the schema for model actions
  *
  * @param ControllerDefinition $controller
  * @param ActionDefinition $action
  * @param ModelDefinition $model
  */
 public function getActionActionsSchema(ControllerDefinition $controller, ActionDefinition $action, ModelDefinition $model)
 {
     $self = $this;
     $controllerActions = $controller->getActionsForModel($model->getClassName());
     $modelActions = array();
     foreach ($model->getActions() as $a) {
         if ($a->isAppliedToModel()) {
             $modelActions[] = $a;
         } else {
             $controllerActions[] = $a;
         }
     }
     return array_merge(array_values(array_filter(array_map(function ($modelAction) use($controller, $action, $self) {
         if (!$self->accessControl->checkPermissions($modelAction->getPermissions())) {
             return false;
         }
         return array_merge($self->getLimitedActionSchema($modelAction), array('behaviors' => $self->getBehaviorsSchema($controller, $modelAction), 'name' => $action->getName() . '/' . $modelAction->getName(), 'controller' => $controller->getName(), 'url' => $self->routing->generate('dashboard.invokeModel', array('controllerName' => $controller->getName(), 'actionName' => $action->getName(), 'modelActionName' => $modelAction->getName()))));
     }, $modelActions))), array_values(array_filter(array_map(function ($action) use($controller, $self) {
         if (!$self->accessControl->checkPermissions($action->getPermissions())) {
             return false;
         }
         return array_merge($self->getLimitedActionSchema($action), array('behaviors' => $self->getBehaviorsSchema($controller, $action), 'controller' => $controller->getName(), 'url' => $self->routing->generate('dashboard.invoke', array('controllerName' => $controller->getName(), 'actionName' => $action->getName()))));
     }, $controllerActions))));
 }