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()); }
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); } }
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 getId(CommandInterface $command) { $entity = $command->getParams("entity"); if (is_object($entity)) { if ($entity instanceof EntityInterface) { return $entity->getId(); } else { throw new \InvalidArgumentException("entity object not instance of EntityInterface"); } } return $entity; }
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"); } }
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); } }
/** * @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); }
public function __construct(CommandInterface $command, $code = 0, Exception $previous = null) { $message = "Not Supported command " . $command->getName() . " (" . get_class($command) . ")"; parent::__construct($message, $code, $previous); }