Completed
Pull Request — 3.x (#336)
by
unknown
30:18
created

getApiQueueStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NotificationBundle\Service;
13
14
use Guzzle\Http\Client as GuzzleClient;
15
use Sonata\NotificationBundle\Exception\MonitoringException;
16
17
/**
18
 * Class RabbitMQQueueStatusGuzzleProvider.
19
 *
20
 * @deprecated Create for BC. Use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider instead
21
 *
22
 * NEXT_MAJOR: remove this and use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider
23
 */
24
class RabbitMQQueueStatusGuzzleProvider implements RabbitMQQueueStatusProviderInterface
25
{
26
    /**
27
     * Array with RabbitMQ connection settings.
28
     *
29
     * @var array
30
     */
31
    protected $settings;
32
33
    public function __construct(array $settings)
34
    {
35
        $this->settings = $settings;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getApiQueueStatus()
42
    {
43
        if (!class_exists(GuzzleClient::class)) {
44
            throw new MonitoringException(
45
                'The guzzle http client library is required to run rabbitmq health checks. '
46
                .'Make sure to add guzzlehttp/guzzle to your composer.json.'
47
            );
48
        }
49
50
        $client = new GuzzleClient();
51
        $client->setConfig(['curl.options' => [CURLOPT_CONNECTTIMEOUT_MS => 3000]]);
52
        $request = $client->get(sprintf('%s/queues', $this->settings['console_url']));
53
        $request->setAuth($this->settings['user'], $this->settings['pass']);
54
55
        return json_decode($request->send()->getBody(true), true);
56
    }
57
}
58