SoapRequestDataHolder::removeHeader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 4
Ratio 44.44 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 4
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace Agavi\Request;
3
4
// +---------------------------------------------------------------------------+
5
// | This file is part of the Agavi package.                                   |
6
// | Copyright (c) 2005-2011 the Agavi Project.                                |
7
// |                                                                           |
8
// | For the full copyright and license information, please view the LICENSE   |
9
// | file that was distributed with this source code. You can also view the    |
10
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
11
// |   vi: set noexpandtab:                                                    |
12
// |   Local Variables:                                                        |
13
// |   indent-tabs-mode: t                                                     |
14
// |   End:                                                                    |
15
// +---------------------------------------------------------------------------+
16
17
/**
18
 * AgaviSoapRequestDataHolder provides methods for retrieving client request
19
 * information parameters and headers of SOAP calls.
20
 *
21
 * @package    agavi
22
 * @subpackage request
23
 *
24
 * @author     David Zülke <[email protected]>
25
 * @copyright  Authors
26
 * @copyright  The Agavi Project
27
 *
28
 * @since      0.11.0
29
 *
30
 * @version    $Id$
31
 */
32
class SoapRequestDataHolder extends WebserviceRequestDataHolder implements HeadersRequestDataHolderInterface
33
{
34
    /**
35
     * @constant   Constant for source name of HTTP headers.
36
     */
37
    const SOURCE_HEADERS = 'headers';
38
    
39
    /**
40
     * @var        array An array of headers sent with the request.
41
     */
42
    protected $headers = array();
43
    
44
    /**
45
     * Constructor
46
     *
47
     * @param      array $data An associative array of request data source names and
48
     *                   data arrays.
49
     *
50
     * @author     David Zülke <[email protected]>
51
     * @since      0.11.0
52
     */
53
    public function __construct(array $data = array())
54
    {
55
        // SOAP headers
56
        $this->registerSource(self::SOURCE_HEADERS, $this->headers);
57
        
58
        // call the parent ctor which handles the actual loading of the data
59
        parent::__construct($data);
60
    }
61
    
62
    /**
63
     * Clear all headers.
64
     *
65
     * @author     Dominik del Bondio <[email protected]>
66
     * @since      0.11.0
67
     */
68
    public function clearHeaders()
69
    {
70
        $this->headers = array();
71
    }
72
73
    /**
74
     * Retrieve all HTTP headers.
75
     *
76
     * @return     array A list of SOAP headers.
77
     *
78
     * @author     David Zülke <[email protected]>
79
     * @since      0.11.0
80
     */
81
    public function &getHeaders()
82
    {
83
        return $this->headers;
84
    }
85
    
86
    /**
87
     * Get a HTTP header.
88
     *
89
     * @param      string $name Case-insensitive name of a header, using either a hyphen
90
     *                    or an underscore as a separator.
91
     * @param      mixed  $defualt A default value.
0 ignored issues
show
Bug introduced by
There is no parameter named $defualt. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
92
     *
93
     * @return     string The header value, or null if header wasn't set.
94
     *
95
     * @author     David Zülke <[email protected]>
96
     * @since      0.11.0
97
     */
98
    public function &getHeader($name, $default = null)
99
    {
100
        if (isset($this->headers[$name])) {
101
            return $this->headers[$name];
102
        }
103
104
        return $default;
105
    }
106
    
107
    /**
108
     * Check if a HTTP header exists.
109
     *
110
     * @param      string $name Case-insensitive name of a header, using either a hyphen
111
     *                    or an underscore as a separator.
112
     *
113
     * @return     bool True if the header was sent with the current request.
114
     *
115
     * @author     David Zülke <[email protected]>
116
     * @since      0.11.0
117
     */
118
    public function hasHeader($name)
119
    {
120
        return isset($this->headers[$name]);
121
    }
122
    
123
    /**
124
     * Checks if there is a value of a header is empty or not set.
125
     *
126
     * @param      string $name The header name.
127
     *
128
     * @return     bool The result.
129
     *
130
     * @author     David Zülke <[email protected]>
131
     * @since      0.11.0
132
     */
133
    public function isHeaderValueEmpty($name)
134
    {
135
        return ($this->getHeader($name) === null);
136
    }
137
    /**
138
     * Set a header.
139
     *
140
     * The header name is normalized before storing it.
141
     *
142
     * @param      string $name A header name.
143
     * @param      mixed  $value A header value.
144
     *
145
     * @author     David Zülke <[email protected]>
146
     * @since      0.11.0
147
     */
148
    public function setHeader($name, $value)
149
    {
150
        $this->headers[$name] = $value;
151
    }
152
153
    /**
154
     * Set an array of headers.
155
     *
156
     * @param      array $headers An associative array of headers and their values.
157
     *
158
     * @author     Dominik del Bondio <[email protected]>
159
     * @since      0.11.0
160
     */
161
    public function setHeaders(array $headers)
162
    {
163
        $this->headers = array_merge($this->headers, $headers);
164
    }
165
166
    /**
167
     * Remove a HTTP header.
168
     *
169
     * @param      string $name Case-insensitive name of a header, using either a hyphen
170
     *                    or an underscore as a separator.
171
     *
172
     * @return     string The value of the removed header, if it had been set.
173
     *
174
     * @author     David Zülke <[email protected]>
175
     * @since      0.11.0
176
     */
177
    public function &removeHeader($name)
178
    {
179
        $retval = null;
180 View Code Duplication
        if (isset($this->headers[$name])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
            $retval =& $this->headers[$name];
182
            unset($this->headers[$name]);
183
        }
184
        return $retval;
185
    }
186
    
187
    /**
188
     * Retrieve an array of header names.
189
     *
190
     * @return     array An indexed array of header names in original PHP format.
191
     *
192
     * @author     David Zülke <[email protected]>
193
     * @since      0.11.0
194
     */
195
    public function getHeaderNames()
196
    {
197
        return array_keys($this->headers);
198
    }
199
    
200
    /**
201
     * Merge in Headers from another request data holder.
202
     *
203
     * @param      RequestDataHolder $other The other request data holder.
204
     *
205
     * @author     David Zülke <[email protected]>
206
     * @since      0.11.0
207
     */
208
    public function mergeHeaders(RequestDataHolder $other)
209
    {
210
        if ($other instanceof HeadersRequestDataHolderInterface) {
211
            $this->setHeaders($other->getHeaders());
212
        }
213
    }
214
}
215