Example #1
0
 /**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = Module::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]);
 }
Example #2
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Module::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['actions']));
     $resource = $resource->fields($params->getFields(['module' => Module::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());
 }
Example #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();
 }
Example #5
0
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function module($model)
 {
     $serializer = Module::getSerializer();
     $id = $serializer->getId($model->getModule());
     if ($id !== null) {
         $relationship = new Relationship(new Resource($model->getModule(), $serializer));
         $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]);
         return $this->addRelationshipSelfLink($relationship, $model, 'module');
     }
     return null;
 }
Example #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();
 }
Example #7
0
 /**
  * Filter the query by a related \keeko\core\model\Module object
  *
  * @param \keeko\core\model\Module|ObjectCollection $module The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @throws \Propel\Runtime\Exception\PropelException
  *
  * @return ChildActionQuery The current query, for fluid interface
  */
 public function filterByModule($module, $comparison = null)
 {
     if ($module instanceof \keeko\core\model\Module) {
         return $this->addUsingAlias(ActionTableMap::COL_MODULE_ID, $module->getId(), $comparison);
     } elseif ($module instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ActionTableMap::COL_MODULE_ID, $module->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByModule() only accepts arguments of type \\keeko\\core\\model\\Module or Collection');
     }
 }
Example #8
0
 /**
  * Filter the query by a related \keeko\core\model\Module object
  *
  * @param \keeko\core\model\Module|ObjectCollection $module the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildPackageQuery The current query, for fluid interface
  */
 public function filterByModule($module, $comparison = null)
 {
     if ($module instanceof \keeko\core\model\Module) {
         return $this->addUsingAlias(PackageTableMap::COL_ID, $module->getId(), $comparison);
     } elseif ($module instanceof ObjectCollection) {
         return $this->useModuleQuery()->filterByPrimaryKeys($module->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByModule() only accepts arguments of type \\keeko\\core\\model\\Module or Collection');
     }
 }
Example #9
0
 /**
  * Sets a single ChildModule object as related to this object by a one-to-one relationship.
  *
  * @param  ChildModule $v ChildModule
  * @return $this|\keeko\core\model\Package The current object (for fluent API support)
  * @throws PropelException
  */
 public function setModule(ChildModule $v = null)
 {
     $this->singleModule = $v;
     // Make sure that that the passed-in ChildModule isn't already associated with this object
     if ($v !== null && $v->getPackage(null, false) === null) {
         $v->setPackage($this);
     }
     return $this;
 }
Example #10
0
 /**
  * Loads the given action
  *
  * @param Action|string $actionName
  * @param string $format the response type (e.g. html, json, ...)
  * @return AbstractAction
  */
 public function loadAction($nameOrAction, $format = null)
 {
     $model = null;
     if ($nameOrAction instanceof Action) {
         $model = $nameOrAction;
         $actionName = $nameOrAction->getName();
     } else {
         $actionName = $nameOrAction;
     }
     if (!isset($this->actions[$actionName])) {
         throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName()));
     }
     if ($model === null) {
         $model = $this->actions[$actionName]['model'];
     }
     /* @var $action ActionSchema */
     $action = $this->actions[$actionName]['action'];
     // check permission
     if (!$this->service->getFirewall()->hasActionPermission($model)) {
         throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName()));
     }
     // check if a response is given
     if ($format !== null) {
         if (!$action->hasResponder($format)) {
             throw new ModuleException(sprintf('No Responder (%s) given for Action (%s) in Module (%s)', $format, $actionName, $this->model->getName()));
         }
         $responseClass = $action->getResponder($format);
         if (!class_exists($responseClass)) {
             throw new ModuleException(sprintf('Responder (%s) not found in Module (%s)', $responseClass, $this->model->getName()));
         }
         $responder = new $responseClass($this);
     } else {
         $responder = new NullResponder($this);
     }
     // gets the action class
     $className = $model->getClassName();
     if (!class_exists($className)) {
         throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName()));
     }
     $class = new $className($model, $this, $responder);
     // locales
     // ------------
     $localeService = $this->getServiceContainer()->getLocaleService();
     // load module l10n
     $file = sprintf('/%s/locales/{locale}/translations.json', $this->package->getFullName());
     $localeService->loadLocaleFile($file, $class->getCanonicalName());
     // 		// load additional l10n files
     // 		foreach ($action->getL10n() as $file) {
     // 			$file = sprintf('/%s/locales/{locale}/%s', $this->package->getFullName(), $file);
     // 			$localeService->loadLocaleFile($file, $class->getCanonicalName());
     // 		}
     // 		// load action l10n
     // 		$file = sprintf('/%s/locales/{locale}/actions/%s', $this->package->getFullName(), $actionName);
     // 		$localeService->loadLocaleFile($file, $class->getCanonicalName());
     // assets
     // ------------
     $app = $this->getServiceContainer()->getKernel()->getApplication();
     $page = $app->getPage();
     // scripts
     foreach ($action->getScripts() as $script) {
         $page->addScript($script);
     }
     // styles
     foreach ($action->getStyles() as $style) {
         $page->addStyle($style);
     }
     return $class;
 }
Example #11
0
 /**
  * Interal mechanism to remove Actions from Module
  * 
  * @param Module $model
  * @param mixed $data
  */
 protected function doRemoveActions(Module $model, $data)
 {
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Action';
         } else {
             $related = ActionQuery::create()->findOneById($entry['id']);
             $model->removeAction($related);
         }
     }
     if (count($errors) > 0) {
         return new ErrorsException($errors);
     }
 }
Example #12
0
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $serializer = Module::getSerializer();
     $relationship = $serializer->actions($payload->getModel());
     return new JsonResponse($relationship->toArray());
 }
Example #13
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aModule) {
         $this->aModule->removeAction($this);
     }
     $this->id = null;
     $this->name = null;
     $this->title = null;
     $this->description = null;
     $this->class_name = null;
     $this->module_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Example #14
0
 /**
  * Exclude object from result
  *
  * @param   ChildModule $module Object to remove from the list of results
  *
  * @return $this|ChildModuleQuery The current query, for fluid interface
  */
 public function prune($module = null)
 {
     if ($module) {
         $this->addUsingAlias(ModuleTableMap::COL_ID, $module->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }