Completed
Pull Request — 3.x (#336)
by
unknown
04:29
created

RabbitMQQueueStatusGuzzleProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
 * @deprecated Create for BC. Use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider instead
19
 *
20
 * NEXT_MAJOR: remove this and use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider
21
 */
22
class RabbitMQQueueStatusGuzzleProvider implements RabbitMQQueueStatusProviderInterface
23
{
24
    /**
25
     * Array with RabbitMQ connection settings.
26
     *
27
     * @var array
28
     */
29
    protected $settings;
30
31
    public function __construct(array $settings)
32
    {
33
        $this->settings = $settings;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getApiQueueStatus()
40
    {
41
        if (!class_exists(GuzzleClient::class)) {
42
            throw new MonitoringException(
43
                'The guzzle http client library is required to run rabbitmq health checks. '
44
                .'Make sure to add guzzlehttp/guzzle to your composer.json.'
45
            );
46
        }
47
48
        $client = new GuzzleClient();
49
        $client->setConfig(['curl.options' => [CURLOPT_CONNECTTIMEOUT_MS => 3000]]);
50
        $request = $client->get(sprintf('%s/queues', $this->settings['console_url']));
51
        $request->setAuth($this->settings['user'], $this->settings['pass']);
52
53
        return json_decode($request->send()->getBody(true), true);
54
    }
55
}
56