Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $controller = $input->getArgument('controller');
     $action = $input->getArgument('action');
     $params = array();
     foreach ($input->getOption('parameters') as $value) {
         $tokens = explode(':', $value);
         if (1 === count($tokens)) {
             $key = $tokens[0];
             if (0 === strlen($key)) {
                 continue;
             }
             $params[$key] = true;
         }
         if (2 === count($tokens)) {
             $key = $tokens[0];
             $value = $tokens[1];
             if (0 === strlen($key) * strlen($value)) {
                 continue;
             }
             $params[$tokens[0]] = $tokens[1];
         }
     }
     $phaxAction = new PhaxAction($controller, $action, $params);
     $phaxAction->setIsCli(true);
     $phaxReaction = $this->getContainer()->get('phax_core')->action($phaxAction);
     if ($phaxReaction->hasMetaMessage()) {
         $output->writeln($phaxReaction->getMetaMessage());
     } else {
         $output->writeln(json_encode($phaxReaction->jsonSerialize()));
     }
 }
Пример #2
0
 /**
  * Phax main controller.
  * Call this controller using phax.action() in js.
  * (Define your PhaxConfig.www_script as the route of this controller).
  * 
  * @return \Phax\CoreBundle\Model\PhaxResponse
  */
 public function phaxAction()
 {
     $request = $this->get('request');
     $params = $request->request->all();
     $controller = $params['phax_metadata']['controller'];
     $action = $params['phax_metadata']['action'];
     $phaxAction = new PhaxAction($controller, $action, $params);
     $phaxAction->setRequest($request)->setIsCli(false);
     $phaxReaction = $this->get('phax_core')->action($phaxAction);
     return new PhaxResponse($phaxReaction);
 }
Пример #3
0
 /**
  * Call action by passing arguments to method parameters with the same name.
  * Or pass PhaxAction if myAction(PhaxAction $arg) is used.
  * 
  * @param mixed $phaxController instance of a phax controller
  * @param PhaxAction $phaxAction instance of PhaxAction
  * @return PhaxReaction
  * @throws PhaxException if method parameters name does not correspond to $phaxAction arguments
  */
 private function callAction($phaxController, $phaxAction)
 {
     $methodName = $phaxAction->getAction() . 'Action';
     $method = new \ReflectionMethod($phaxController, $methodName);
     $arguments = array();
     foreach ($method->getParameters() as $parameter) {
         $parameterClass = $parameter->getClass();
         if ($parameterClass && $parameterClass->getName() === 'Phax\\CoreBundle\\Model\\PhaxAction') {
             $arguments[] = $phaxAction;
         } elseif (isset($phaxAction->{$parameter->getName()})) {
             $arguments[] = $phaxAction->{$parameter->getName()};
         } else {
             throw new PhaxException('Action ' . $methodName . ' of your Phax controller ' . get_class($phaxController) . ' has a parameter ' . $parameter->getName() . ' which do not correspond to any query parameter.' . ' To pass entire PhaxAction instance, use "myAction(PhaxAction $phaxAction)"' . ' in your method declaration.');
         }
     }
     return call_user_func_array(array($phaxController, $methodName), $arguments);
 }
Пример #4
0
 /**
  * Return all parameters sent in phax action
  * 
  * @param \Phax\CoreBundle\Model\PhaxAction $phaxAction
  * @return \Phax\CoreBundle\Model\PhaxReaction
  */
 public function testAction(PhaxAction $phaxAction)
 {
     $data = $phaxAction->jsonSerialize();
     $data['phaxAction_metadata'] = $data['phax_metadata'];
     return $this->get('phax')->reaction($data);
 }