Skip to content

Commit d829473

Browse files
committed
Merge pull request php-amqplib#170 from fprochazka/patch-4
fixed fatal error and few typos
2 parents 0bb1334 + c9d7018 commit d829473

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

PhpAmqpLib/Channel/AMQPChannel.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ public function __construct($connection, $channel_id = null, $auto_decode = true
106106

107107
public function __destruct()
108108
{
109-
//TODO:???if($this->connection)
110-
// $this->close("destroying channel");
109+
$this->close();
111110
}
112111

113112

@@ -117,9 +116,11 @@ public function __destruct()
117116
*/
118117
protected function do_close()
119118
{
120-
$this->is_open = false;
121-
unset($this->connection->channels[$this->channel_id]);
119+
if ($this->channel_id !== NULL) {
120+
unset($this->connection->channels[$this->channel_id]);
121+
}
122122
$this->channel_id = $this->connection = null;
123+
$this->is_open = false;
123124
}
124125

125126

@@ -151,6 +152,11 @@ protected function channel_alert($args)
151152
*/
152153
public function close($reply_code = 0, $reply_text = "", $method_sig = array(0, 0))
153154
{
155+
if ($this->is_open !== true || !$this->connection || !$this->connection->isConnected()) {
156+
$this->do_close();
157+
return; // already closed
158+
}
159+
154160
list($class_id, $method_id, $args) = $this->protocolWriter->channelClose(
155161
$reply_code,
156162
$reply_text,

PhpAmqpLib/Channel/AbstractChannel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class AbstractChannel
2323
protected $debug;
2424

2525
/**
26-
*
2726
* @var AbstractConnection
2827
*/
2928
protected $connection;

PhpAmqpLib/Connection/AMQPLazyConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function channel($channel_id = null)
3636
*/
3737
protected function getIO()
3838
{
39-
$this->connect();
39+
if (!$this->io) {
40+
$this->connect();
41+
}
4042

4143
return $this->io;
4244
}

PhpAmqpLib/Connection/AbstractConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ public function channel($channel_id = null)
606606
*/
607607
public function close($reply_code = 0, $reply_text = "", $method_sig = array(0, 0))
608608
{
609-
if (!$this->protocolWriter) {
610-
return;
609+
if (!$this->protocolWriter || !$this->isConnected()) {
610+
return NULL;
611611
}
612612

613613
list($class_id, $method_id, $args) = $this->protocolWriter->connectionClose(

PhpAmqpLib/Wire/GenericContent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function has($name)
6464
/**
6565
* Look for additional properties in the 'properties' dictionary,
6666
* and if present - the 'delivery_info' dictionary.
67+
*
68+
* @return mixed|AMQPChannel
6769
*/
6870
public function get($name)
6971
{

0 commit comments

Comments
 (0)