/** * @param int $type One of AMQPAbstractCollection::T_* constants * @param mixed $val */ private function write_value($type, $val) { //This will find appropriate symbol for given data type for currently selected protocol //Also will raise an exception on unknown type $this->write(AMQPAbstractCollection::getSymbolForDataType($type)); switch ($type) { case AMQPAbstractCollection::T_INT_SHORTSHORT: $this->write_signed_octet($val); break; case AMQPAbstractCollection::T_INT_SHORTSHORT_U: $this->write_octet($val); break; case AMQPAbstractCollection::T_INT_SHORT: $this->write_signed_short($val); break; case AMQPAbstractCollection::T_INT_SHORT_U: $this->write_short($val); break; case AMQPAbstractCollection::T_INT_LONG: $this->write_signed_long($val); break; case AMQPAbstractCollection::T_INT_LONG_U: $this->write_long($val); break; case AMQPAbstractCollection::T_INT_LONGLONG: $this->write_signed_longlong($val); break; case AMQPAbstractCollection::T_INT_LONGLONG_U: $this->write_longlong($val); break; case AMQPAbstractCollection::T_DECIMAL: $this->write_octet($val->getE()); $this->write_signed_long($val->getN()); break; case AMQPAbstractCollection::T_TIMESTAMP: $this->write_timestamp($val); break; case AMQPAbstractCollection::T_BOOL: $this->write_octet($val ? 1 : 0); break; case AMQPAbstractCollection::T_STRING_SHORT: $this->write_shortstr($val); break; case AMQPAbstractCollection::T_STRING_LONG: $this->write_longstr($val); break; case AMQPAbstractCollection::T_ARRAY: $this->write_array($val); break; case AMQPAbstractCollection::T_TABLE: $this->write_table($val); break; case AMQPAbstractCollection::T_VOID: break; default: throw new AMQPInvalidArgumentException(sprintf('Unsupported type "%s"', $type)); } }
/** * Reads the array in the next value. * * @param bool $returnObject Whether to return AMQPArray instance instead of plain array * @return array|AMQPArray */ public function read_array($returnObject = false) { $this->bitcount = $this->bits = 0; // Determine array length and its end position $arrayLength = $this->read_php_int(); $endOffset = $this->offset + $arrayLength; $result = $returnObject ? new AMQPArray() : array(); // Read values until we reach the end of the array while ($this->offset < $endOffset) { $fieldType = AMQPAbstractCollection::getDataTypeForSymbol($this->rawread(1)); $fieldValue = $this->read_value($fieldType, $returnObject); $returnObject ? $result->push($fieldValue, $fieldType) : ($result[] = $fieldValue); } return $result; }
/** * @inheritdoc */ public function unbind(string $exchangeName, string $routingKey = '', array $arguments = []) { $args = []; // see: https://github.com/php-amqplib/php-amqplib/issues/405 $supportedDataTypes = AMQPAbstractCollection::getSupportedDataTypes(); foreach ($arguments as $k => $v) { if (is_array($v)) { if (empty($v) || array_keys($v) === range(0, count($v) - 1)) { $args[$k] = [$supportedDataTypes[AMQPAbstractCollection::T_ARRAY], new AMQPArray($v)]; } else { $args[$k] = [$supportedDataTypes[AMQPAbstractCollection::T_TABLE], new AMQPTable($v)]; } } elseif (is_int($v)) { $args[$k] = [$supportedDataTypes[AMQPAbstractCollection::T_INT_LONG], $v]; } elseif (is_bool($v)) { $args[$k] = [$supportedDataTypes[AMQPAbstractCollection::T_BOOL], $v]; } elseif (is_string($v)) { $args[$k] = [$supportedDataTypes[AMQPAbstractCollection::T_STRING_LONG], $v]; } else { throw new Exception\InvalidArgumentException('Unknown argument type ' . gettype($v)); } } $this->channel->getResource()->exchange_unbind($exchangeName, $this->name, $routingKey, $args, null); }
public function testIterator() { $d = array('a' => 1, 'b' => -2147, 'c' => array('foo' => 'bar'), 'd' => true, 'e' => false); $ed = array('a' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('I'), 1), 'b' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('I'), -2147), 'c' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('F'), array('foo' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('S'), 'bar'))), 'd' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('t'), true), 'e' => array(Wire\AMQPAbstractCollection::getDataTypeForSymbol('t'), false)); $this->setProtoVersion(Wire\AMQPAbstractCollection::PROTOCOL_091); $a = new Wire\AMQPTable($d); foreach ($a as $key => $val) { if (!isset($d[$key])) { $this->fail('Unknown key: ' . $key); } $this->assertEquals($ed[$key], $val[1] instanceof Wire\AMQPAbstractCollection ? array($val[0], $this->getEncodedRawData($val[1])) : $val); } }