This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9: Implement an event queue factory to resolve issues with multiple …
…connections
- Loading branch information
Showing
4 changed files
with
131 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Phergie (http://phergie.org) | ||
* @copyright Copyright (c) 2008-2014 Phergie Development Team (http://phergie.org) | ||
* @license http://phergie.org/license Simplified BSD License | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
|
||
namespace Phergie\Irc\Bot\React; | ||
|
||
use Phergie\Irc\ConnectionInterface; | ||
|
||
/** | ||
* Default implementation of a factory to maintain connection-specific event | ||
* queue objects. | ||
* | ||
* @category Phergie | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
class EventQueueFactory implements EventQueueFactoryInterface | ||
{ | ||
/** | ||
* Stores event queues keyed by connection | ||
* | ||
* @var \SplObjectStorage | ||
*/ | ||
protected $queues; | ||
|
||
/** | ||
* Initializes storage for event queues. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->queues = new \SplObjectStorage; | ||
} | ||
|
||
/** | ||
* Returns the event queue for a specified connection. | ||
* | ||
* @param \Phergie\Irc\ConnectionInterface $connection | ||
* @return \Phergie\Irc\Bot\React\EventQueueInterface | ||
*/ | ||
public function getEventQueue(ConnectionInterface $connection) | ||
{ | ||
if (!isset($this->queues[$connection])) { | ||
$this->queues[$connection] = new EventQueue; | ||
} | ||
return $this->queues[$connection]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Phergie (http://phergie.org) | ||
* @copyright Copyright (c) 2008-2014 Phergie Development Team (http://phergie.org) | ||
* @license http://phergie.org/license Simplified BSD License | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
|
||
namespace Phergie\Irc\Bot\React; | ||
|
||
use Phergie\Irc\ConnectionInterface; | ||
|
||
/** | ||
* Interface for a factory to maintain connection-specific event queue objects. | ||
* | ||
* @category Phergie | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
interface EventQueueFactoryInterface | ||
{ | ||
/** | ||
* Returns the event queue for a specified connection. | ||
* | ||
* @param \Phergie\Irc\ConnectionInterface $connection | ||
* @return \Phergie\Irc\Bot\React\EventQueueInterface | ||
*/ | ||
public function getEventQueue(ConnectionInterface $connection); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters