Skip to content

Commit b522877

Browse files
author
devyk
committed
AmqpMessage delay method has been added. Updated namespace. Added possibility to pass dependencies via constructor. Composer json actualization.
1 parent 8ada25c commit b522877

10 files changed

+587
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

components/Amqp.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
* @license https://github.com/webtoucher/yii2-amqp/blob/master/LICENSE.md
66
*/
77

8-
namespace webtoucher\amqp\components;
8+
namespace devyk\amqp\components;
99

1010
use yii\base\Component;
1111
use yii\base\Exception;
12-
use yii\helpers\Inflector;
1312
use yii\helpers\Json;
1413
use PhpAmqpLib\Channel\AMQPChannel;
1514
use PhpAmqpLib\Connection\AMQPConnection;

components/AmqpInterpreter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @license https://github.com/webtoucher/yii2-amqp/blob/master/LICENSE.md
66
*/
77

8-
namespace webtoucher\amqp\components;
8+
namespace devyk\amqp\components;
99

1010
use yii\helpers\Console;
1111

components/AmqpMessage.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace devyk\amqp\components;
4+
5+
use PhpAmqpLib\Message\AMQPMessage as BaseAMQPMessage;
6+
use PhpAmqpLib\Wire\AMQPTable;
7+
8+
class AmqpMessage extends BaseAMQPMessage
9+
{
10+
/**
11+
* @param array $body
12+
* @return $this
13+
*/
14+
public function setBody($body)
15+
{
16+
parent::setBody(json_encode($body));
17+
return $this;
18+
}
19+
20+
/**
21+
* @param $delay
22+
* @return $this
23+
*/
24+
public function setDelay($delay)
25+
{
26+
$this->set(
27+
'application_headers',
28+
new AMQPTable([
29+
'x-delay' => $delay * 1000
30+
])
31+
);
32+
return $this;
33+
}
34+
}

components/AmqpTrait.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
* @license https://github.com/webtoucher/yii2-amqp/blob/master/LICENSE.md
66
*/
77

8-
namespace webtoucher\amqp\components;
8+
namespace devyk\amqp\components;
99

10-
use Yii;
10+
use yii;
1111
use PhpAmqpLib\Channel\AMQPChannel;
1212
use PhpAmqpLib\Connection\AMQPConnection;
13-
use webtoucher\amqp\components\Amqp;
14-
use webtoucher\commands\Controller;
1513

1614

1715
/**
@@ -26,7 +24,7 @@
2624
trait AmqpTrait
2725
{
2826
/**
29-
* @var Amqp
27+
* @var \devyk\amqp\components\Amqp
3028
*/
3129
protected $amqpContainer;
3230

@@ -40,7 +38,7 @@ trait AmqpTrait
4038
/**
4139
* Returns AMQP object.
4240
*
43-
* @return Amqp
41+
* @return \devyk\amqp\components\Amqp
4442
*/
4543
public function getAmqp()
4644
{

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.0",
20+
"yiisoft/yii2": "2.0.*",
2021
"php-amqplib/php-amqplib": "~2.0",
2122
"webtoucher/yii2-commands": "*"
2223
},
2324
"autoload": {
2425
"psr-4": {
25-
"webtoucher\\amqp\\": ""
26+
"devyk\\amqp\\": ""
2627
}
2728
}
2829
}

0 commit comments

Comments
 (0)