Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
83.33% |
15 / 18 |
| QueueConnection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
9.37 | |
83.33% |
15 / 18 |
| create | |
0.00% |
0 / 1 |
7.18 | |
84.62% |
11 / 13 |
|||
| mergeFromFile | |
0.00% |
0 / 1 |
2.03 | |
80.00% |
4 / 5 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\MicroService\QueueConnection; |
| 4 | |
| 5 | use Illuminate\Contracts\Foundation\CachesConfiguration; |
| 6 | |
| 7 | class QueueConnection |
| 8 | { |
| 9 | public static function create(array $configQueue = []) |
| 10 | { |
| 11 | $app = app(); |
| 12 | if (! ($app instanceof CachesConfiguration && $app->configurationIsCached())) { |
| 13 | $config = $app->make('config'); |
| 14 | $queue = $config->get('queue'); |
| 15 | |
| 16 | if (!empty($configQueue)) { |
| 17 | if (!isset($queue['connections'])) { |
| 18 | $queue['connections'] = []; |
| 19 | } |
| 20 | |
| 21 | foreach ($configQueue as $name => $connection) { |
| 22 | if (isset( $queue['connections'][$name])) { |
| 23 | throw new \Exception("Configuration already exist ! ($name)"); |
| 24 | } |
| 25 | |
| 26 | $queue['connections'][$name] = $connection; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | $config->set('queue', $queue); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public static function mergeFromFile(string $file) |
| 35 | { |
| 36 | if (!file_exists($file)) { |
| 37 | throw new \Exception("File config connection : '$file' does not exist"); |
| 38 | } |
| 39 | $connections = require $file; |
| 40 | self::create($connections); |
| 41 | } |
| 42 | } |