定制 coala/console-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coala/console-bundle

Composer 安装命令:

composer require coala/console-bundle

包简介

Console extension, e.g. converting foreign events to console output

README 文档

README

Bundle installation

composer.json

{
    require: {
        "coala/console-bundle": "dev-master"
    }
}

AppKernel.php

<?php

$bundles = array(
    new Coala\ConsoleBundle\CoalaConsoleBundle(),
);

ConsoleEventTransformer

Why do I need it?

Sometimes you start long running service commands from the console and want to display status messages from the service in real-time.

To make the service universally usable, it should throw different events on certain actions. These events can be anything, even a unique Log event.

This bundle provides you with a tool to convert "foreign" events to a MessageEvent whose output can be displayed on the console.

All you need is a little bit of configuration and some custom event transformer classes.

How do I use it?

Say, you have a service that throws a custom event AcmeOrderImportEvent with the ID "acme.order.import".

You need to implement an event transformer class that takes this AcmeOrderImportEvent and converts it to a MessageEvent provided by this bundle.

You're free to place this transformer class anywhere you wish, for example directly inside your "Command" folder.

Your transformer class should implement the interface Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEventTransformerInterface.

Example (e.g. your AcmeOrderImportEvent provides a method getOrder()->getId()):

  namespace App\AcmeBundle\Command;

  use Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEventTransformerInterface;
  use Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEvent;

  use App\Event\AcmeOrderImportEvent;

  class AcmeOrderImportEventTransformer implements MessageEventTransformerInterface
  {
      /**
       * @param \App\Event\AcmeOrderImportEvent $updateEvent
       * @return MessageEvent
       */
      public function transform($updateEvent)
      {
          $message = "Importing order: " . $updateEvent->getOrder()->getId();
          return new MessageEvent(MessageEvent::INFO, $message);
      }
  }

Then you need to register this event transformer with the service ID acme.order.import. This is done in your config.yml.

  coala_console:
      events:
          acme.order.import: App\AcmeBundle\Command\AcmeOrderImportEventTransformer

And finally you should change your command to extend from Coala\ConsoleBundle\ConsoleEventTransformer\Command\MessageEventCommand:

  use Coala\ConsoleBundle\Command\MessageEventCommand;

  class AcmeTestCommand extends MessageEventCommand
  {
      /* ... all your normal command code in here ... */
  }

And you're done!

统计信息

  • 总下载量: 969
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-21