Example #1
0
 public function execute($actionId, $method, $uriFragments, $parameters, $headers, RecordInterface $body = null)
 {
     $action = $this->actionTable->get($actionId);
     if (!empty($action)) {
         if ($body === null) {
             $body = new Record();
         }
         $app = $this->appRepository->get(1);
         $user = $this->userRepository->get(1);
         $uriFragments = $this->parseQueryString($uriFragments);
         $parameters = $this->parseQueryString($parameters);
         $headers = $this->parseQueryString($headers);
         $context = new Context($actionId, $app, $user);
         $request = new Request(new HttpRequest(new Uri('/'), $method, $headers), $uriFragments, $parameters, $body);
         return $this->processor->execute($action->id, $request, $context);
     } else {
         return null;
     }
 }
Example #2
0
 public function delete($actionId)
 {
     $action = $this->actionTable->get($actionId);
     if (!empty($action)) {
         // check depending
         if ($this->routesMethodTable->hasAction($actionId)) {
             throw new StatusCode\BadRequestException('Cannot delete action because a route depends on it');
         }
         // delete route dependencies
         $this->routesActionTable->deleteByAction($action['id']);
         $this->actionTable->delete(array('id' => $action['id']));
     } else {
         throw new StatusCode\NotFoundException('Could not find action');
     }
 }
Example #3
0
 protected function getDependingActionsByAction($actionId)
 {
     $action = $this->actionTable->get($actionId);
     $config = $action->config;
     $form = $this->actionParser->getForm($action->class);
     $actions = [];
     if ($form instanceof Form\Container) {
         $elements = $form->getElements();
         foreach ($elements as $element) {
             if ($element instanceof Form\Element\Action) {
                 $name = $element->getName();
                 if (isset($config[$name]) && is_int($config[$name])) {
                     $actions[] = $config[$name];
                     $actions = array_merge($actions, $this->getDependingActionsByAction($config[$name]));
                 }
             }
         }
     }
     return array_unique($actions);
 }
Example #4
0
 protected function buildRepository($actionId, Repository\ActionInterface $repository)
 {
     $action = $this->actionTable->get($actionId);
     $config = $action->config;
     $form = $this->actionParser->getForm($action->class);
     if ($form instanceof Form\Container) {
         $elements = $form->getElements();
         foreach ($elements as $element) {
             if ($element instanceof Form\Element\Action) {
                 $name = $element->getName();
                 if (isset($config[$name]) && $config[$name] > 0) {
                     $this->buildRepository($config[$name], $repository);
                 }
             }
         }
     }
     $entry = new Model\Action();
     $entry->setId($action['id']);
     $entry->setName($action['name']);
     $entry->setClass($action['class']);
     $entry->setConfig($action['config']);
     $entry->setDate($action['date']->format('Y-m-d H:i:s'));
     $repository->add($entry);
 }