imponeer/composer-custom-commands

此包已被弃用,不再维护。未建议替代包。

添加了使用Symfony控制台组件语法定义控制台命令为Composer命令的可能性

安装量: 7,134

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分叉: 0

开放问题: 1

类型:composer-plugin

0.2.1 2020-08-13 12:00 UTC

This package is auto-updated.

Last update: 2020-08-13 12:03:50 UTC


README

License PHP from Packagist

Composer Custom Commands

这是一个Composer插件,允许使用Symfony控制台组件的语法来定义控制台命令。

使用方法

要开始使用此插件,您只需执行以下4个简单步骤

1. 将插件添加到您的Composer项目中

最简单的方法是在控制台执行Composer命令

composer require imponeer/composer-custom-commands

2. 创建一个实现新命令的类

它应该看起来像这样

namespace My\Commands;

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

/**
 * Your new command
 */
class DummyCommand extends Command
{

	/**
	 * Here we can configure command name, options and arguments.
	 * We using here Symfony Command syntax.
	 */
	protected function configure()
	{

	}

	/**
	 * Execute command
	 *
	 * @param InputInterface $input STDInput
	 * @param OutputInterface $output SRDOutput
	 */
	protected function execute(InputInterface $input, OutputInterface $output)
	{

	}

}

3. 在项目的composer.json中创建或编辑配置部分,并添加custom-commands部分,其中包含commands键,并添加要添加到Composer的命令的PHP类名

它应该看起来像这样

{
	"name": "my-project",
	"description": "",
	"type": "project",
	"require": {
		"imponeer/composer-custom-commands": "*"
	},
	"license": "MIT",
	"authors": [
		{
			"name": "SomeBody SomeOne",
			"email": "internet@is.ours.com"
		}
	],
	"autoload": {
		"psr-4": {
			"My\\": "src/"
		}
	},
	"extra": {
		"custom-commands": {
			"commands": [
				"My\\Commands\\DummyCommand"
			]
		}
	}
}

如果您需要执行某些脚本(例如定义某些常量)在每个命令之前,您可以在其中添加boot键,其值是从composer.json位置相对于文件名的路径。

在这种情况下,您的composer.json应类似于以下内容

{
	"name": "my-project",
	"description": "",
	"type": "project",
	"require": {
		"imponeer/composer-custom-commands": "*"
	},
	"license": "MIT",
	"authors": [
		{
			"name": "SomeBody SomeOne",
			"email": "internet@is.ours.com"
		}
	],
	"autoload": {
		"psr-4": {
			"My\\": "src/"
		}
	},
	"extra": {
		"custom-commands": {
			"commands": [
				"My\\Commands\\DummyCommand"
			],
			"boot": "boot.php"
		}
	}
}

4. 如果您一切操作正确,您将能够使用嵌入到您项目中的新Composer命令。

如何贡献?

如果您想添加一些功能或修复错误,您可以分叉、更改并创建pull request。如果您不确定如何操作,请尝试交互式GitHub教程

如果您发现任何错误或有任何问题,请使用问题选项卡并在其中写下您的问题。