Exemplo n.º 1
0
 /**
  * Handle the Ajax response. Run the appropriate
  * action hooks used by WordPress in order to perform
  * POST ajax request securely.
  * Developers have the option to run ajax for the
  * Front-end, Back-end either users are logged in or not
  * or both.
  *
  * @param string $action Your ajax 'action' name
  * @param string $logged Accepted values are 'no', 'yes', 'both'
  * @param callable|string $callable The function to run when ajax action is called
  * @throws AjaxException
  */
 public function listen($action, $logged = 'no', $callable)
 {
     if (!is_string($action) || strlen($action) == 0) {
         throw new AjaxException("Invalid parameter for the action.");
     }
     // resolve callable
     if (is_callable($callable)) {
         $this->registerWithClosure($action, $logged, $callable);
     } else {
         if (strpos($callable, '@') !== false) {
             $parts = explode('@', $callable);
             $callable = $parts[0];
             $method = $parts[1];
         } else {
             $method = 'run';
             // default
         }
         try {
             $resolvedCallback = $this->app->make($callable);
             $this->registerWithClassInstance($action, $logged, $resolvedCallback, $method);
         } catch (\Exception $e) {
             throw new AjaxException($e->getMessage());
         }
     }
 }
 /**
  * Execute decorators
  *
  * @param $command
  * @param string $decoratorSide
  * @return mixed
  * @throws \InvalidArgumentException
  */
 private function executeDecorators($command, $decoratorSide = '')
 {
     $commandState = $command;
     foreach ($this->{$decoratorSide} as $className) {
         if (!class_exists($className)) {
             throw new InvalidArgumentException("The decorate class [{$className}] does not exists.");
         }
         $instance = $this->app->make($className);
         if (!$instance instanceof CommandHandler) {
             $message = 'The class to decorate must be an implementation of Weloquent\\Bus\\Contracts\\CommandHandler';
             throw new InvalidArgumentException($message);
         }
         // execute
         $commandState = $instance->handle($commandState);
     }
     return $commandState;
 }