Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge b3e9558 into be3beb4
Browse files Browse the repository at this point in the history
  • Loading branch information
hashworks committed Feb 11, 2015
2 parents be3beb4 + b3e9558 commit a353a88
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* Phergie (http://phergie.org)
*
* @link http://github.com/phergie/phergie-irc-bot-react for the canonical source repository
* @copyright Copyright (c) 2008-2014 Phergie Development Team (http://phergie.org)
* @copyright Copyright (c) 2008-2015 Phergie Development Team (http://phergie.org)
* @license http://phergie.org/license New BSD License
* @package Phergie\Irc\Bot\React
*/

namespace Phergie\Irc\Bot\React;

use Monolog\Logger;
use Phergie\Irc\Bot\React\PluginProcessor\ClientInjector;
use Phergie\Irc\Bot\React\PluginProcessor\EventEmitterInjector;
use Phergie\Irc\Bot\React\PluginProcessor\LoggerInjector;
use Phergie\Irc\Bot\React\PluginProcessor\LoopInjector;
Expand Down Expand Up @@ -383,10 +384,13 @@ function($processor) {
* configuration.
*
* @param \Phergie\Irc\Bot\React\PluginProcessor\PluginProcessorInterface[]
*
* @return PluginProcessorInterface[]
*/
protected function getDefaultPluginProcessors()
{
return array(
new ClientInjector,
new EventEmitterInjector,
new LoggerInjector,
new LoopInjector,
Expand Down
29 changes: 29 additions & 0 deletions src/ClientAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Phergie (http://phergie.org)
*
* @link http://github.com/phergie/phergie-irc-bot-react for the canonical source repository
* @copyright Copyright (c) 2008-2015 Phergie Development Team (http://phergie.org)
* @license http://phergie.org/license New BSD License
* @package Phergie\Irc\Bot\React
*/

namespace Phergie\Irc\Bot\React;

use Phergie\Irc\Client\React\Client;

/**
* Interface for injection of the client.
*
* @category Phergie
* @package Phergie\Irc\Bot\React
*/
interface ClientAwareInterface
{
/**
* Sets the client for the implementing class to use.
*
* @param Client $client
*/
public function setClient(Client $client);
}
39 changes: 39 additions & 0 deletions src/PluginProcessor/ClientInjector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Phergie (http://phergie.org)
*
* @link http://github.com/phergie/phergie-irc-bot-react for the canonical source repository
* @copyright Copyright (c) 2008-2015 Phergie Development Team (http://phergie.org)
* @license http://phergie.org/license New BSD License
* @package Phergie\Irc\Bot\React
*/

namespace Phergie\Irc\Bot\React\PluginProcessor;

use Phergie\Irc\Bot\React\Bot;
use Phergie\Irc\Bot\React\ClientAwareInterface;
use Phergie\Irc\Bot\React\PluginInterface;

/**
* Plugin processor that injects the plugin with the bot's client if
* possible.
*
* @category Phergie
* @package Phergie\Irc\Bot\React
*/
class ClientInjector implements PluginProcessorInterface
{
/**
* Injects the bot's client into the plugin if it implements
* \Phergie\Irc\Bot\React\ClientAwareInterface.
*
* @param \Phergie\Irc\Bot\React\PluginInterface $plugin Loaded plugin
* @param \Phergie\Irc\Bot\React\Bot $bot Bot that loaded the plugin
*/
public function process(PluginInterface $plugin, Bot $bot)
{
if ($plugin instanceof ClientAwareInterface) {
$plugin->setClient($bot->getClient());
}
}
}

0 comments on commit a353a88

Please sign in to comment.