/** * Execute compilation * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $compiler = new ThriftCompiler(); if ($path = $input->getOption('path')) { $compiler->setExecPath($path); } $service = $input->getArgument('service'); $configs = $this->getContainer()->getParameter('thrift.config.services'); // Get config if (isset($configs[$service])) { $config = $configs[$service]; } else { $output->writeln(sprintf('<error>Unknow service %s</error>', $service)); return 1; } // Get definition path $definitionPath = $this->getContainer()->get('thrift.compile_warmer')->getDefinitionPath($config['definition'], $config['definitionPath']); // Get out path if ($bundleName = $input->getOption('bundleNameOut')) { $bundle = $this->getContainer()->get('kernel')->getBundle($bundleName); $bundlePath = $bundle->getPath(); } else { $bundlePath = getcwd(); } //Set Path $compiler->setModelPath(sprintf('%s/%s', $bundlePath, ThriftCompileCacheWarmer::CACHE_SUFFIX)); //Set include dirs if ($includeDirs = $input->getOption('includeDir')) { $compiler->setIncludeDirs($includeDirs); } //Add namespace prefix if needed if ($input->getOption('namespace')) { $compiler->setNamespacePrefix($input->getOption('namespace')); } $return = $compiler->compile($definitionPath, $input->getOption('server')); //Error if (1 === $return) { $output->writeln(sprintf('<error>%s</error>', implode("\n", $compiler->getLastOutput()))); } else { $output->writeln(sprintf('<info>%s</info>', implode("\n", $compiler->getLastOutput()))); } }
public function testCompile() { $compiler = new ThriftCompiler(); $this->assertTrue($compiler->setExecPath('/usr/local/bin', 'Work without /')); $this->assertTrue($compiler->setExecPath('/usr/local/bin/', 'Work with /')); $compiler->setModelPath($this->modelPath); // Add namespace prefix $compiler->setNamespacePrefix($this->namespace); // First compile without server $this->assertTrue($compiler->compile($this->definitionPath), 'Return no error'); // Check if the return is correct $this->assertEquals($compiler->getLastOutput(), array(sprintf('Scanning %s for includes', realpath($this->definitionPath)), sprintf('Parsing %s for types', realpath($this->definitionPath)), sprintf('Program: %s', realpath($this->definitionPath)), sprintf('Generating "php:oop,nsglobal=%s"', $this->namespace))); // Now compile with server $this->assertTrue($compiler->compile($this->definitionPath, true), 'Return no error'); // Check if the return is correct $this->assertEquals($compiler->getLastOutput(), array(sprintf('Scanning %s for includes', realpath($this->definitionPath)), sprintf('Parsing %s for types', realpath($this->definitionPath)), sprintf('Program: %s', realpath($this->definitionPath)), sprintf('Generating "php:oop,nsglobal=%s,server"', $this->namespace))); // Unknow definition $this->setExpectedException('Overblog\\ThriftBundle\\Exception\\ConfigurationException', sprintf('Unable to find Thrift definition at path "%s"', $this->definitionPath . 'UNKNOWN')); $compiler->compile($this->definitionPath . 'UNKNOWN', true); }