コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function process($context, Result $result, Collection $collection)
 {
     $routes = $this->locateRoutesForClass($context->getContext()->getClass());
     if (empty($routes)) {
         return;
     }
     $resource = $context->getAnnotation()->toModel();
     foreach ($routes as $route) {
         $function = $this->extractFunctionFromRoute($route);
         foreach ($route->getMethods() as $method) {
             $operation = new Operation(sprintf('%s/%s/%s', $resource->getId(), $method, $function));
             $operation->setMethod($method);
             $operation->setPath($route->getPath());
             foreach ($this->extractParametersFromRoute($route) as $parameter) {
                 $operation->addParameter($parameter);
             }
             if ($this->versionOperation) {
                 $operation = $this->versionOperation->version($operation, $result, $route);
             }
             if (!is_array($operation)) {
                 $operation = array($operation);
             }
             foreach ($operation as $value) {
                 $resource->addOperation($value);
             }
         }
     }
     $result->set('resource', $resource->getId(), $resource);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function version(Operation $operation, Result $result, Route $route)
 {
     if (!$operation->hasParameter($this->parameter)) {
         return $operation;
     }
     $version = $operation->getParameter($this->parameter);
     $operation->removeParameter($this->parameter);
     if (!($versions = $version->getType()->getEnum())) {
         $requirements = $route->getRequirements();
         $versions = array($requirements[$this->parameter]);
     }
     $operations = array();
     foreach ($versions as $version) {
         $op = clone $operation;
         $op->setVersion($version);
         $op->setPath(str_replace(sprintf('{%s}', $this->parameter), $version, $op->getPath()));
         $operations[] = $op;
     }
     return count($operations) === 1 ? current($operations) : $operations;
 }
コード例 #3
0
ファイル: Transformer.php プロジェクト: dokapi/dokapi-rest
 /**
  * @param Operation $operation operation
  *
  * @return array|null
  */
 private function getTypeOfOperation(OperationModel $operation)
 {
     $responsesByCode = array();
     $chosen = false;
     foreach ($operation->getResponses() as $response) {
         if ($response->getCode() === 200) {
             $chosen = $response;
             break;
         }
         if (substr($response->getCode(), 0, 1) == 2) {
             $responsesByCode[$response->getCode()] = $response;
         }
     }
     if (!$chosen) {
         if (count($responsesByCode) === 0) {
             return null;
         }
         ksort($responsesByCode);
         $chosen = current($responsesByCode);
     }
     return $this->transformDataTypeAsArray($chosen->getType());
 }