Skip to content

Commit

Permalink
renamed proto -> protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Nov 19, 2014
1 parent 2adbded commit 59f0cff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
16 changes: 8 additions & 8 deletions PhpAmqpLib/Channel/AbstractChannel.php
Expand Up @@ -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;

Expand Down Expand Up @@ -85,15 +85,15 @@ 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;
$this->protocolWriter = new Protocol091();
$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;
Expand All @@ -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;
}

/**
Expand Down
44 changes: 22 additions & 22 deletions PhpAmqpLib/Wire/AMQPAbstractCollection.php
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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 {
Expand All @@ -312,53 +312,53 @@ 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);
}

/**
* @return array
*/
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;
}

/**
* @return array [dataTypeConstant => dataTypeSymbol]
*/
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:
Expand All @@ -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;

Expand All @@ -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];
Expand All @@ -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];
Expand Down
32 changes: 16 additions & 16 deletions tests/Unit/Wire/AMQPCollectionTest.php
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Wire/AMQPWriterTest.php
Expand Up @@ -18,23 +18,23 @@ class AMQPWriterTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->setProtoVersion(AMQPArray::PROTO_091);
$this->setProtoVersion(AMQPArray::PROTOCOL_091);
$this->_writer = new AMQPWriter();
}



public function tearDown()
{
$this->setProtoVersion(AMQPArray::PROTO_RBT);
$this->setProtoVersion(AMQPArray::PROTOCOL_RBT);
$this->_writer = null;
}



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);
}
Expand Down

0 comments on commit 59f0cff

Please sign in to comment.