asika/jconsole

此包已被废弃,不再维护。没有建议的替代包。
此包的最新版本(1.0.9)没有提供许可证信息。

用于Joomla CMS的有用命令行工具

1.0.9 2016-03-11 14:21 UTC

This package is auto-updated.

Last update: 2024-06-02 16:45:08 UTC


README

用于Joomla CMS的有用控制台工具

JConsole 是从 Joomla Console Package 实现的命令行工具。它提供了一个接口来创建嵌套命令。

关于控制台包

请参阅:https://github.com/asika32764/joomla-framework/tree/console/src/Joomla/Console

注意:控制台包尚未添加到Joomla框架中,它是一个实验性包。

通过Composer安装

cd your/joomla/path

php composer.phar create-project asika/jconsole libraries/jconsole 1.0.*

然后,如果你想通过Git跟踪整个Joomla,请删除libraries/jconsole/.gitignore,使用根gitignore代替。

入门指南

打开终端,转到path/of/joomla

输入

php cli/console

将获取帮助信息

Joomla! Console - version: 1.0
------------------------------------------------------------

[console Help]


Usage:
  console <command> [option]


Options:

  -h | --help       Display this help message.
  -q | --quiet      Do not output any message.
  -v | --verbose    Increase the verbosity of messages.
  --no-ansi         Suppress ANSI colors on unsupported terminals.


Available commands:

  help      List all arguments and show usage & manual.

  build     Some useful tools for building system.

  sql       Example description.

  system    System control.

Welcome to Joomla! Console.

可用命令

  help                   List all arguments and show usage & manual.

  build                  Some useful tools for building system.
      check-constants    Check php files which do not included Joomla constants.
      gen-command        Generate a command class.
      index              Create empty index.html files in directories.

  sql                    SQL migration tools.
      backup             Backup sql.
      col                Column operation
      export             Export sql.
      import             Import a sql file.
      profile            Profiles.
      restore            Restore to pervious point.
      table              Model operation.

  system                 System control.
      clean-cache        Clean system cache.
      off                Set this site offline.
      on                 Set this site online.

添加自己的命令

使用插件

console组中创建插件。

<?php

// no direct access
defined('_JEXEC') or die;

class plgConsoleMycommand extends JPlugin
{
	/**
     * onConsoleLoadCommand Event, called when auto added command.
     *
     * @param   string                     $context  The command class, example: 'Command\\Build\\Indexmaker'.
     * @param   JConsole\Command\JCommand  $command  The parent command, You can addArgument to it.
     *
     * @return  void
     */
    public function onConsoleLoadCommand($context, $command)
    {
        if ($context != 'Command\\System\\System')
        {
            return;
        }

        /** @var $command JCommand */
        $command->addArgument(
            'mycommand',             // Command name
            'This is my command.',   // Description
            null,                    // Options

            // Executing code.
            function($command)
            {
                $command->out('Hello World');
            }
        );
    }
}

现在,此自定义命令将添加到系统命令中。

Joomla! Console - version: 1.0
------------------------------------------------------------

[system Help]

System control.

Usage:
  system <command> [option]

Options:
  -h | --help       Display this help message.
  -q | --quiet      Do not output any message.
  -v | --verbose    Increase the verbosity of messages.
  --no-ansi         Suppress ANSI colors on unsupported terminals.

Available commands:
  mycommand      This is my command.    <---- Here is your command
  clean-cache    Clean system cache.
  off            Set this site offline.
  on             Set this site online.

我们执行它。

$ php cli/console system mycommand

结果

$ php console system mycommand
Hello World

使用自定义命令类

我们可以将我们的命令放在插件文件夹中

plugins/system/mycomnand
    |---  Command
    |        |--- MyCommand
    |                |--- MyCommand.php  <--- Here is our command class
    |
    |---  mycommand.php
    |---  mycommand.xml

创建您的命令类。

<?php
namespace Command\Mycommand;

use JConsole\Command\JCommand;

class Mycommand extends JCommand
{
	/**
	 * An enabled flag.
	 *
	 * @var bool
	 */
	public static $isEnabled = true;

	protected $name = 'mycommand';

	protected $description = 'This is mycommand.';

	protected function doExecute()
	{
		$this->out('Hello World.');

		return;
	}
}

在您的插件中注册命令。

public function onConsoleLoadCommand($context, $command)
{
    if ($context != 'Command\\System\\System')
    {
        return;
    }

    // Add autoload to plugin folder
    JLoader::registerNamespace('Command', __DIR__);

    // Namespace 'Command\Mycommand\Mycommand` will auto match `Command/Mycommand/Mycommand.php` path.
    $command->addArgument(new Command\Mycommand\MyCommand);
}

此结果将与前面章节相同。

如何使用命令类

请参阅:https://github.com/asika32764/joomla-framework/tree/console/src/Joomla/Console

有关更多信息,请参阅:https://github.com/asika32764/joomla-framework/tree/console/src/Joomla/Console/Command

待办事项

  1. SQL迁移文档。
  2. 站点安装
  3. 资产工具
  4. ACL修复器

贡献

欢迎任何Pull-request。