Пример #1
0
 public function execute(CommandInterface $command)
 {
     if ($command->getName() !== CommandInterface::COMMAND_CREATE) {
         throw new \InvalidArgumentException("Command type \" {$command->getName()} not supported");
     }
     return $this->create($command->getClass(), $command->getParams());
 }
Пример #2
0
 public function execute(CommandInterface $command)
 {
     switch ($command->getName()) {
         case CommandInterface::COMMAND_FIND:
             $criteria = $command->getParams("criteria", []);
             $limit = $command->getParams("limit", null);
             $offset = $command->getParams("offset", null);
             $order = $command->getParams("order", null);
             return $this->find($criteria, $limit, $offset, $order);
         case CommandInterface::COMMAND_GET:
             $id = $command->getParams("id");
             return $this->get($id);
         case CommandInterface::COMMAND_COUNT:
             $criteria = $command->getParams("criteria", []);
             return $this->count($criteria);
         case CommandInterface::COMMAND_SAVE:
             /** @var EntityInterface $entity */
             $entity = $command->getParams("entity");
             $isExisting = $entity->isExistingEntity();
             $data = $command->getParams("data");
             return $this->save($data, $isExisting);
         case CommandInterface::COMMAND_DELETE:
             $id = $command->getParams("id");
             return $this->delete($id);
         case CommandInterface::COMMAND_LOAD:
             return $this->load($command->getParams("entity"), $command->getParams("data"));
         case CommandInterface::COMMAND_RESERVE:
             return $this->reserve($command->getParams("entity"));
         case GenerateIdCommandInterface::COMMAND_GENERATE_ID:
             return $this->genId($command->getParams("tableId"));
         default:
             throw new \InvalidArgumentException("Command type \" {$command->getName()} not supported");
     }
 }
Пример #3
0
 public function execute(CommandInterface $command)
 {
     switch ($command->getName()) {
         case AfterCommandInterface::COMMAND_AFTER_FIND:
         case AfterCommandInterface::COMMAND_AFTER_GET:
             $result = $this->set($command);
             $command->addResult($result);
             return $result;
         default:
             throw new NotSupportedCommand($command);
     }
 }
Пример #4
0
 public function execute(CommandInterface $command)
 {
     switch ($command->getName()) {
         case self::COMMAND_AFTER_GENERATE_ID:
             /** @var AfterCommandInterface $command */
             $result = $this->toId($command);
             $command->addResult($result);
             return $result;
         default:
             throw new NotSupportedCommand($command);
     }
 }
 public function execute(CommandInterface $command)
 {
     switch ($command->getName()) {
         case self::COMMAND_BEFORE_SAVE:
             /** @var PreCommandInterface $command */
             $result = $this->translate($command);
             break;
         case self::COMMAND_BEFORE_DELETE:
             $result = ["id" => $this->getId($command)];
             break;
         default:
             throw new NotSupportedCommand($command);
     }
     $command->addParams($result);
     return $result;
 }
Пример #6
0
 public function execute(CommandInterface $command)
 {
     switch ($command->getName()) {
         case RelationLoadCommand::COMMAND_RELATION_LOAD:
             return $this->getLinked($command->getParams("entity"));
             break;
         case RelationParamsCommand::COMMAND_RELATION_PARAMS:
             return $this->getParam($command->getParams("param"), $command->getParams());
         default:
             return parent::execute($command);
     }
 }
Пример #7
0
 /**
  * @param CommandInterface $command
  * @return WorkerInterface[]
  */
 public function getCommandWorkers(CommandInterface $command)
 {
     $class = (string) $command->getClass();
     $action = $command->getName();
     do {
         if (false === $class) {
             $class = "";
         }
         $path = [$action, $class];
         if (ArrayUtils::issetByPath($this->actionMap, $path)) {
             $workers = ArrayUtils::get($this->actionMap, $path);
             $workers = ArrayUtils::sortByKey($workers);
             //may be cache like: $this->actionMap = ArrayUtils::set($this->actionMap, $path, $workers);
             foreach ($workers as $worker) {
                 (yield $this->getWorker($worker["name"]));
             }
         }
         if ("" !== $class) {
             $class = get_parent_class($class);
         }
     } while ("" !== $class);
 }
Пример #8
0
 public function __construct(CommandInterface $command, $code = 0, Exception $previous = null)
 {
     $message = "Not Supported command " . $command->getName() . " (" . get_class($command) . ")";
     parent::__construct($message, $code, $previous);
 }