2016-06-20 5 views
0

Мне нужно запустить внутри рабочего каталога, установленного композитором после успешного jquery (я разрабатываю панель git под Silex). Мне сказали, что с Symfony Console это может быть хорошо сделано, потому что он может содержать некоторые опции. Но я понятия не имею, как это назвать.Выполнение «установки композитора» внутри консоли Symfony

Я создал класс расширяет которым команды, я думаю, что я должен реализовать это под выполнить метод ...

class ComposerCommand extends Command 
{ 
    protected function configure() 
    { 
     $this 
      ->setName('composer:install') 
      ->setDescription('Composer install') 
      ->addArgument() 
      ->addOption() 
     ; 
    } 

    protected function execute(InputInterface $input, OutputInterface $output) 
    { 
     $name = $input->getArgument('name'); 

    } 
} 

Спасибо за вашу помощь ...

Edit: попытался это:

<?php 
namespace App\Console\Command; 

use Symfony\Component\Console\Command\Command; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Output\OutputInterface; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputOption; 

class TestCommand extends Command { 


    protected function configure() { 
     $this->setName("test") 
      ->setDescription("Sample description for our command named test") 
      ->setDefinition(array(
       new InputOption('flag', 'f', InputOption::VALUE_NONE, 'Raise a flag'), 
       new InputArgument('activities', InputArgument::IS_ARRAY, 'Space-separated activities to perform', null), 
      )) 

      ->setHelp(<<<EOT 
The <info>test</info> command does things and stuff 
EOT 
      ); 
    } 

    protected function execute(InputInterface $input, OutputInterface $output) { 
     try { 
      \Phar::mapPhar('composer.phar'); 
      include 'phar://composer.phar/demarrage.php'; 
     } catch (\Exception $e) { 
      throw new \Exception($e); 
     } 

    } 
} 

Еще не работает ...

+0

1. Вам не нужен аргумент «имя» (возможно, некоторые другие аргументы, но в этом контексте вам не нужно имя). 2. Я думаю, вам нужно вызвать команду оболочки из вашей команды. – Alex

+0

Shell exec не принимает аргументы: установка композитора --no-взаимодействие – Amelie

+0

Вы можете это проверить: https://github.com/composer/composer/issues/1906 – mTorres

ответ

0

Хорошо, я нашел что-то интересное.

namespace App\Console\Command; 

use Symfony\Component\Console\Command\Command; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Output\OutputInterface; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Process\Process; 
use Symfony\Component\Process\Exception\ProcessFailedException; 

class ComposerCommand extends Command { 

    /** 
    * Configures the console Application 
    * 
    */ 
    protected function configure() { 
     $this->setName("composer:install") 
      ->setDescription("Composer install inside a symfony console.") 
      ->addOption('path', 'p', InputOption::VALUE_REQUIRED) 
      ->setHelp(<<<EOT 
The <info>composer:install</info> command makes "composer install" 
EOT 
      ); 
    } 

    /** 
    * Executes the console Application 
    * 
    * @param InputInterface $input 
    * @param OutputInterface $output 
    * @throws \Exception 
    */ 
    protected function execute(InputInterface $input, OutputInterface $output) { 
     try { 
      $path = $input->getOption('path'); 

      $process = new Process('php composer.phar install --no-interaction'); 
      $process->setWorkingDirectory($path); 
      $process->run(); 

      // executes after the command finishes 
      if (!$process->isSuccessful()) { 
       throw new ProcessFailedException($process); 
      } 

      $output->writeln($process->getOutput()); 
      $output->writeln($process->getErrorOutput()); 
     } catch (\Exception $e) { 
      throw new \Exception($e); 
     } 

    } 
}