Completed
Pull Request — master (#18)
by Stéphane
66:12 queued 61:24
created

HttpConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the bee4/transport package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author  Stephane HULARD <[email protected]>
9
 * @package Bee4\Transport\Configuration
10
 */
11
12
namespace Bee4\Transport\Configuration;
13
14
/**
15
 * HTTP Configuration implementation
16
 * @package Bee4\Transport\Configuration
17
 */
18
class HttpConfiguration extends Configuration
19
{
20
    /**
21
     * Default configuration values
22
     */
23
    const DEFAULTS = [
24
        'allow_redirects' => [
25
            'max' => null,
26
            'referer' => true,
27
        ],
28
        'accept_encoding' => null,
29
        'user_agent' => null,
30
        'commands' => [
31
            'request' => null,
32
            'post' => null
33
        ]
34
    ];
35
36
    /**
37
     * Build a configuration instance
38
     * @param array $data
39
     */
40
    public function __construct(array $data = [])
41
    {
42
        parent::__construct(array_merge(
43
            self::DEFAULTS,
44
            $data
45
        ));
46
    }
47
48
    /**
49
     * Check if redirects are allowed
50
     * @return boolean
51
     */
52
    public function redirectsAllowed()
53
    {
54
        return $this['allow_redirects']!==false;
55
    }
56
57
    /**
58
     * Define how much redirects must be followed, default null = infinite
59
     * @return Configuration|integer|null
60
     */
61
    public function allowRedirectsMax($max = null)
62
    {
63
        return $this->arrayValue('allow_redirects', 'max', $max);
64
    }
65
66
    /**
67
     * Define if referer must be set during redirection
68
     * @return Configuration|boolean
69
     */
70
    public function allowRedirectsReferer($referer = null)
71
    {
72
        return $this->arrayValue('allow_redirects', 'referer', $referer);
73
    }
74
}
75