Simplified

Removed magic methods from Connection(Interface)
Connection is closer to a POPO now
This commit is contained in:
Chris Boden 2012-04-25 21:58:12 -04:00
parent 01ccbcf8c8
commit dd79245ecf
5 changed files with 4 additions and 93 deletions

6
composer.lock generated
View File

@ -1,5 +1,5 @@
{ {
"hash": "2e386d1cab16a0caaed00960707929ce", "hash": "bd52a853cdf4e34ae75e805f32ed97ae",
"packages": [ "packages": [
{ {
"package": "doctrine/common", "package": "doctrine/common",
@ -13,12 +13,12 @@
{ {
"package": "symfony/event-dispatcher", "package": "symfony/event-dispatcher",
"version": "dev-master", "version": "dev-master",
"source-reference": "07e1d0174f3a0ec36bbe04b3850270df7a86271d" "source-reference": "b98d68d3b8513c62d35504570f09e9d3dc33d083"
}, },
{ {
"package": "symfony/validator", "package": "symfony/validator",
"version": "dev-master", "version": "dev-master",
"source-reference": "ce994a5616b20f6ebf37d66a1a89bdd3af6b4ea2" "source-reference": "53ec97264f909d29ae01665e8345f8fb763b94f3"
} }
], ],
"packages-dev": null, "packages-dev": null,

View File

@ -7,8 +7,6 @@ use Ratchet\Resource\Socket\SocketInterface;
* This acts as a container to storm data (in memory) about the connection * This acts as a container to storm data (in memory) about the connection
*/ */
class Connection implements ConnectionInterface { class Connection implements ConnectionInterface {
protected $_data = array();
/** /**
* @var Ratchet\Resource\Socket\SocketInterface * @var Ratchet\Resource\Socket\SocketInterface
*/ */
@ -35,40 +33,4 @@ class Connection implements ConnectionInterface {
public function getSocket() { public function getSocket() {
return $this->_socket; return $this->_socket;
} }
/**
* {@inheritdoc}
*/
public function __set($name, $value) {
$this->_data[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function __get($name) {
if (!$this->__isset($name)) {
throw new \InvalidArgumentException("Attribute '{$name}' not found in Connection {$this->getID()}");
}
if (is_callable($this->_data[$name])) {
return $this->_data[$name]($this);
} else {
return $this->_data[$name];
}
}
/**
* {@inheritdoc}
*/
public function __isset($name) {
return isset($this->_data[$name]);
}
/**
* {@inheritdoc}
*/
public function __unset($name) {
unset($this->_data[$name]);
}
} }

View File

@ -6,30 +6,4 @@ interface ConnectionInterface {
* @return int * @return int
*/ */
function getId(); function getId();
/**
* Set an attribute to the connection
* @param mixed
* @param mixed
*/
function __set($name, $value);
/**
* Get a previously set attribute bound to the connection
* @return mixed
* @throws \InvalidArgumentException
*/
function __get($name);
/**
* @param mixed
* @return bool
*/
function __isset($name);
/**
* @param mixed
*/
function __unset($name);
} }

View File

@ -43,31 +43,6 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, $this->_c->{$key}); $this->assertEquals($val, $this->_c->{$key});
} }
public function testExceptionThrownOnInvalidGet() {
$this->setExpectedException('InvalidArgumentException');
$ret = $this->_c->faked;
}
public static function lambdaProvider() {
return array(
array('hello', 'world')
, array('obj', new \stdClass)
, array('arr', array())
);
}
/**
* @dataProvider lambdaProvider
*/
public function testLambdaReturnValueOnGet($key, $val) {
$fn = function() use ($val) {
return $val;
};
$this->_c->{$key} = $fn;
$this->assertSame($val, $this->_c->{$key});
}
/** /**
* @dataProvider keyAndValProvider * @dataProvider keyAndValProvider
*/ */

View File

@ -2,4 +2,4 @@
error_reporting(E_ALL | E_STRICT); error_reporting(E_ALL | E_STRICT);
require_once dirname(__DIR__) . '/vendor/.composer/autoload.php'; require_once dirname(__DIR__) . '/vendor/autoload.php';