Bravo3\Orm\Drivers\Common\WorkerPool::execute PHP Method

execute() public method

Have the appropriate worker execute a command
public execute ( Command $command ) : mixed
$command Command
return mixed
    public function execute(Command $command)
    {
        $worker = $this->getWorker($command->getName());
        $args = $command->getArguments();
        foreach ($worker->getRequiredParameters() as $param) {
            if (!array_key_exists($param, $args)) {
                throw new InvalidArgumentException("Command '" . $command->getName() . "' requires parameter '" . $param . "''");
            }
        }
        return $worker->execute($args);
    }

Usage Example

Example #1
0
 /**
  * Get all refs to an entity
  *
  * @param string $key Entity ref key
  * @return Ref[]
  */
 public function getRefs($key)
 {
     $current = $this->worker_pool->execute(new Command('retrieve_index', ['key' => $key]));
     array_walk($current, function (&$item) {
         $item = Ref::fromString($item);
     });
     return $current;
 }