Beispiel #1
0
 /**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = Api::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]);
 }
Beispiel #2
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Api::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['action']));
     $resource = $resource->fields($params->getFields(['api' => Api::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $data = $payload->getModel();
     $serializer = Action::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['module', 'groups', 'apis']));
     $resource = $resource->fields($params->getFields(['action' => Action::getSerializer()->getFields(), 'module' => Module::getSerializer()->getFields(), 'group' => Group::getSerializer()->getFields(), 'api' => Api::getSerializer()->getFields()]));
     $document = new Document($resource);
     // meta
     if ($params->getPage('size') != -1) {
         $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]);
     }
     // return response
     return new JsonResponse($document->toArray());
 }
Beispiel #4
0
 private function updateApi(Module $model, ModuleSchema $module, $actions)
 {
     $repo = $this->service->getResourceRepository();
     $filename = sprintf('/packages/%s/api.json', $model->getName());
     if (!$repo->contains($filename)) {
         return;
     }
     // delete every api existent for the given module prior to create the new ones
     ApiQuery::create()->filterByActionId(array_values($actions))->delete();
     // 		$extensions = $this->service->getExtensionRegistry()->getExtensionsByPackage('keeko.api', $model->getName());
     $json = Json::decode($repo->get($filename)->getBody());
     $swagger = new Swagger($json);
     foreach ($swagger->getPaths() as $path) {
         /* @var $path Path */
         foreach (Swagger::$METHODS as $method) {
             if ($path->hasOperation($method)) {
                 $op = $path->getOperation($method);
                 $actionName = $op->getOperationId();
                 if (!isset($actions[$actionName])) {
                     continue;
                 }
                 // find required parameters
                 $required = [];
                 foreach ($op->getParameters() as $param) {
                     /* @var $param Parameter */
                     if ($param->getIn() == 'path' && $param->getRequired()) {
                         $required[] = $param->getName();
                     }
                 }
                 // 					$prefix = isset($extensions[$actionName])
                 // 						? $extensions[$actionName]
                 // 						: $module->getSlug();
                 $prefix = $module->getSlug();
                 $fullPath = str_replace('//', '/', $prefix . '/' . $path->getPath());
                 $api = new Api();
                 $api->setMethod($method);
                 $api->setRoute($fullPath);
                 $api->setActionId($actions[$actionName]);
                 $api->setRequiredParams(implode(',', $required));
                 $api->save();
             }
         }
     }
     $model->setApi(true);
     $model->save();
 }
Beispiel #5
0
 /**
  */
 public function getRelationships()
 {
     return ['module' => Module::getSerializer()->getType(null), 'groups' => Group::getSerializer()->getType(null), 'apis' => Api::getSerializer()->getType(null)];
 }
Beispiel #6
0
 private function installApi(Module $module, $data, $actionMap)
 {
     if (!isset($data['api'])) {
         return;
     }
     if (!isset($data['api']['apis'])) {
         return;
     }
     $base = '/';
     if (isset($data['api']['resourcePath'])) {
         $base = $data['api']['resourcePath'];
     }
     foreach ($data['api']['apis'] as $apis) {
         $path = $apis['path'];
         foreach ($apis['operations'] as $op) {
             // fetch required params
             $required = [];
             if (isset($op['parameters'])) {
                 foreach ($op['parameters'] as $param) {
                     if (isset($param['paramType']) && $param['paramType'] == 'path') {
                         $required[] = $param['name'];
                     }
                 }
             }
             // create record
             $fullPath = str_replace('//', '/', $base . '/' . $path);
             $api = new Api();
             $api->setMethod($op['method']);
             $api->setRoute($fullPath);
             $api->setActionId($actionMap[$op['nickname']]);
             $api->setRequiredParams(implode(',', $required));
             $api->save();
         }
     }
     $module->setApi(true);
     $module->save();
 }
Beispiel #7
0
 /**
  * Filter the query by a related \keeko\core\model\Api object
  *
  * @param \keeko\core\model\Api|ObjectCollection $api the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildActionQuery The current query, for fluid interface
  */
 public function filterByApi($api, $comparison = null)
 {
     if ($api instanceof \keeko\core\model\Api) {
         return $this->addUsingAlias(ActionTableMap::COL_ID, $api->getActionId(), $comparison);
     } elseif ($api instanceof ObjectCollection) {
         return $this->useApiQuery()->filterByPrimaryKeys($api->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByApi() only accepts arguments of type \\keeko\\core\\model\\Api or Collection');
     }
 }
Beispiel #8
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function read(Request $request, Found $payload)
 {
     $serializer = Api::getSerializer();
     $relationship = $serializer->action($payload->getModel());
     return new JsonResponse($relationship->toArray());
 }
Beispiel #9
0
 /**
  * @param ChildApi $api The ChildApi object to add.
  */
 protected function doAddApi(ChildApi $api)
 {
     $this->collApis[] = $api;
     $api->setAction($this);
 }
Beispiel #10
0
 /**
  * Exclude object from result
  *
  * @param   ChildApi $api Object to remove from the list of results
  *
  * @return $this|ChildApiQuery The current query, for fluid interface
  */
 public function prune($api = null)
 {
     if ($api) {
         $this->addUsingAlias(ApiTableMap::COL_ID, $api->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #11
0
 /**
  * Internal mechanism to set the Action id
  * 
  * @param Api $model
  * @param mixed $relatedId
  */
 protected function doSetActionId(Api $model, $relatedId)
 {
     if ($model->getActionId() !== $relatedId) {
         $model->setActionId($relatedId);
         return true;
     }
     return false;
 }