Skip to content

Commit 71b8b15

Browse files
committed
merge
2 parents 846fa43 + 0d87777 commit 71b8b15

File tree

227 files changed

+2170
-516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2170
-516
lines changed

.php_cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
This file is part of Swoft.
5+
6+
@link https://swoft.org
7+
@document https://swoft.org/docs
8+
@contact group@swoft.org
9+
@license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
10+
EOF;
11+
12+
$rules = [
13+
'@PSR2' => true,
14+
'array_syntax' => [
15+
'syntax' => 'short'
16+
],
17+
'list_syntax' => [
18+
'syntax' => 'short'
19+
],
20+
'class_attributes_separation' => true,
21+
'declare_strict_types' => true,
22+
'global_namespace_import' => [
23+
'import_constants' => true,
24+
'import_functions' => true,
25+
],
26+
'header_comment' => [
27+
'comment_type' => 'PHPDoc',
28+
'header' => $header,
29+
'separate' => 'bottom'
30+
],
31+
'no_unused_imports' => true,
32+
'single_quote' => true,
33+
'standardize_not_equals' => true,
34+
'void_return' => true, // add :void for method
35+
];
36+
37+
return PhpCsFixer\Config::create()
38+
->setRiskyAllowed(true)
39+
->setRules($rules)
40+
->setFinder(
41+
PhpCsFixer\Finder::create()
42+
->exclude('test')
43+
->exclude('runtime')
44+
->exclude('vendor')
45+
->in(__DIR__)
46+
)
47+
->setUsingCache(false);

run.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
<?php
2-
/** For Swoole coroutine tests */
1+
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
310

411
use Swoole\ExitException;
512

@@ -16,9 +23,14 @@
1623
* file that was distributed with this source code.
1724
*/
1825
if (version_compare('7.1.0', PHP_VERSION, '>')) {
19-
fwrite(STDERR,
20-
sprintf('This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL,
21-
PHP_VERSION, PHP_BINARY));
26+
fwrite(
27+
STDERR,
28+
sprintf(
29+
'This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL,
30+
PHP_VERSION,
31+
PHP_BINARY
32+
)
33+
);
2234
die(1);
2335
}
2436
if (!ini_get('date.timezone')) {
@@ -36,8 +48,10 @@
3648
}
3749
unset($file);
3850
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
39-
fwrite(STDERR,
40-
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
51+
fwrite(
52+
STDERR,
53+
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
54+
);
4155
die(1);
4256
} else {
4357
if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'tests') {
@@ -61,7 +75,7 @@
6175
require PHPUNIT_COMPOSER_INSTALL;
6276

6377
$status = 0;
64-
go(function () {
78+
go(function (): void {
6579
// Status
6680
global $status;
6781

src/amqp/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "swoft/amqp",
33
"type": "library",
4-
"version": "v2.0.8",
4+
"version": "v2.0.10",
55
"keywords": [
66
"php",
77
"swoole",

src/amqp/src/Amqp.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp;
412

@@ -42,8 +50,12 @@ public static function connection(string $pool = Pool::DEFAULT_POOL): Connection
4250
$connection->setRelease(true);
4351
$conManager->setConnection($connection);
4452
} catch (Throwable $e) {
45-
throw new AMQPException(sprintf('Pool error is %s file=%s line=%d', $e->getMessage(), $e->getFile(),
46-
$e->getLine()));
53+
throw new AMQPException(sprintf(
54+
'Pool error is %s file=%s line=%d',
55+
$e->getMessage(),
56+
$e->getFile(),
57+
$e->getLine()
58+
));
4759
}
4860

4961
// Not instanceof Connection

src/amqp/src/AutoLoader.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp;
412

src/amqp/src/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp;
412

src/amqp/src/Connection/Connection.php

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp\Connection;
412

@@ -47,7 +55,7 @@ class Connection extends AbstractConnection implements ConnectionInterface
4755
* @param Pool $pool
4856
* @param Client $client
4957
*/
50-
public function initialize(Pool $pool, Client $client)
58+
public function initialize(Pool $pool, Client $client): void
5159
{
5260
$this->pool = $pool;
5361
$this->client = $client;
@@ -85,10 +93,14 @@ public function createClient(): void
8593

8694
try {
8795
$this->connection = $this->connect([$auth], $setting['connect'] ?? []);
88-
$this->connection = $this->client->getConnector()->connect();
96+
// $this->connection = $this->client->getConnector()->connect(); TODO connect() method body is emtpy ???
8997
} catch (Exception $e) {
90-
throw new AMQPException(sprintf('RabbitMQ connect error is %s file=%s line=%d', $e->getMessage(),
91-
$e->getFile(), $e->getLine()));
98+
throw new AMQPException(sprintf(
99+
'RabbitMQ connect error is %s file=%s line=%d',
100+
$e->getMessage(),
101+
$e->getFile(),
102+
$e->getLine()
103+
));
92104
}
93105

94106
$this->channel();
@@ -198,12 +210,24 @@ protected function declareExchange(): void
198210
$setting = $this->client->getSetting();
199211

200212
try {
201-
$this->channel->exchange_declare($exchange, $type, $setting['passive'] ?? false,
202-
$setting['durable'] ?? true, $setting['auto_delete'] ?? false, $setting['internal'] ?? false,
203-
$setting['nowait'] ?? false, $setting['arguments'] ?? [], $setting['ticket'] ?? null);
213+
$this->channel->exchange_declare(
214+
$exchange,
215+
$type,
216+
$setting['passive'] ?? false,
217+
$setting['durable'] ?? true,
218+
$setting['auto_delete'] ?? false,
219+
$setting['internal'] ?? false,
220+
$setting['nowait'] ?? false,
221+
$setting['arguments'] ?? [],
222+
$setting['ticket'] ?? null
223+
);
204224
} catch (Exception $e) {
205-
throw new AMQPException(sprintf('RabbitMQ declare exchange error is %s file=%s line=%d', $e->getMessage(),
206-
$e->getFile(), $e->getLine()));
225+
throw new AMQPException(sprintf(
226+
'RabbitMQ declare exchange error is %s file=%s line=%d',
227+
$e->getMessage(),
228+
$e->getFile(),
229+
$e->getLine()
230+
));
207231
}
208232
}
209233

@@ -218,12 +242,23 @@ protected function declareQueue(): void
218242
$setting = $this->client->getSetting();
219243

220244
try {
221-
$this->channel->queue_declare($queue, $setting['passive'] ?? false, $setting['durable'] ?? true,
222-
$setting['exclusive'] ?? false, $setting['auto_delete'] ?? false, $setting['nowait'] ?? false,
223-
$setting['arguments'] ?? [], $setting['ticket'] ?? null);
245+
$this->channel->queue_declare(
246+
$queue,
247+
$setting['passive'] ?? false,
248+
$setting['durable'] ?? true,
249+
$setting['exclusive'] ?? false,
250+
$setting['auto_delete'] ?? false,
251+
$setting['nowait'] ?? false,
252+
$setting['arguments'] ?? [],
253+
$setting['ticket'] ?? null
254+
);
224255
} catch (Exception $e) {
225-
throw new AMQPException(sprintf('RabbitMQ declare queue error is %s file=%s line=%d', $e->getMessage(),
226-
$e->getFile(), $e->getLine()));
256+
throw new AMQPException(sprintf(
257+
'RabbitMQ declare queue error is %s file=%s line=%d',
258+
$e->getMessage(),
259+
$e->getFile(),
260+
$e->getLine()
261+
));
227262
}
228263
}
229264

@@ -240,11 +275,21 @@ protected function bind(): void
240275
$setting = $this->client->getSetting();
241276

242277
try {
243-
$this->channel->queue_bind($queue, $exchange, $route, $setting['nowait'] ?? false,
244-
$setting['arguments'] ?? [], $setting['ticket'] ?? null);
278+
$this->channel->queue_bind(
279+
$queue,
280+
$exchange,
281+
$route,
282+
$setting['nowait'] ?? false,
283+
$setting['arguments'] ?? [],
284+
$setting['ticket'] ?? null
285+
);
245286
} catch (Exception $e) {
246-
throw new AMQPException(sprintf('RabbitMQ bind queue and exchange error is %s file=%s line=%d',
247-
$e->getMessage(), $e->getFile(), $e->getLine()));
287+
throw new AMQPException(sprintf(
288+
'RabbitMQ bind queue and exchange error is %s file=%s line=%d',
289+
$e->getMessage(),
290+
$e->getFile(),
291+
$e->getLine()
292+
));
248293
}
249294
}
250295

@@ -294,17 +339,23 @@ public function listen(Closure $callback = null): void
294339
$consume = $setting['consume'] ?? [];
295340

296341
//consume the message
297-
$this->channel->basic_consume($queue, $consume['consumer_tag'] ?? '', $consume['no_local'] ?? false,
298-
$consume['no_ack'] ?? false, $consume['exclusive'] ?? false, $consume['nowait'] ?? false,
299-
function (AMQPMessage $message) use ($callback, $consume) {
342+
$this->channel->basic_consume(
343+
$queue,
344+
$consume['consumer_tag'] ?? '',
345+
$consume['no_local'] ?? false,
346+
$consume['no_ack'] ?? false,
347+
$consume['exclusive'] ?? false,
348+
$consume['nowait'] ?? false,
349+
function (AMQPMessage $message) use ($callback, $consume): void {
300350
$cancelTag = $consume['cancel_tag'] ?? [];
301351
$cancel = is_array($cancelTag) ? in_array($message->body, $cancelTag) : $message->body == $cancelTag;
302352
$this->channel->basic_ack($message->delivery_info['delivery_tag']);
303353
if ($cancel) {
304354
$this->channel->basic_cancel($message->delivery_info['consumer_tag']);
305355
}
306356
!empty($callback) && $callback($message);
307-
});
357+
}
358+
);
308359

309360
//wait for message
310361
while ($this->channel->is_consuming()) {

src/amqp/src/Connection/ConnectionManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp\Connection;
412

@@ -66,5 +74,4 @@ public function release(bool $final = false): void
6674
$this->unset($finalKey);
6775
}
6876
}
69-
70-
}
77+
}

src/amqp/src/Connection/SSLConnection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp\Connection;
412

@@ -16,4 +24,4 @@ class SSLConnection extends Connection
1624
public function create(): void
1725
{
1826
}
19-
}
27+
}

src/amqp/src/Connection/SocketConnection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
210

311
namespace Swoft\Amqp\Connection;
412

@@ -16,4 +24,4 @@ class SocketConnection extends Connection
1624
public function create(): void
1725
{
1826
}
19-
}
27+
}

0 commit comments

Comments
 (0)