Refactored Commands
This commit is contained in:
parent
a6073a87eb
commit
0de53cf7ee
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Ratchet\Command;
|
||||
namespace Ratchet\Command\Action;
|
||||
use Ratchet\Command\CommandInterface;
|
||||
use Ratchet\SocketInterface;
|
||||
|
||||
/**
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Ratchet\Command;
|
||||
namespace Ratchet\Command\Action;
|
||||
use Ratchet\Command\CommandInterface;
|
||||
use Ratchet\SocketInterface;
|
||||
|
||||
/**
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Ratchet\Command;
|
||||
namespace Ratchet\Command\Action;
|
||||
use Ratchet\Command\CommandInterface;
|
||||
use Ratchet\SocketInterface;
|
||||
|
||||
class Runtime implements CommandInterface {
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Ratchet\Command;
|
||||
namespace Ratchet\Command\Action;
|
||||
use Ratchet\Command\CommandInterface;
|
||||
use Ratchet\SocketInterface;
|
||||
|
||||
/**
|
@ -8,7 +8,7 @@ class Composite extends \SplQueue {
|
||||
* @param Ratchet\SocketInterface
|
||||
* @return CommandInterface
|
||||
*/
|
||||
public function create($name, SocketInterface $socket) {
|
||||
public function NOPEcreate($name, SocketInterface $socket) {
|
||||
$class = __NAMESPACE__ . "\\{$name}\\";
|
||||
if (!class_exists($class)) {
|
||||
throw new \UnexpectedValueException("Command {$name} not found");
|
||||
|
44
lib/Ratchet/Command/Factory.php
Normal file
44
lib/Ratchet/Command/Factory.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Ratchet\Command;
|
||||
use Ratchet\SocketInterface;
|
||||
|
||||
class Factory {
|
||||
protected $_paths = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->addActionPath(__NAMESPACE__ . '\\Action');
|
||||
}
|
||||
|
||||
public function addActionPath($namespace) {
|
||||
$this->_paths[] = $this->slashIt($namespace);
|
||||
}
|
||||
|
||||
public function newComposite() {
|
||||
return new Composite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return CommandInterface
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function newCommand($name, SocketInterface $conn) {
|
||||
$cmd = null;
|
||||
foreach ($this->_paths as $path) {
|
||||
if (class_exists($path . $name)) {
|
||||
$cmd = $path . $name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $cmd) {
|
||||
throw new \UnexepctedValueException("Command {$name} not found");
|
||||
}
|
||||
|
||||
return new $cmd($conn);
|
||||
}
|
||||
|
||||
protected function slashIt($ns) {
|
||||
return (substr($ns, -1) == '\\' ? $ns : $ns . '\\');
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use Ratchet\Protocol\WebSocket\VersionInterface;
|
||||
use Ratchet\SocketInterface;
|
||||
use Ratchet\SocketObserver;
|
||||
use Ratchet\Command\CommandInterface;
|
||||
use Ratchet\Command\SendMessage;
|
||||
use Ratchet\Command\Action\SendMessage;
|
||||
use Ratchet\Command\Composite;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user