/**
  * Takes a fixture config object and returns a list of fixture files
  *
  * @param FixtureConfig $fixtureConfig
  * @return array
  */
 public function getFixtures($fixtureConfig)
 {
     $fixtures = [];
     // Apply fixture config
     if (null !== $fixtureConfig->getFixtures()) {
         $fixtures = $fixtureConfig->getFixtures();
     }
     // Apply bundle config
     if (null !== $fixtureConfig->getBundles()) {
         $fixtures = array_merge($fixtures, $this->resolveBundles($fixtureConfig->getBundles()));
     }
     if (count($fixtures) == 0) {
         $fixtures = $this->resolveBundles(array_keys($this->kernel->getBundles()));
     }
     return $fixtures;
 }
 /**
  *
  * @param array $connection
  * @param array $paths Array of Paths where Search Entities are found
  * @param \AppKernel $kernel
  */
 public function __construct(array $connection, array $paths = array(), \AppKernel $kernel)
 {
     $cacheProvider = 'Doctrine\\Common\\Cache\\ArrayCache';
     //Annotation metadata driver
     $config = new Configuration();
     $md = $config->newDefaultAnnotationDriver($paths);
     $config->setMetadataDriverImpl($md);
     $config->setMetadataCacheImpl(new $cacheProvider());
     $config->setEntitySerializer(new CallbackSerializer('toESDocument', 'fromESDocument'));
     $bundles = $kernel->getBundles();
     $entityNamespaces = array();
     foreach ($bundles as $bundle) {
         $nameSpace = $bundle->getNamespace();
         $name = $bundle->getName();
         $entityNamespaces[$name] = $nameSpace;
     }
     $config->setEntityNamespaces($entityNamespaces);
     $client = new \Elastica\Client(array('connections' => array($connection)));
     $this->searchManager = new SearchManager($config, new \Revinate\SearchBundle\Lib\Search\ElasticSearch\Client($client), new EventManager());
     $this->mappingManager = new MappingManager($this->searchManager, $kernel->getEnvironment());
 }
 public function requestAction()
 {
     $request = $this->get('request');
     if ($request->isXmlHttpRequest() && $request->getMethod() == 'POST') {
         // retrieve command string
         $sf2Command = stripslashes($request->request->get('command'));
         if ($sf2Command == '.') {
             // this trick is used to give the possibility to have "php app/console" equivalent
             $sf2Command = 'list';
         }
         //TODO: not really efficient
         $app = $request->request->get('app') ? $request->request->get('app') : basename($this->get('kernel')->getRootDir());
         if (!in_array($app, $this->container->getParameter('sf2gen_console.apps'))) {
             return new Response('This application is not allowed...', 200);
             // set to 200 to allow console display
         }
         //Try to run a separate shell process
         if ($this->container->getParameter('sf2gen_console.new_process')) {
             //Try to run a separate shell process
             try {
                 $php = $this->getPhpExecutable();
                 $commandLine = $php . ' ' . $app . '/' . 'console ';
                 if (!empty($sf2Command)) {
                     $commandLine .= $sf2Command;
                 }
                 $p = new Process($commandLine, dirname($this->get('kernel')->getRootDir()), null, null, 30, array('suppress_errors' => false, 'bypass_shell' => false));
                 $p->run();
                 $output = $p->getOutput();
                 /*
                 if the process is not successful:
                 - 1) Symfony throws an error and ouput is not empty; continue without Exception.
                 - 2) Process throws an error and ouput is empty => Exception!
                 */
                 if (!$p->isSuccessful() && empty($output)) {
                     throw new \RuntimeException('Unabled to run the process.');
                 }
             } catch (\Exception $e) {
                 // not trying the other method. It is interesting to know where it is not working (single process or not)
                 return new Response(nl2br("The request failed when using a separated shell process. Try to use 'new_process: false' in configuration.\n Error : " . $e->getMessage()));
             }
         } else {
             //Try to execute a console within this process
             //TODO: fix cache:clear issue
             try {
                 //Prepare input
                 $args = preg_split("/ /", trim($sf2Command));
                 array_unshift($args, "fakecommandline");
                 //To simulate the console's arguments
                 $app = $args[1];
                 $input = new ArgvInput($args);
                 //Prepare output
                 ob_start();
                 $output = new StreamOutput(fopen("php://output", 'w'), StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatterHtml(true));
                 //Start a kernel/console and an application
                 $env = $input->getParameterOption(array('--env', '-e'), 'dev');
                 $debug = !$input->hasParameterOption(array('--no-debug', ''));
                 $kernel = new \AppKernel($env, $debug);
                 $kernel->boot();
                 $application = new Application($kernel);
                 foreach ($kernel->getBundles() as $bundle) {
                     $bundle->registerCommands($application);
                 }
                 //integrate all availables commands
                 //Find, initialize and run the real command
                 $run = $application->find($app)->run($input, $output);
                 $output = ob_get_contents();
                 ob_end_clean();
             } catch (\Exception $e) {
                 return new Response(nl2br("The request failed  when using same process.\n Error : " . $e->getMessage()));
             }
         }
         // common response for both methods
         if (empty($output)) {
             $output = 'The command "' . $sf2Command . '" was successful.';
         }
         return new Response($this->convertOuput($output));
     }
     return new Response('This request was not found.', 404);
     // request is not a POST request
 }