public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     if ($method->name == 'cgetAction' && (is_subclass_of($method->class, 'KwfBundle\\Controller\\FOSRestModelController') || $method->class == 'KwfBundle\\Controller\\FOSRestModelController')) {
         $annotation->addParameter('limit', array('required' => true, 'dataType' => 'int', 'default' => '25'));
         $annotation->addParameter('start', array('required' => true, 'dataType' => 'int', 'default' => '0'));
         $annotation->addParameter('sort', array('required' => false, 'dataType' => 'string', 'default' => ''));
         $annotation->addParameter('query', array('required' => false, 'dataType' => 'string', 'default' => null));
         $annotation->addParameter('filter', array('required' => false, 'dataType' => 'json string', 'default' => null));
     }
 }
 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     foreach ($annotations as $annot) {
         if ($annot instanceof RequestParam) {
             $annotation->addParameter($annot->name, array('required' => $annot->strict && $annot->default === null, 'dataType' => $annot->requirements, 'description' => $annot->description, 'readonly' => false));
         } elseif ($annot instanceof QueryParam) {
             if ($annot->strict && $annot->default === null) {
                 $annotation->addRequirement($annot->name, array('requirement' => $annot->requirements, 'dataType' => '', 'description' => $annot->description));
             } elseif ($annot->default !== null) {
                 $annotation->addFilter($annot->name, array('requirement' => $annot->requirements, 'description' => $annot->description, 'default' => $annot->default));
             } else {
                 $annotation->addFilter($annot->name, array('requirement' => $annot->requirements, 'description' => $annot->description));
             }
         }
     }
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     foreach ($annotations as $annot) {
         if ($annot instanceof RequestParam) {
             $requirements = $this->handleRequirements($annot->requirements);
             $data = array('required' => $annot->strict && $annot->nullable === false && $annot->default === null, 'dataType' => $requirements . ($annot->array ? '[]' : ''), 'actualType' => $this->inferType($requirements), 'subType' => null, 'description' => $annot->description, 'readonly' => false);
             if ($annot->strict === false) {
                 $data['default'] = $annot->default;
             }
             $annotation->addParameter($annot->name, $data);
         } elseif ($annot instanceof QueryParam) {
             if ($annot->strict && $annot->nullable === false && $annot->default === null) {
                 $annotation->addRequirement($annot->name, array('requirement' => $this->handleRequirements($annot->requirements) . ($annot->array ? '[]' : ''), 'dataType' => '', 'description' => $annot->description));
             } elseif ($annot->default !== null) {
                 $annotation->addFilter($annot->name, array('requirement' => $this->handleRequirements($annot->requirements) . ($annot->array ? '[]' : ''), 'description' => $annot->description, 'default' => $annot->default));
             } else {
                 $annotation->addFilter($annot->name, array('requirement' => $this->handleRequirements($annot->requirements) . ($annot->array ? '[]' : ''), 'description' => $annot->description));
             }
         }
     }
 }
Пример #4
0
 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     if (!($objectName = $route->getDefault('_jarves_object')) || !($object = $this->objects->getDefinition($objectName))) {
         return;
     }
     if ($entryPointPath = $route->getDefault('_jarves_entry_point')) {
         $adminUtils = new \Jarves\Admin\Utils($this->jarves);
         $entryPoint = $adminUtils->getEntryPoint($entryPointPath);
         $annotation->setSection(sprintf('%s %s %s', $entryPoint->isFrameworkWindow() ? 'Framework Window: ' : '', $entryPoint->getBundle() ? ($entryPoint->getBundle()->getLabel() ?: $entryPoint->getBundle()->getBundleName()) . ', ' : 'No Bundle, ', $entryPoint->getLabel() ?: $entryPoint->getPath()));
     } else {
         $objectKey = $route->getDefault('_jarves_object_section') ?: $route->getDefault('_jarves_object');
         $objectSection = $this->objects->getDefinition($objectKey);
         $annotation->setSection(sprintf('Object %s', $objectKey));
     }
     $filters = $annotation->getFilters();
     if (@$filters['fields']) {
         $fields = [];
         foreach ($object->getFields() as $field) {
             if ('object' === $field->getId()) {
                 $foreignObject = $this->objects->getDefinition($field->getObject());
                 foreach ($foreignObject->getFields() as $fField) {
                     $filters[] = $field->getId() . '.' . $fField->getId();
                 }
             } else {
                 $fields[] = $field->getId();
             }
         }
         $annotation->addFilter('fields', ['requirement' => '.*', 'description' => "Comma separated list of fields. Possible fields to select: \n" . implode(', ', $fields)]);
     }
     $annotation->setDescription(str_replace('%object%', $object->getBundle()->getBundleName() . ':' . lcfirst($object->getId()), $annotation->getDescription()));
     $isRelationRoute = $route->getDefault('_jarves_object_relation');
     $requirePk = $route->getDefault('_jarves_object_requirePk');
     $method = explode(':', $route->getDefault('_controller'))[1];
     //        maybe in version 1.1
     //        if ($isRelationRoute) {
     //            $objectKey = $route->getDefault('_jarves_object_section') ? : $route->getDefault('_jarves_object');
     //            $objectParent = $this->jarves->getObjects()->getDefinition($objectKey);
     //
     //            foreach ($objectParent->getFields() as $field) {
     //                if ($field->isPrimaryKey()) {
     //                    $annotation->addRequirement(
     //                        $field->getId(),
     //                        [
     //                            'requirement' => $field->getRequiredRegex(),
     //                            'dataType' => $field->getPhpDataType(),
     //                            'description' => '(' . $objectParent->getId() . ') ' . $field->getDescription()
     //                        ]
     //                    );
     //                }
     //            }
     //        }
     if ($requirePk) {
         foreach ($object->getFields() as $field) {
             if (!$field->hasFieldType()) {
                 continue;
             }
             if ($field->isPrimaryKey()) {
                 $annotation->addRequirement(($isRelationRoute ? lcfirst($object->getId()) . '_' : '') . $field->getId(), ['requirement' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'description' => $isRelationRoute ? '(' . $object->getId() . ') ' : '']);
             }
         }
     }
     //add all fields to some actions
     if (in_array($method, ['addItemAction', 'patchItemAction', 'updateItemAction'])) {
         foreach ($object->getFields() as $field) {
             if (!$field->hasFieldType()) {
                 continue;
             }
             if ($field->isRequired() && !$field->getDefault()) {
                 $annotation->addRequirement($field->getId(), array('requirement' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'description' => ($isRelationRoute ? '(' . $object->getId() . ') ' : '') . $field->getLabel()));
             } else {
                 $annotation->addParameter($field->getId(), array('format' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'default' => $field->getDefault(), 'description' => $field->getLabel() . ($field->isAutoIncrement() ? ' (autoIncremented)' : ''), 'readonly' => false, 'required' => false));
             }
         }
     }
 }
 /**
  * Parses annotations for a given method, and adds new information to the given ApiDoc
  * annotation. Useful to extract information from the FOSRestBundle annotations.
  *
  * @param ApiDoc           $annotation
  * @param Route            $route
  * @param ReflectionMethod $method
  */
 protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
 {
     foreach ($this->reader->getMethodAnnotations($method) as $annot) {
         if (is_a($annot, self::FOS_REST_QUERY_PARAM_CLASS)) {
             if ($annot->strict) {
                 $annotation->addRequirement($annot->name, array('requirement' => $annot->requirements, 'dataType' => '', 'description' => $annot->description));
             } else {
                 $annotation->addFilter($annot->name, array('requirement' => $annot->requirements, 'description' => $annot->description));
             }
         } elseif (is_a($annot, self::FOS_REST_REQUEST_PARAM_CLASS)) {
             $annotation->addParameter($annot->name, array('required' => !$annot->nullable, 'dataType' => $annot->requirements, 'description' => $annot->description, 'readonly' => false));
         }
     }
 }