如何在编辑器安装后运行 Symfony 控制台命令



My composer.json包含以下声明:

    "post-install-cmd": [
        "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile"
    ],

我想运行我在 src/MyBundle/Command/MyCommand.php 中的自定义控制台命令。如何将其添加到脚本中以在作曲器中运行?

您可以看到安装后钩子如何适用于 Sensio DistributionBundle。

例如,您可以通过以下方式调用 Acme 演示捆绑包的 Hello World 命令:

脚本处理程序

<?php
namespace AcmeDemoBundleComposer;
use ComposerScriptCommandEvent;
class ScriptHandler extends SensioBundleDistributionBundleComposerScriptHandler {

    /**
     * Call the demo command of the Acme Demo Bundle.
     *
     * @param $event CommandEvent A instance
     */
    public static function helloWorld(CommandEvent $event)
    {
        $options = self::getOptions($event);
        $consoleDir = self::getConsoleDir($event, 'hello world');
        if (null === $consoleDir) {
            return;
        }
//        $extraParam = '';
//        if (!$options['who']) {
//            $extraParam = ' --who';
//        }
        static::executeCommand($event, $consoleDir, 'acme:hello', $options['process-timeout']);
    }
}

您可以在 json 文件本身中管理额外的参数。

作曲家.json

"post-install-cmd": [
    "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
    "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
    "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
    "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
    "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
    "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
    "Acme\DemoBundle\Composer\ScriptHandler::helloWorld"
],

测试

我扩展了版本的感官分发包的ScriptHandler类:

sensio/distribution-bundle (v3.0.18)

希望这个帮助

相关内容

  • 没有找到相关文章