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.
|
|
<?php namespace Zitec\RuleEngineBundle\Traits;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelInterface;
trait ActionsTrait { public function executeConditionActions($userId, $action = null, $condition='true') { if($action==null){ return; } $application = new Application($this->kernel); $application->setAutoExit(false); error_reporting ( E_ALL & ~E_DEPRECATED & ~E_STRICT); $input = new ArrayInput([ 'command' => 'zitec:action:execute', // (optional) define the value of command arguments
'action' => $action, 'condition' => $condition, 'userid' => $userId,
]); file_put_contents ( 'action.log' , 'zitec:action:execute '. $action.' '.$condition.' '.$userId , FILE_APPEND ); error_reporting(E_ERROR | E_WARNING | E_PARSE); // You can use NullOutput() if you don't need the output
$output = new BufferedOutput(); $application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch(); if($this->getParameter('kernel.environment')=='prod'){ if(json_decode($content, true)['route'] ||json_decode($content, true)['error']) return $content; } $content=explode("\n",$content);
$lastelement=null; foreach($content as $contenido){ if (!is_array($contenido)){ if(json_decode($contenido, true)['route'] ||json_decode($contenido, true)['error']) $lastelement= $contenido; }else{ if(json_decode(end($contenido), true)['route'] ||json_decode(end($contenido), true)['error']) $lastelement= end($contenido); } }// if(!empty($content))
// die(print_r($content,true));
return $lastelement;//$content;//[count($content)-2];
} }
|