diff --git a/Library/Command/BuildCommand.php b/Library/Command/BuildCommand.php index 1ec5b832ef..732f7690e7 100644 --- a/Library/Command/BuildCommand.php +++ b/Library/Command/BuildCommand.php @@ -23,8 +23,10 @@ * * @package Zephir\Command */ -class BuildCommand extends ContainerAwareCommand +class BuildCommand extends ContainerAwareCommand implements DevelopmentModeAwareInterface { + use DevelopmentModeAwareTrait; + protected function configure() { $this @@ -39,7 +41,7 @@ protected function configure() ) ->addOption('dev', null, InputOption::VALUE_NONE, 'Build the extension in development mode') ->addOption('no-dev', null, InputOption::VALUE_NONE, 'Build the extension in production mode') - ->setHelp($this->getBuildDevHelp()); + ->setHelp($this->getDevelopmentModeHelp()); } protected function execute(InputInterface $input, OutputInterface $output) @@ -53,21 +55,21 @@ protected function execute(InputInterface $input, OutputInterface $output) $command = $this->getApplication()->find('install'); - $devMode = (bool) $input->getOption('no-dev'); - if ($devMode == false) { - $devMode = $input->getOption('dev') || PHP_DEBUG; - } - $arguments = [ 'command' => 'install', '--backend' => $input->getOption('backend'), - '--dev' => $devMode, + '--dev' => $this->isDevelopmentModeEnabled($input), ]; return $command->run(new ArrayInput($arguments), $output); } - private function getBuildDevHelp() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDevelopmentModeHelp() { return <<addOption('dev', null, InputOption::VALUE_NONE, 'Compile the extension in development mode') ->addOption('no-dev', null, InputOption::VALUE_NONE, 'Compile the extension in production mode') - ->setHelp($this->getCompileDevHelp()); + ->setHelp($this->getDevelopmentModeHelp()); } protected function execute(InputInterface $input, OutputInterface $output) @@ -50,18 +52,20 @@ protected function execute(InputInterface $input, OutputInterface $output) -W([a-z0-9\-]+) Turns a warning off */ - $devMode = (bool) $input->getOption('no-dev'); - if ($devMode == false) { - $devMode = $input->getOption('dev') || PHP_DEBUG; - } - // TODO: Move all the stuff from the compiler - $this->compiler->compile($devMode); + $this->compiler->compile( + $this->isDevelopmentModeEnabled($input) + ); return 0; } - private function getCompileDevHelp() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDevelopmentModeHelp() { return << + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Command; + +use Symfony\Component\Console\Input\InputInterface; + +interface DevelopmentModeAwareInterface +{ + /** + * Returns the development mode for the command. + * + * @return string + */ + public function getDevelopmentModeHelp(); + + /** + * Checks if the development mode is enabled. + * + * @param InputInterface $input + * @return bool + */ + public function isDevelopmentModeEnabled(InputInterface $input); +} diff --git a/Library/Command/DevelopmentModeAwareTrait.php b/Library/Command/DevelopmentModeAwareTrait.php new file mode 100644 index 0000000000..c7b342cde2 --- /dev/null +++ b/Library/Command/DevelopmentModeAwareTrait.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Command; + +use Symfony\Component\Console\Input\InputInterface; + +/** + * Zephir\Command\DevelopmentModeAwareTrait + * + * @package Zephir\Command + */ +trait DevelopmentModeAwareTrait +{ + /** + * {@inheritdoc} + * + * @param InputInterface $input + * @return bool + */ + public function isDevelopmentModeEnabled(InputInterface $input) + { + if ($input->getOption('no-dev') == false) { + return $input->getOption('dev') || PHP_DEBUG; + } + + return false; + } +} diff --git a/Library/Command/InstallCommand.php b/Library/Command/InstallCommand.php index 0024d59d9a..423a6f2cac 100644 --- a/Library/Command/InstallCommand.php +++ b/Library/Command/InstallCommand.php @@ -22,8 +22,10 @@ * * @package Zephir\Command */ -class InstallCommand extends ContainerAwareCommand +class InstallCommand extends ContainerAwareCommand implements DevelopmentModeAwareInterface { + use DevelopmentModeAwareTrait; + protected function configure() { $this @@ -31,23 +33,25 @@ protected function configure() ->setDescription('Installs the extension in the extension directory (may require root password)') ->addOption('dev', null, InputOption::VALUE_NONE, 'Install the extension in development mode') ->addOption('no-dev', null, InputOption::VALUE_NONE, 'Install the extension in production mode') - ->setHelp($this->getInstallDevHelp()); + ->setHelp($this->getDevelopmentModeHelp()); } protected function execute(InputInterface $input, OutputInterface $output) { - $devMode = (bool) $input->getOption('no-dev'); - if ($devMode == false) { - $devMode = $input->getOption('dev') || PHP_DEBUG; - } - // TODO: Move all the stuff from the compiler - $this->compiler->install($devMode); + $this->compiler->install( + $this->isDevelopmentModeEnabled($input) + ); return 0; } - private function getInstallDevHelp() + /** + * {@inheritdoc} + * + * @return string + */ + public function getDevelopmentModeHelp() { return <<environment->isWindows()) { - $this->fileSystem->system('php-config --includes', 'stdout', Zephir::VERSION . '/php-includes'); + $this->fileSystem->system( + 'php-config --includes', + 'stdout', + escapeshellcmd(Zephir::VERSION) . '/php-includes' + ); } return trim($this->fileSystem->read(Zephir::VERSION . '/php-includes')); @@ -656,14 +665,14 @@ public function preCompileHeaders() 'cd ext && gcc -c kernel/' . $file->getBaseName() . ' -I. ' . $phpIncludes . ' -o kernel/' . $file->getBaseName() . '.gch', 'stdout', - Zephir::VERSION . '/compile-header' + escapeshellcmd(Zephir::VERSION) . '/compile-header' ); } elseif (filemtime($path) > filemtime($path . '.gch')) { $this->fileSystem->system( 'cd ext && gcc -c kernel/' . $file->getBaseName() . ' -I. ' . $phpIncludes . ' -o kernel/' . $file->getBaseName() . '.gch', 'stdout', - Zephir::VERSION . '/compile-header' + escapeshellcmd(Zephir::VERSION) . '/compile-header' ); } } @@ -2249,7 +2258,7 @@ protected function getGccVersion() return $this->fileSystem->read(Zephir::VERSION . '/gcc-version'); } - $this->fileSystem->system('gcc -v', 'stderr', Zephir::VERSION . '/gcc-version-temp'); + $this->fileSystem->system('gcc -v', 'stderr', escapeshellcmd(Zephir::VERSION) . '/gcc-version-temp'); $lines = $this->fileSystem->file(Zephir::VERSION . '/gcc-version-temp'); foreach ($lines as $line) {