Esempio n. 1
0
 /**
  * @param array|null $data
  */
 public function __construct(array $data = null)
 {
     parent::__construct(empty($data) ? null : array_values($data));
 }
 /**
  * Read an AMQP table, and return as a PHP array. keys are strings,
  * values are (type,value) tuples.
  *
  * @param bool $returnObject Whether to return AMQPTable instance instead of plain array
  * @return array|AMQPTable
  */
 public function read_table($returnObject = false)
 {
     $this->bitcount = $this->bits = 0;
     $tlen = $this->read_php_int();
     if ($tlen < 0) {
         throw new AMQPOutOfBoundsException('Table is longer than supported');
     }
     $table_data = new AMQPBufferReader($this->rawread($tlen));
     $result = $returnObject ? new AMQPTable() : array();
     while ($table_data->tell() < $tlen) {
         $name = $table_data->read_shortstr();
         $ftype = AMQPAbstractCollection::getDataTypeForSymbol($ftypeSym = $table_data->rawread(1));
         $val = $table_data->read_value($ftype, $returnObject);
         $returnObject ? $result->set($name, $val, $ftype) : ($result[$name] = array($ftypeSym, $val));
     }
     return $result;
 }
 /**
  * @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->e);
             $this->write_signed_long($val->n);
             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_TABLE:
             $this->write_table($val);
             break;
         case AMQPAbstractCollection::T_VOID:
             break;
         default:
             throw new Exception\AMQPInvalidArgumentException(sprintf('Unsupported type "%s"', $type));
     }
 }