From 59f0cff7c427d03aee9ee28e55ac5b3278d207e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Mon, 17 Nov 2014 23:30:24 +0100 Subject: [PATCH] renamed proto -> protocol --- PhpAmqpLib/Channel/AbstractChannel.php | 16 ++++---- PhpAmqpLib/Wire/AMQPAbstractCollection.php | 44 +++++++++++----------- tests/Unit/Wire/AMQPCollectionTest.php | 32 ++++++++-------- tests/Unit/Wire/AMQPWriterTest.php | 6 +-- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/PhpAmqpLib/Channel/AbstractChannel.php b/PhpAmqpLib/Channel/AbstractChannel.php index 5bb6780e1..8d6644784 100644 --- a/PhpAmqpLib/Channel/AbstractChannel.php +++ b/PhpAmqpLib/Channel/AbstractChannel.php @@ -17,8 +17,8 @@ class AbstractChannel { - const PROTO_080 = '0.8'; - const PROTO_091 = '0.9.1'; + const PROTOCOL_080 = '0.8'; + const PROTOCOL_091 = '0.9.1'; public static $PROTOCOL_CONSTANTS_CLASS; @@ -85,7 +85,7 @@ public function __construct(AbstractConnection $connection, $channel_id) $this->protocolVersion = self::getProtocolVersion(); switch ($this->protocolVersion) { - case self::PROTO_091: + case self::PROTOCOL_091: self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants091'; $c = self::$PROTOCOL_CONSTANTS_CLASS; $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER; @@ -93,7 +93,7 @@ public function __construct(AbstractConnection $connection, $channel_id) $this->waitHelper = new Wait091(); $this->methodMap = new MethodMap091(); break; - case self::PROTO_080: + case self::PROTOCOL_080: self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib\Wire\Constants080'; $c = self::$PROTOCOL_CONSTANTS_CLASS; $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER; @@ -113,13 +113,13 @@ public function __construct(AbstractConnection $connection, $channel_id) */ public static function getProtocolVersion() { - $proto = defined('AMQP_PROTOCOL') ? AMQP_PROTOCOL : self::PROTO_091; + $protocol = defined('AMQP_PROTOCOL') ? AMQP_PROTOCOL : self::PROTOCOL_091; //adding check here to catch unknown protocol ASAP, as this method may be called from the outside - if (!in_array($proto, array(self::PROTO_080, self::PROTO_091), TRUE)) { - throw new AMQPOutOfRangeException(sprintf('Protocol version %s not implemented.', $proto)); + if (!in_array($protocol, array(self::PROTOCOL_080, self::PROTOCOL_091), TRUE)) { + throw new AMQPOutOfRangeException(sprintf('Protocol version %s not implemented.', $protocol)); } - return $proto; + return $protocol; } /** diff --git a/PhpAmqpLib/Wire/AMQPAbstractCollection.php b/PhpAmqpLib/Wire/AMQPAbstractCollection.php index d4c280cea..7789da5e4 100644 --- a/PhpAmqpLib/Wire/AMQPAbstractCollection.php +++ b/PhpAmqpLib/Wire/AMQPAbstractCollection.php @@ -12,9 +12,9 @@ abstract class AMQPAbstractCollection implements \Iterator { //protocol defines available field types and their corresponding symbols - const PROTO_080 = AbstractChannel::PROTO_080; - const PROTO_091 = AbstractChannel::PROTO_091; - const PROTO_RBT = 'rabbit'; //pseudo proto + const PROTOCOL_080 = AbstractChannel::PROTOCOL_080; + const PROTOCOL_091 = AbstractChannel::PROTOCOL_091; + const PROTOCOL_RBT = 'rabbit'; //pseudo proto //Abstract data types const T_INT_SHORTSHORT = 1; @@ -41,7 +41,7 @@ abstract class AMQPAbstractCollection implements \Iterator /** * @var string */ - private static $_proto = null; + private static $_protocol = null; /* * Field types messy mess http://www.rabbitmq.com/amqp-0-9-1-errata.html#section_3 @@ -220,7 +220,7 @@ protected function encodeValue($val) } elseif (is_array($val)) { //AMQP specs says "Field names MUST start with a letter, '$' or '#'" //so beware, some servers may raise an exception with 503 code in cases when indexed array is encoded as table - if (self::isProto(self::PROTO_080)) { + if (self::isProtocol(self::PROTOCOL_080)) { //080 doesn't support arrays, forcing table $val = array(self::T_TABLE, new AMQPTable($val)); } elseif (empty($val) || (array_keys($val) === range(0, count($val) - 1))) { @@ -285,7 +285,7 @@ protected function encodeInt($val) { if (($val >= -2147483648) && ($val <= 2147483647)) { $ev = array(self::T_INT_LONG, $val); - } elseif (self::isProto(self::PROTO_080)) { + } elseif (self::isProtocol(self::PROTOCOL_080)) { //080 doesn't support longlong $ev = $this->encodeString((string) $val); } else { @@ -312,7 +312,7 @@ protected function encodeBool($val) { $val = (bool) $val; - return self::isProto(self::PROTO_080) ? array(self::T_INT_LONG, (int) $val) : array(self::T_BOOL, $val); + return self::isProtocol(self::PROTOCOL_080) ? array(self::T_INT_LONG, (int) $val) : array(self::T_BOOL, $val); } /** @@ -320,30 +320,30 @@ protected function encodeBool($val) */ protected function encodeVoid() { - return self::isProto(self::PROTO_080) ? $this->encodeString('') : array(self::T_VOID, null); + return self::isProtocol(self::PROTOCOL_080) ? $this->encodeString('') : array(self::T_VOID, null); } /** * @return string */ - final public static function getProto() + final public static function getProtocol() { - if (self::$_proto === null) { - self::$_proto = defined('AMQP_STRICT_FLD_TYPES') && AMQP_STRICT_FLD_TYPES ? + if (self::$_protocol === null) { + self::$_protocol = defined('AMQP_STRICT_FLD_TYPES') && AMQP_STRICT_FLD_TYPES ? AbstractChannel::getProtocolVersion() : - self::PROTO_RBT; + self::PROTOCOL_RBT; } - return self::$_proto; + return self::$_protocol; } /** * @param string $proto * @return bool */ - final public static function isProto($proto) + final public static function isProtocol($proto) { - return self::getProto() == $proto; + return self::getProtocol() == $proto; } /** @@ -351,14 +351,14 @@ final public static function isProto($proto) */ final public static function getSupportedDataTypes() { - switch ($proto = self::getProto()) { - case self::PROTO_080: + switch ($proto = self::getProtocol()) { + case self::PROTOCOL_080: $types = self::$_types_080; break; - case self::PROTO_091: + case self::PROTOCOL_091: $types = self::$_types_091; break; - case self::PROTO_RBT: + case self::PROTOCOL_RBT: $types = self::$_types_rabbit; break; default: @@ -378,7 +378,7 @@ final public static function checkDataTypeIsSupported($type, $return = true) try { $supported = self::getSupportedDataTypes(); if (!isset($supported[$type])) { - throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t support data of type [%s]', self::getProto(), $type)); + throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t support data of type [%s]', self::getProtocol(), $type)); } return true; @@ -399,7 +399,7 @@ final public static function getSymbolForDataType($type) { $types = self::getSupportedDataTypes(); if (!isset($types[$type])) { - throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t support data of type [%s]', self::getProto(), $type)); + throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t support data of type [%s]', self::getProtocol(), $type)); } return $types[$type]; @@ -413,7 +413,7 @@ final public static function getDataTypeForSymbol($symbol) { $symbols = array_flip(self::getSupportedDataTypes()); if (!isset($symbols[$symbol])) { - throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t define data of type [%s]', self::getProto(), $symbol)); + throw new Exception\AMQPOutOfRangeException(sprintf('AMQP-%s doesn\'t define data of type [%s]', self::getProtocol(), $symbol)); } return $symbols[$symbol]; diff --git a/tests/Unit/Wire/AMQPCollectionTest.php b/tests/Unit/Wire/AMQPCollectionTest.php index 95c18cd45..a505102e9 100644 --- a/tests/Unit/Wire/AMQPCollectionTest.php +++ b/tests/Unit/Wire/AMQPCollectionTest.php @@ -9,7 +9,7 @@ class AMQPCollectionTest extends \PHPUnit_Framework_TestCase public function testEncode080() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_080); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_080); $a = new Wire\AMQPArray(array(1, (int) -2147483648, (int) 2147483647, -2147483649, 2147483648, true, false, array('foo' => 'bar'), array('foo'), array())); $this->assertEquals( @@ -38,7 +38,7 @@ public function testEncode080() public function testEncode091() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPArray(array(1, (int) -2147483648, (int) 2147483647, -2147483649, 2147483648, true, false, array('foo' => 'bar'), array('foo'), array())); $is64 = PHP_INT_SIZE == 8; @@ -68,7 +68,7 @@ public function testEncode091() public function testEncodeRabbit() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_RBT); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_RBT); $a = new Wire\AMQPArray(array(1, (int) -2147483648, (int) 2147483647, -2147483649, 2147483648, true, false, array('foo' => 'bar'), array('foo'), array())); $is64 = PHP_INT_SIZE == 8; @@ -107,7 +107,7 @@ public function testEncodeUnknownDatatype() public function testPushUnsupportedDataType080() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_080); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_080); $a = new Wire\AMQPArray(); $this->setExpectedException('PhpAmqpLib\\Exception\\AMQPOutOfRangeException'); @@ -119,7 +119,7 @@ public function testPushUnsupportedDataType080() public function testPushUnsupportedDataType091() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPArray(); $this->setExpectedException('PhpAmqpLib\\Exception\\AMQPOutOfRangeException'); @@ -131,7 +131,7 @@ public function testPushUnsupportedDataType091() public function testPushUnsupportedDataTypeRabbit() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_RBT); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_RBT); $a = new Wire\AMQPArray(); $this->setExpectedException('PhpAmqpLib\\Exception\\AMQPOutOfRangeException'); @@ -164,7 +164,7 @@ public function testPushWithType() public function testConflictingFieldSymbols() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPArray(); $a->push(576, Wire\AMQPArray::T_INT_SHORT); @@ -179,7 +179,7 @@ public function testConflictingFieldSymbols() ); - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_RBT); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_RBT); $a = new Wire\AMQPArray(); $a->push(576, Wire\AMQPArray::T_INT_SHORT); @@ -261,7 +261,7 @@ public function testPushFloatWithDecimalType() public function testArrayRoundTrip080() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_080); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_080); $a = new Wire\AMQPArray($this->getTestDataSrc()); $this->assertEquals(array_values($this->getTestDataCmp080()), $a->getNativeData()); @@ -271,7 +271,7 @@ public function testArrayRoundTrip080() public function testArrayRoundTrip091() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPArray($this->getTestDataSrc()); $this->assertEquals(array_values($this->getTestDataCmp()), $a->getNativeData()); @@ -281,7 +281,7 @@ public function testArrayRoundTrip091() public function testArrayRoundTripRabbit() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_RBT); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_RBT); $a = new Wire\AMQPArray($this->getTestDataSrc()); $this->assertEquals(array_values($this->getTestDataCmp()), $a->getNativeData()); @@ -291,7 +291,7 @@ public function testArrayRoundTripRabbit() public function testTableRoundTrip080() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_080); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_080); $a = new Wire\AMQPTable($this->getTestDataSrc()); $this->assertEquals($this->getTestDataCmp080(), $a->getNativeData()); @@ -301,7 +301,7 @@ public function testTableRoundTrip080() public function testTableRoundTrip091() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPTable($this->getTestDataSrc()); $this->assertEquals($this->getTestDataCmp(), $a->getNativeData()); @@ -311,7 +311,7 @@ public function testTableRoundTrip091() public function testTableRoundTripRabbit() { - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_RBT); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_RBT); $a = new Wire\AMQPTable($this->getTestDataSrc()); $this->assertEquals($this->getTestDataCmp(), $a->getNativeData()); @@ -402,7 +402,7 @@ public function testIterator() 'e' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('t'), false) ); - $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTO_091); + $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPTable($d); foreach ($a as $key => $val) { @@ -417,7 +417,7 @@ public function testIterator() protected function setProtoVersion($proto) { - $r = new \ReflectionProperty('\\PhpAmqpLib\\Wire\\AMQPAbstractCollection', '_proto'); + $r = new \ReflectionProperty('\\PhpAmqpLib\\Wire\\AMQPAbstractCollection', '_protocol'); $r->setAccessible(true); $r->setValue(null, $proto); } diff --git a/tests/Unit/Wire/AMQPWriterTest.php b/tests/Unit/Wire/AMQPWriterTest.php index cf6c8f340..2b7b305e8 100644 --- a/tests/Unit/Wire/AMQPWriterTest.php +++ b/tests/Unit/Wire/AMQPWriterTest.php @@ -18,7 +18,7 @@ class AMQPWriterTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->setProtoVersion(AMQPArray::PROTO_091); + $this->setProtoVersion(AMQPArray::PROTOCOL_091); $this->_writer = new AMQPWriter(); } @@ -26,7 +26,7 @@ public function setUp() public function tearDown() { - $this->setProtoVersion(AMQPArray::PROTO_RBT); + $this->setProtoVersion(AMQPArray::PROTOCOL_RBT); $this->_writer = null; } @@ -34,7 +34,7 @@ public function tearDown() protected function setProtoVersion($proto) { - $r = new \ReflectionProperty('\\PhpAmqpLib\\Wire\\AMQPAbstractCollection', '_proto'); + $r = new \ReflectionProperty('\\PhpAmqpLib\\Wire\\AMQPAbstractCollection', '_protocol'); $r->setAccessible(true); $r->setValue(null, $proto); }