From dd79245ecf3cb6a6260fc93922d78f5c16639a89 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 21:58:12 -0400 Subject: [PATCH] Simplified Removed magic methods from Connection(Interface) Connection is closer to a POPO now --- composer.lock | 6 +-- src/Ratchet/Resource/Connection.php | 38 ------------------- src/Ratchet/Resource/ConnectionInterface.php | 26 ------------- .../Ratchet/Tests/Resource/ConnectionTest.php | 25 ------------ tests/bootstrap.php | 2 +- 5 files changed, 4 insertions(+), 93 deletions(-) diff --git a/composer.lock b/composer.lock index 184b061..4018db3 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "2e386d1cab16a0caaed00960707929ce", + "hash": "bd52a853cdf4e34ae75e805f32ed97ae", "packages": [ { "package": "doctrine/common", @@ -13,12 +13,12 @@ { "package": "symfony/event-dispatcher", "version": "dev-master", - "source-reference": "07e1d0174f3a0ec36bbe04b3850270df7a86271d" + "source-reference": "b98d68d3b8513c62d35504570f09e9d3dc33d083" }, { "package": "symfony/validator", "version": "dev-master", - "source-reference": "ce994a5616b20f6ebf37d66a1a89bdd3af6b4ea2" + "source-reference": "53ec97264f909d29ae01665e8345f8fb763b94f3" } ], "packages-dev": null, diff --git a/src/Ratchet/Resource/Connection.php b/src/Ratchet/Resource/Connection.php index e15eaa9..df2c5c4 100644 --- a/src/Ratchet/Resource/Connection.php +++ b/src/Ratchet/Resource/Connection.php @@ -7,8 +7,6 @@ use Ratchet\Resource\Socket\SocketInterface; * This acts as a container to storm data (in memory) about the connection */ class Connection implements ConnectionInterface { - protected $_data = array(); - /** * @var Ratchet\Resource\Socket\SocketInterface */ @@ -35,40 +33,4 @@ class Connection implements ConnectionInterface { public function getSocket() { 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]); - } } \ No newline at end of file diff --git a/src/Ratchet/Resource/ConnectionInterface.php b/src/Ratchet/Resource/ConnectionInterface.php index ed9ad9e..6b0608c 100644 --- a/src/Ratchet/Resource/ConnectionInterface.php +++ b/src/Ratchet/Resource/ConnectionInterface.php @@ -6,30 +6,4 @@ interface ConnectionInterface { * @return int */ 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); } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Resource/ConnectionTest.php b/tests/Ratchet/Tests/Resource/ConnectionTest.php index 375c09c..97c3994 100644 --- a/tests/Ratchet/Tests/Resource/ConnectionTest.php +++ b/tests/Ratchet/Tests/Resource/ConnectionTest.php @@ -43,31 +43,6 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase { $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 */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f814127..9c15fdc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,4 +2,4 @@ error_reporting(E_ALL | E_STRICT); - require_once dirname(__DIR__) . '/vendor/.composer/autoload.php'; \ No newline at end of file + require_once dirname(__DIR__) . '/vendor/autoload.php'; \ No newline at end of file