/** * @param string $replyCode * @param int $replyText * @param string $methodSig */ public function __construct($replyCode, $replyText, $methodSig) { parent::__construct($replyText, $replyCode); $this->amqpMethodSig = $methodSig; $ms = Helper::methodSig($methodSig); $mn = isset(AbstractChannel::$globalMethodNames[$ms]) ? AbstractChannel::$globalMethodNames[$ms] : ($mn = ''); $this->args = array($replyCode, $replyText, $methodSig, $mn); }
/** * @todo refactor * * Wait for some expected AMQP methods and dispatch to them. * Unexpected methods are queued up for later calls to this PHP * method. * * @param array $allowedMethods * @param bool $nonBlocking * * @return mixed|null * @throws \Exception */ public function wait($allowedMethods = array(), $nonBlocking = false) { if ($allowedMethods) { if ($this->debug) { Helper::debugMsg(sprintf('waiting for %s', implode(', ', $allowedMethods))); } } else { if ($this->debug) { Helper::debugMsg('waiting for any method'); } } //Process deferred methods foreach ($this->methodQueue as $queueKey => $queuedMethod) { if ($this->debug) { Helper::debugMsg(sprintf('checking queue method %s', $queueKey)); } $methodSig = $queuedMethod[0]; if ($allowedMethods == null || in_array($methodSig, $allowedMethods)) { unset($this->methodQueue[$queueKey]); if ($this->debug) { Helper::debugMsg(sprintf('Executing queued method: $methodSig: %s', self::$globalMethodNames[Helper::methodSig($methodSig)])); } return $this->dispatch($queuedMethod[0], $queuedMethod[1], $queuedMethod[2]); } } // No deferred methods? wait for new ones while (true) { $frame = $this->nextFrame(); $frameType = $frame[0]; $payload = $frame[1]; if ($frameType != 1) { throw new \Exception(sprintf('Expecting AMQP method, received frame type: %s', $frameType)); } if (strlen($payload) < 4) { throw new \Exception('Method frame too short'); } $methodSigArray = unpack('n2', substr($payload, 0, 4)); $methodSig = '' . $methodSigArray[1] . ',' . $methodSigArray[2]; $args = new Reader(substr($payload, 4)); if ($this->debug) { Helper::debugMsg('> ' . $methodSig . ': ' . self::$globalMethodNames[Helper::methodSig($methodSig)]); } if (in_array($methodSig, self::$contentMethods)) { $content = $this->waitContent(); } else { $content = null; } if ($allowedMethods == null || in_array($methodSig, $allowedMethods) || in_array($methodSig, self::$closeMethods)) { return $this->dispatch($methodSig, $args, $content); } // Wasn't what we were looking for? save it for later if ($this->debug) { Helper::debugMsg(sprintf('Queueing for later: %s: %s', $methodSig, self::$globalMethodNames[Helper::methodSig($methodSig)])); } $this->methodQueue[] = array($methodSig, $args, $content); if ($nonBlocking) { break; } } return null; }
/** * @param Wire\Reader $args */ protected function openOk(\AMQP\Wire\Reader $args) { $this->isOpen = true; if ($this->debug) { Helper::debugMsg('Channel open'); } }
protected function closeSocket() { if ($this->debug) { Helper::debugMsg('closing socket'); } if (is_resource($this->sock)) { @fclose($this->sock); } $this->sock = null; }