magnifico / bitrix-console

此包最新版本(v0.1.7)没有可用的许可信息。

v0.1.7 2017-10-19 11:23 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:43:00 UTC


README

如何安装

  1. 通过 composer 安装包
composer require magnifico/bitrix-console:^0.1
  1. 从 bitrix 目录创建名为 "magnifico.console" 的符号链接到包的位置,例如
cd /home/bitrix/www/bitrix/modules
ln -s ../../../vendor/magnifico/bitrix-console magnifico.console
  1. 在 bitrix 管理员面板中安装模块

  2. 在某个位置创建 "manage.php" 文件

<?php

# Определяем, где находится DOCUMENT_ROOT
$_SERVER['DOCUMENT_ROOT'] = '/home/bitrix/www';

# Включаем служебный скрипт, который сделает все остальное
require_once $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/magnifico.console/manage.php';
  1. 使用

如何使用模块

要向应用程序实例添加自己的命令,需要订阅 "OnBeforeRun" 事件

$eventManager = \Bitrix\Main\EventManager::getInstance();

$eventManager->addEventHandler('magnifico.console', 'OnBeforeRun', function(\Bitrix\Main\Event $event){
    $app = $event->getParameter('app');
    $app->add(new class() extends \Symfony\Component\Console\Command\Command {
        protected function configure()
        {
            $this->setName('foobar');
        }
    });
});

在应用程序启动前,manage.php 脚本将加载系统中所有已安装的模块,以便它们可以按照上述方式订阅该事件。

其他方面的工作与 symfony/console 应用程序相同。