安装 composer 后如何 运行 Symfony 控制台命令?
How do I run a Symfony Console command after composer install?
我的 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
中的自定义控制台命令。我如何将它添加到脚本中 运行 in composer?
您可以看到 Sensio DistributionBundle 的安装后挂钩是如何工作的。
例如,您可以这样调用 Acme 演示包的 Hello World
命令:
ScriptHandler
<?php
namespace Acme\DemoBundle\Composer;
use Composer\Script\CommandEvent;
class ScriptHandler extends \Sensio\Bundle\DistributionBundle\Composer\ScriptHandler {
/**
* 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 文件本身中管理额外的参数。
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",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Acme\DemoBundle\Composer\ScriptHandler::helloWorld"
],
测试
我扩展了ScriptHandler
class版本的sensio-distribution bundle:
sensio/distribution-bundle (v3.0.18)
希望对您有所帮助
我的 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
中的自定义控制台命令。我如何将它添加到脚本中 运行 in composer?
您可以看到 Sensio DistributionBundle 的安装后挂钩是如何工作的。
例如,您可以这样调用 Acme 演示包的 Hello World
命令:
ScriptHandler
<?php
namespace Acme\DemoBundle\Composer;
use Composer\Script\CommandEvent;
class ScriptHandler extends \Sensio\Bundle\DistributionBundle\Composer\ScriptHandler {
/**
* 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 文件本身中管理额外的参数。
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",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Acme\DemoBundle\Composer\ScriptHandler::helloWorld"
],
测试
我扩展了ScriptHandler
class版本的sensio-distribution bundle:
sensio/distribution-bundle (v3.0.18)
希望对您有所帮助