[WAMP] Static Factory
I'm sorry... refs #11 Optionally, statically register namespaces for Command Factory
This commit is contained in:
parent
45c44fb841
commit
d91a88219b
@ -4,6 +4,7 @@ use Ratchet\Component\WebSocket\WebSocketComponentInterface;
|
||||
use Ratchet\Resource\ConnectionInterface;
|
||||
use Ratchet\Resource\Command\Composite;
|
||||
use Ratchet\Resource\Command\CommandInterface;
|
||||
use Ratchet\Resource\Command\Factory as CmdFactory;
|
||||
use Ratchet\Component\WAMP\Command\Action\Prefix;
|
||||
use Ratchet\Component\WAMP\Command\Action\Welcome;
|
||||
|
||||
@ -168,6 +169,8 @@ class WAMPServerComponent implements WebSocketComponentInterface {
|
||||
* @param WAMPServerComponentInterface An class to propagate calls through
|
||||
*/
|
||||
public function __construct(WAMPServerComponentInterface $server_component) {
|
||||
CmdFactory::registerActionPath(__NAMESPACE__ . '\\Command\\Action');
|
||||
|
||||
$this->_decorating = $server_component;
|
||||
$this->_msg_buffer = new Composite;
|
||||
}
|
||||
|
@ -10,8 +10,16 @@ class Factory {
|
||||
|
||||
protected $_mapped_commands = array();
|
||||
|
||||
public function __construct() {
|
||||
protected static $globalPaths = array();
|
||||
|
||||
protected $_ignoreGlobals = false;
|
||||
|
||||
/**
|
||||
* @param bool If set to TRUE this will ignore all the statically registered namespaces
|
||||
*/
|
||||
public function __construct($ignoreGlobals = false) {
|
||||
$this->addActionPath(__NAMESPACE__ . '\\Action');
|
||||
$this->_ignoreGlobals = (boolean)$ignoreGlobals;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,6 +30,10 @@ class Factory {
|
||||
$this->_paths[] = $this->slashIt($namespace);
|
||||
}
|
||||
|
||||
public static function registerActionPath($namespace) {
|
||||
static::$globalPaths[$namespace] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Composite
|
||||
*/
|
||||
@ -47,6 +59,16 @@ class Factory {
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $this->_ignoreGlobals) {
|
||||
foreach (static::$globalPaths as $path => $one) {
|
||||
$path = $this->slashIt($path);
|
||||
if (class_exists($path . $name)) {
|
||||
$this->_mapped_commands[$name] = $path . $name;
|
||||
return $this->newCommand($name, $conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new \UnexepctedValueException("Command {$name} not found");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user