dartmoon / prestashop-console
PrestaShop 命令行命令简化
v0.1.0
2021-12-14 22:08 UTC
README
简单的样板代码,用于简化自定义 PrestaShop 命令行的创建。
安装
composer require dartmoon/prestashop-console
用法
创建命令文件
您可以在模块文件夹的任何位置创建命令文件,但为了解释说明,我们假设我们有一个名为 src/Commands
的文件夹。
让我们创建我们的第一个命令,创建文件 src/Commands/HelloWorldCommand.php
<?php namespace Dartmoon\MyModule\Commands; use Dartmoon\Console\AbstractCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class HelloWorldCommand extends AbstractCommand { /** * Name and description */ protected $name = 'mymodule:hello-world'; /** * Command description */ protected $description = 'Simple command that says Hello Wold!'; /** * Execute command */ protected function execute(InputInterface $input, OutputInterface $output) { echo "Hello World!"; } }
在 PrestaShop 中注册命令
要注册命令,我们需要在模块根目录下创建一个名为 config
的文件夹,并在其中创建一个名为 services.yml
的文件。
文件 config/services.yml
services: _defaults: autowire: true autoconfigure: true console.command.hello-world-command: class: Dartmoon\MyModule\Commands\HelloWorldCommand public: true tags: - { name: "console.command" }
重置模块
一旦您在 services.yml
文件中注册了命令,您需要重置您的模块,以便 PrestaShop 可以安装该命令。
执行命令
从 PrestaShop 安装根目录执行
php bin/console mymodule:hello-world
许可协议
本项目采用 MIT 许可协议 - 有关详细信息,请参阅 LICENSE.md 文件。