Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.4 KiB

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\Traits;
  3. use Symfony\Bundle\FrameworkBundle\Console\Application;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Console\Input\ArrayInput;
  6. use Symfony\Component\Console\Output\BufferedOutput;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\KernelInterface;
  10. trait ActionsTrait
  11. {
  12. public function executeConditionActions($userId, $action = null, $condition='true')
  13. {
  14. if($action==null){
  15. return;
  16. }
  17. $application = new Application($this->kernel);
  18. $application->setAutoExit(false);
  19. error_reporting ( E_ALL & ~E_DEPRECATED & ~E_STRICT);
  20. $input = new ArrayInput([
  21. 'command' => 'zitec:action:execute',
  22. // (optional) define the value of command arguments
  23. 'action' => $action,
  24. 'condition' => $condition,
  25. 'userid' => $userId,
  26. ]);
  27. file_put_contents ( 'action.log' , 'zitec:action:execute '. $action.' '.$condition.' '.$userId , FILE_APPEND );
  28. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  29. // You can use NullOutput() if you don't need the output
  30. $output = new BufferedOutput();
  31. $application->run($input, $output);
  32. // return the output, don't use if you used NullOutput()
  33. $content = $output->fetch();
  34. if($this->getParameter('kernel.environment')=='prod'){
  35. if(json_decode($content, true)['route'] ||json_decode($content, true)['error'])
  36. return $content;
  37. }
  38. $content=explode("\n",$content);
  39. $lastelement=null;
  40. foreach($content as $contenido){
  41. if (!is_array($contenido)){
  42. if(json_decode($contenido, true)['route'] ||json_decode($contenido, true)['error'])
  43. $lastelement= $contenido;
  44. }else{
  45. if(json_decode(end($contenido), true)['route'] ||json_decode(end($contenido), true)['error'])
  46. $lastelement= end($contenido);
  47. }
  48. }
  49. // if(!empty($content))
  50. // die(print_r($content,true));
  51. return $lastelement;//$content;//[count($content)-2];
  52. }
  53. }