22
33namespace Zend \Http \Header ;
44
5- class GenericMultiHeader implements MultipleHeaderDescription
5+ class GenericMultiHeader extends GenericHeader implements MultipleHeaderDescription
66{
7- /**
8- * @var string
9- */
10- protected $ fieldName = null ;
11-
12- /**
13- * @var string
14- */
15- protected $ fieldValue = null ;
16-
177 public static function fromString ($ headerLine )
188 {
199 list ($ fieldName , $ fieldValue ) = explode (': ' , $ headerLine , 2 );
@@ -28,105 +18,8 @@ public static function fromString($headerLine)
2818 $ header = new static ($ fieldName , $ fieldValue );
2919 return $ header ;
3020 }
31-
32-
33- }
34-
35- /**
36- * Constructor
37- *
38- * @param null|string $fieldName
39- * @param null|string $fieldValue
40- */
41- public function __construct ($ fieldName = null , $ fieldValue = null )
42- {
43- if ($ fieldName ) {
44- $ this ->setFieldName ($ fieldName );
45- }
46-
47- if ($ fieldValue ) {
48- $ this ->setFieldValue ($ fieldValue );
49- }
50- }
51-
52- /**
53- * Set header name
54- *
55- * @param string $fieldName
56- * @return GenericHeader
57- */
58- public function setFieldName ($ fieldName )
59- {
60- if (!is_string ($ fieldName ) || empty ($ fieldName )) {
61- throw new Exception \InvalidArgumentException ('Header name must be a string ' );
62- }
63-
64- // Pre-filter to normalize valid characters, change underscore to dash
65- $ fieldName = str_replace (' ' , '- ' , ucwords (str_replace (array ('_ ' , '- ' ), ' ' , $ fieldName )));
66-
67- // Validate what we have
68- if (!preg_match ('/^[a-z][a-z0-9-]*$/i ' , $ fieldName )) {
69- throw new Exception \InvalidArgumentException ('Header name must start with a letter, and consist of only letters, numbers, and dashes ' );
70- }
71-
72- $ this ->fieldName = $ fieldName ;
73- return $ this ;
74- }
75-
76- /**
77- * Retrieve header name
78- *
79- * @return string
80- */
81- public function getFieldName ()
82- {
83- return $ this ->fieldName ;
84- }
85-
86- /**
87- * Set header value
88- *
89- * @param string|array $fieldValue
90- * @return GenericHeader
91- */
92- public function setFieldValue ($ fieldValue )
93- {
94- $ fieldValue = (string ) $ fieldValue ;
95-
96- if (empty ($ fieldValue ) || preg_match ('/^\s+$/ ' , $ fieldValue )) {
97- $ fieldValue = '' ;
98- }
99-
100- $ this ->fieldValue = $ fieldValue ;
101- return $ this ;
10221 }
10322
104- /**
105- * Retrieve header value
106- *
107- * @return string
108- */
109- public function getFieldValue ()
110- {
111- return $ this ->fieldValue ;
112- }
113-
114- /**
115- * Cast to string
116- *
117- * Returns in form of "NAME: VALUE\r\n"
118- *
119- * @return string
120- */
121- public function toString ()
122- {
123- $ name = $ this ->getFieldName ();
124- $ value = $ this ->getFieldValue ();
125-
126- return $ name . ': ' . $ value . "\r\n" ;
127- }
128-
129-
13023 public function toStringMultipleHeaders (array $ headers )
13124 {
13225 $ name = $ this ->getFieldName ();
0 commit comments