/**
  * @param \PhpAmqpLib\Connection\AbstractConnection $connection
  * @param                                       $channel_id
  */
 public function __construct(PhpAmqpLib_Connection_AbstractConnection $connection, $channel_id)
 {
     $this->connection = $connection;
     $this->channel_id = $channel_id;
     $connection->channels[$channel_id] = $this;
     $this->frame_queue = array();
     // Lower level queue for frames
     $this->method_queue = array();
     // Higher level queue for methods
     $this->auto_decode = false;
     $this->debug = defined('AMQP_DEBUG') ? AMQP_DEBUG : false;
     $this->protocolVersion = defined('AMQP_PROTOCOL') ? AMQP_PROTOCOL : '0.9.1';
     switch ($this->protocolVersion) {
         case '0.9.1':
             self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib_Wire_Constants091';
             $c = self::$PROTOCOL_CONSTANTS_CLASS;
             $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
             $this->protocolWriter = new PhpAmqpLib_Helper_Protocol_Protocol091();
             $this->waitHelper = new PhpAmqpLib_Helper_Protocol_Wait091();
             $this->methodMap = new PhpAmqpLib_Helper_Protocol_MethodMap091();
             break;
         case '0.8':
             self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib_Wire_Constants080';
             $c = self::$PROTOCOL_CONSTANTS_CLASS;
             $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
             $this->protocolWriter = new PhpAmqpLib_Helper_Protocol_Protocol080();
             $this->waitHelper = new PhpAmqpLib_Helper_Protocol_Wait080();
             $this->methodMap = new PhpAmqpLib_Helper_Protocol_MethodMap080();
             break;
         default:
             throw new PhpAmqpLib_Exception_AMQPRuntimeException('Protocol: ' . $this->protocolVersion . ' not implemented.');
     }
 }
 /**
  * @param PhpAmqpLib_Connection_AbstractConnection $connection
  * @param null $channel_id
  * @param bool $auto_decode
  * @throws Exception
  */
 public function __construct($connection, $channel_id = null, $auto_decode = true)
 {
     if ($channel_id == null) {
         $channel_id = $connection->get_free_channel_id();
     }
     parent::__construct($connection, $channel_id);
     $this->publish_cache = array();
     $this->publish_cache_max_size = 100;
     if ($this->debug) {
         PhpAmqpLib_Helper_MiscHelper::debug_msg('using channel_id: ' . $channel_id);
     }
     $this->default_ticket = 0;
     $this->is_open = false;
     $this->active = true;
     // Flow control
     $this->alerts = array();
     $this->callbacks = array();
     $this->auto_decode = $auto_decode;
     try {
         $this->x_open();
     } catch (Exception $e) {
         $this->close();
         throw $e;
     }
 }
 public function __construct($connection, $channel_id = null, $auto_decode = true)
 {
     if ($channel_id == null) {
         $channel_id = $connection->get_free_channel_id();
     }
     parent::__construct($connection, $channel_id);
     if ($this->debug) {
         PhpAmqpLib_Helper_MiscHelper::debug_msg("using channel_id: " . $channel_id);
     }
     $this->default_ticket = 0;
     $this->is_open = false;
     $this->active = true;
     // Flow control
     $this->alerts = array();
     $this->callbacks = array();
     $this->auto_decode = $auto_decode;
     $this->x_open();
 }
 /**
  * @param PhpAmqpLib_Connection_AbstractConnection $connection
  * @param $channel_id
  * @throws _PhpAmqpLib_Exception_AMQPRuntimeException
  */
 public function __construct($connection, $channel_id)
 {
     $this->connection = $connection;
     $this->channel_id = $channel_id;
     $connection->channels[$channel_id] = $this;
     $this->frame_queue = array();
     // Lower level queue for frames
     $this->method_queue = array();
     // Higher level queue for methods
     $this->auto_decode = false;
     $this->debug = defined('AMQP_DEBUG') ? AMQP_DEBUG : false;
     $this->msg_property_reader = new PhpAmqpLib_Wire_AMQPReader(null);
     $this->wait_content_reader = new PhpAmqpLib_Wire_AMQPReader(null);
     $this->dispatch_reader = new PhpAmqpLib_Wire_AMQPReader(null);
     $this->protocolVersion = self::getProtocolVersion();
     switch ($this->protocolVersion) {
         case self::PROTOCOL_091:
             self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib_Wire_Constants091';
             $c = self::$PROTOCOL_CONSTANTS_CLASS;
             $this->amqp_protocol_header = self::getStaticProperty($c, 'AMQP_PROTOCOL_HEADER');
             $this->protocolWriter = new PhpAmqpLib_Helper_Protocol_Protocol091();
             $this->waitHelper = new PhpAmqpLib_Helper_Protocol_Wait091();
             $this->methodMap = new PhpAmqpLib_Helper_Protocol_MethodMap091();
             break;
         case self::PROTOCOL_080:
             self::$PROTOCOL_CONSTANTS_CLASS = 'PhpAmqpLib_Wire_Constants080';
             $c = self::$PROTOCOL_CONSTANTS_CLASS;
             $this->amqp_protocol_header = self::getStaticProperty($c, 'AMQP_PROTOCOL_HEADER');
             $this->protocolWriter = new PhpAmqpLib_Helper_Protocol_Protocol080();
             $this->waitHelper = new PhpAmqpLib_Helper_Protocol_Wait080();
             $this->methodMap = new PhpAmqpLib_Helper_Protocol_MethodMap080();
             break;
         default:
             //this is logic exception (requires code changes to fix), so OutOfRange, not OutOfBounds or Runtime
             throw new PhpAmqpLib_Exception_AMQPOutOfRangeException(sprintf('Protocol version %s not implemented.', $this->protocolVersion));
     }
 }
 public function __construct($user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = null, $locale = "en_US", PhpAmqpLib_Wire_IO_AbstractIO $io)
 {
     // save the params for the use of __clone
     $this->construct_params = func_get_args();
     if ($user && $password) {
         $login_response = new PhpAmqpLib_Wire_AMQPWriter();
         $login_response->write_table(array("LOGIN" => array('S', $user), "PASSWORD" => array('S', $password)));
         $login_response = substr($login_response->getvalue(), 4);
         //Skip the length
     } else {
         $login_response = null;
     }
     $d = self::$LIBRARY_PROPERTIES;
     while (true) {
         $this->channels = array();
         // The connection object itself is treated as channel 0
         parent::__construct($this, 0);
         $this->channel_max = 65535;
         $this->frame_max = 131072;
         $this->io = $io;
         $this->input = new PhpAmqpLib_Wire_AMQPReader(null, $this->io);
         $this->write($this->amqp_protocol_header);
         $this->wait(array($this->waitHelper->get_wait('connection.start')));
         $this->x_start_ok($d, $login_method, $login_response, $locale);
         $this->wait_tune_ok = true;
         while ($this->wait_tune_ok) {
             $this->wait(array($this->waitHelper->get_wait('connection.secure'), $this->waitHelper->get_wait('connection.tune')));
         }
         $host = $this->x_open($vhost, "", $insist);
         if (!$host) {
             return;
             // we weren't redirected
         }
         // we were redirected, close the socket, loop and try again
         $this->close_socket();
     }
 }
 /**
  * @return string
  */
 public static final function getProtocol()
 {
     if (self::$_protocol === null) {
         self::$_protocol = defined('AMQP_STRICT_FLD_TYPES') && AMQP_STRICT_FLD_TYPES ? PhpAmqpLib_Channel_AbstractChannel::getProtocolVersion() : self::PROTOCOL_RBT;
     }
     return self::$_protocol;
 }
 /**
  * Connects to the AMQP server
  */
 protected function connect()
 {
     try {
         // Loop until we connect
         while (!$this->isConnected()) {
             // Assume we will connect, until we dont
             $this->setIsConnected(true);
             // Connect the socket
             $this->getIO()->connect();
             $this->channels = array();
             // The connection object itself is treated as channel 0
             parent::__construct($this, 0);
             $this->input = new PhpAmqpLib_Wire_AMQPReader(null, $this->getIO());
             $this->write($this->amqp_protocol_header);
             $this->wait(array($this->waitHelper->get_wait('connection.start')));
             $this->x_start_ok(self::$LIBRARY_PROPERTIES, $this->login_method, $this->login_response, $this->locale);
             $this->wait_tune_ok = true;
             while ($this->wait_tune_ok) {
                 $this->wait(array($this->waitHelper->get_wait('connection.secure'), $this->waitHelper->get_wait('connection.tune')));
             }
             $host = $this->x_open($this->vhost, '', $this->insist);
             if (!$host) {
                 return;
                 // we weren't redirected
             }
             $this->setIsConnected(false);
             $this->closeChannels();
             // we were redirected, close the socket, loop and try again
             $this->close_socket();
         }
     } catch (Exception $e) {
         // Something went wrong, set the connection status
         $this->setIsConnected(false);
         $this->closeChannels();
         throw $e;
         // Rethrow exception
     }
 }