在 Symfony 控制台内执行"composer install"



我必须在工作目录内启动作曲家安装后的jQuery成功(我正在Silex下开发GIT面板)。有人告诉我,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');
        
    }
}

我尝试了:

    <?php
namespace AppConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleInputInputArgument;
use SymfonyComponentConsoleInputInputOption;
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);
        }
    }
}

仍然不起作用。

好吧,我发现了一些有趣的东西。

namespace AppConsoleCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleInputInputArgument;
use SymfonyComponentConsoleInputInputOption;
use SymfonyComponentProcessProcess;
use SymfonyComponentProcessExceptionProcessFailedException;
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);
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新