SallyCMS/console

用于管理SallyCMS项目的命令行工具

安装次数: 92

依赖者: 1

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 1

开放问题: 0

类型: sallycms-app

v0.10.1 2016-06-09 11:23 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:01:45 UTC


README

此包提供了一个用于管理SallyCMS项目的命令行应用程序。它能够执行清除缓存和执行由插件提供的命令等任务,使其成为SallyCMS的一个强大扩展。技术上,它基于Symfony Console组件。

要求

  • SallyCMS 0.8+
  • Composer

安装

由于控制台还不是SallyCMS项目的标准分发的一部分,因此您必须手动要求并使用Composer执行安装。将以下行添加到您的 composer.json

:::json
{
    "require": {
        "sallycms/console": "0.9.*@dev"
    }
}

安装完成后(通过 composer install),您可以通过以下方式在shell上访问控制台

:::text
$ sally/console/bin/console ...

当然,如果您喜欢,您可以在项目的任何位置创建指向此文件的符号链接。

使用方法

控制台分为 命令,这些命令本身可以有参数和选项。技术上,控制台的第一个参数决定了命令。命令名称分为命名空间,使用 : 分隔;建议所有命令都使用一个有意义的命名空间前缀,在大多数情况下,这是Sally核心命令的 sly:,而插件的命令使用插件的名称,如 imageresize:

不提供其他参数调用控制台将列出所有可用的命令和全局选项(您可以提供给任何命令的选项,即使命令可能不使用它)

:::text
$ sally/console/bin/console
Sally Console version 0.9.0

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.

Available commands:
  help          Displays help for a command
  list          Lists commands
sly
  sly:install   Perform initial system installation

要了解如何使用命令,请使用 help 命令或使用 --help 选项调用命令本身

:::text
$ sally/console/bin/console sly:install --help
Usage:
 sly:install [--timezone="..."] [--name="..."] [--db-host="..."] [--db-driver="..."] [--db-prefix="..."] [--no-db-init] [--create-db] [--no-user] db-name db-user db-pass [password] [username]

Arguments:
 db-name               The name of the database to use
 db-user               The database username
 db-pass               The database password
 password              The password for the new admin account
 username              The username for the new admin account

Options:
 --timezone            The project timezone (default: "UTC")
 --name                The project name (default: "SallyCMS-Projekt")
 --db-host             The database host (default: "localhost")
 --db-driver           The database driver to use (default: "mysql")
 --db-prefix           The database table prefix (default: "sly_")
 --no-db-init          To perform no changes to the database.
 --create-db           To create the database if it does not yet exist.
 --no-user             To not create/update the admin account.

命令

命令由需要扩展 sly\Console\Command\Base 的PHP类实现,这只为Sally命令添加了一些语法糖,但继承自 Symfony\Component\Console\Command\Command。在这方面,Sally命令与Symfony命令相同,所以任何有关如何配置它们的文档也适用于此处,唯一的区别是命令不是从命令类名称中推断出来的,而是从Sally配置中推断出来的(见下文)。

这里的主要区别在于命令类的构造函数,它不仅接收传递的命令名称(作为第一个参数),而且还接收Sally依赖注入容器。如果您继承Sally的基命令,一切都会得到妥善处理,您可以通过 getContainer() 简单地访问容器

:::php
<?php

class MyCommand extends sly\Console\Command\Base {
   protected function configure() {
      $this
         ->setName('prefix:command')
         ->setDescription('This is my first command.')
         ->setDefinition(array(
            new InputArgument('argx', InputArgument::REQUIRED, 'My only required argument.')
         ));
   }

   protected function execute(InputInterface $input, OutputInterface $output) {
      $container = $this->getContainer();
      // ...
   }
}

配置

要使新的命令可用,它需要在Sally配置中注册。这可以通过插件或 develop/config/ 中的任何配置文件完成。必须将命令添加到 console/commands,每个命令都有一个唯一的键(这不是命令名称,而是一个标识符)

:::yaml
console:
   commands:
      my_command: 'Fully\Qualified\Class\Name'
      my_other_command: 'AddOn\Command\Other'