Exemple #1
0
 /**
  * Execute the handler
  *
  * @param CommandInterface         $command    The command
  * @param CommandChainInterface    $chain      The chain executing the command
  * @return mixed|null If a handler breaks, returns the break condition. NULL otherwise.
  */
 public function execute(CommandInterface $command, CommandChainInterface $chain)
 {
     $parts = explode('.', $command->getName());
     $method = '_' . $parts[0] . ucfirst($parts[1]);
     if (method_exists($this, $method)) {
         return $this->{$method}($command);
     }
 }
 /**
  * Applies the specified prefix to all the arguments but the last one.
  *
  * @param CommandInterface $command Command instance.
  * @param string $prefix Prefix string.
  */
 public static function skipLast(CommandInterface $command, $prefix)
 {
     $arguments = $command->getArguments();
     $length = count($arguments);
     for ($i = 0; $i < $length - 1; $i++) {
         $arguments[$i] = "{$prefix}{$arguments[$i]}";
     }
     $command->setRawArguments($arguments);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function open()
 {
     $command = $this->command->toString();
     $this->getOutput()->write("[+] New process with command: " . $command);
     // Command options
     $in = array_values($this->command->getOption('in', array('pipe', 'r')));
     $out = array_values($this->command->getOption('out', array('file', '/tmp/nyx.log', 'a')));
     $err = array_values($this->command->getOption('err', array('file', '/tmp/nyx-error.log', 'a')));
     $this->process = proc_open($command, array(0 => $in, 1 => $out, 2 => $err), $pipes);
 }
Exemple #4
0
 /**
  * @param MessageInterface|CommandInterface $message
  * @return CommandHandlerInterface
  * @throws CommandBusException
  */
 protected function getHandler(CommandInterface $message)
 {
     $messageName = $message->getName();
     $handlerId = $this->resolver->resolve($messageName);
     if (!$this->locator->has($handlerId)) {
         throw new CommandBusException(sprintf("Cannot instantiate handler '%s' for command '%s'", $handlerId, $messageName));
     }
     /** @var CommandHandlerInterface $handler */
     $handler = $this->locator->get($handlerId);
     if (!$handler instanceof CommandHandlerInterface) {
         throw new CommandBusException(sprintf("Handler '%s' returned by locator for command '%s' should implement CommandHandlerInterface", $handlerId, $messageName));
     }
     return $handler;
 }
Exemple #5
0
 /**
  *
  * @return InputStream
  */
 private function getInputStream()
 {
     $config = new CommandConfig();
     $this->commandObject->doConfig($config);
     $commandArguments = [];
     foreach ($config->getArguments() as $argument) {
         $this->parseArgument($argument, $commandArguments);
     }
     return new InputStream($commandArguments);
 }
 /**
  * Registers a command.
  *
  * @param CommandInterface $command
  *
  * @return void
  */
 public function register(CommandInterface $command)
 {
     /*
      * Gets the name of the command
      * @var string
      */
     $name = $command->getCommand();
     /*
      * Check if the command isn't already registered
      * otherwise throw an exception
      */
     if (array_key_exists($name, $this->commands)) {
         throw new CommandException("Command with name '{$name}' already registered");
     }
     /*
      * Adds the command to the array
      */
     $this->commands[$name] = $command;
 }
 /**
  * Command handler
  *
  * Only handles before.action commands to check authorization rules.
  *
  * @param CommandInterface         $command    The command
  * @param CommandChainInterface    $chain      The chain executing the command
  * @throws  ControllerExceptionRequestForbidden      If the user is authentic and the actions is not allowed.
  * @throws  ControllerExceptionRequestNotAuthorized  If the user is not authentic and the action is not allowed.
  * @return  boolean Return TRUE if action is permitted. FALSE otherwise.
  */
 public function execute(CommandInterface $command, CommandChainInterface $chain)
 {
     $parts = explode('.', $command->getName());
     if ($parts[0] == 'before') {
         $action = $parts[1];
         if ($this->canExecute($action) === false) {
             $message = 'Action ' . ucfirst($action) . ' Not Allowed';
             if ($this->getUser()->isAuthentic()) {
                 if (!$this->getUser()->isEnabled()) {
                     $message = 'Account disabled';
                 }
                 throw new ControllerExceptionRequestForbidden($message);
             } else {
                 throw new ControllerExceptionRequestNotAuthorized($message);
             }
             return false;
         }
     }
     return true;
 }
 public function run()
 {
     $result = $this->firstOperand->run();
     foreach ($this->otherOperands as $otherOperand) {
         $operator = $otherOperand['operator'];
         $command = $otherOperand['command'];
         switch ($operator) {
             case self::ADD_OPERATOR:
                 $result = $result + $command->run();
                 break;
             case self::MULTIPLY_OPERATOR:
                 $result = $result * $command->run();
                 break;
             case self::SUBTRACT_OPERATOR:
                 $result = $result - $command->run();
                 break;
             case self::DIVIDE_OPERATOR:
                 $result = $result / $command->run();
                 break;
         }
     }
     return $result;
 }
Exemple #9
0
 /**
  * Command handler
  *
  * @param CommandInterface         $command    The command
  * @param CommandChainInterface    $chain      The chain executing the command
  * @return mixed|null If a handler breaks, returns the break condition. NULL otherwise.
  */
 public function execute(CommandInterface $command, CommandChainInterface $chain)
 {
     $type = '';
     $package = '';
     $subject = '';
     if ($command->getSubject()) {
         $identifier = $command->getSubject()->getIdentifier()->toArray();
         $package = $identifier['package'];
         if ($identifier['path']) {
             $type = array_shift($identifier['path']);
             $subject = $identifier['name'];
         } else {
             $type = $identifier['name'];
         }
     }
     $parts = explode('.', $command->getName());
     $when = array_shift($parts);
     // Before or After
     $name = StringInflector::implode($parts);
     // Action
     // Create Specific and Generic event names
     $event_specific = 'on' . ucfirst($when) . ucfirst($package) . ucfirst($subject) . ucfirst($type) . $name;
     $event_generic = 'on' . ucfirst($when) . ucfirst($type) . $name;
     // Clone the context
     if ($this->isEventImmutable()) {
         $event = clone $command;
     } else {
         $event = $command;
     }
     // Create event object to check for propagation
     $event = $this->getEventPublisher()->publishEvent($event_specific, $event->getAttributes(), $event->getSubject());
     // Ensure event can be propagated and event name is different
     if ($event->canPropagate() && $event_specific != $event_generic) {
         $event->setName($event_generic);
         $this->getEventPublisher()->publishEvent($event);
     }
 }
 /**
  * executes the command
  */
 public function run()
 {
     // here is a key feature of the invoker
     // the invoker is the same whatever is the command
     $this->command->execute();
 }
Exemple #11
0
 public function run()
 {
     $this->command->execute();
 }
 /**
  * @return bool
  */
 public function execute()
 {
     return $this->command->execute();
 }
Exemple #13
0
 /**
  * Create the signature from the command
  *
  * @param CommandInterface $command
  * @param string $authKey
  * @param int $timestamp Unix timestamp
  * @return string
  */
 public static function sign(CommandInterface $command, $authKey, $timestamp = null)
 {
     return static::createSignature($authKey, $command->getRequestUrl(), $command->getRequestData(), $timestamp);
 }