1 | <?php |
||
25 | abstract class AbstractHeader |
||
26 | { |
||
27 | /** |
||
28 | * @var string the name of the header |
||
29 | */ |
||
30 | protected $name; |
||
31 | |||
32 | /** |
||
33 | * @var \ZBateson\MailMimeParser\Header\Consumer\Part\HeaderPart[] the |
||
34 | * header's parts (as returned from the consumer) |
||
35 | */ |
||
36 | protected $parts; |
||
37 | |||
38 | /** |
||
39 | * @var string the raw value |
||
40 | */ |
||
41 | protected $rawValue; |
||
42 | |||
43 | /** |
||
44 | * Assigns the header's name and raw value, then calls getConsumer and |
||
45 | * parseHeaderValue to extract a parsed value. |
||
46 | * |
||
47 | * @param ConsumerService $consumerService |
||
48 | * @param string $name |
||
49 | * @param string $value |
||
50 | */ |
||
51 | 24 | public function __construct(ConsumerService $consumerService, $name, $value) |
|
59 | |||
60 | /** |
||
61 | * Returns the header's Consumer |
||
62 | * |
||
63 | * @param ConsumerService $consumerService |
||
64 | * @return \ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer |
||
65 | */ |
||
66 | abstract protected function getConsumer(ConsumerService $consumerService); |
||
67 | |||
68 | /** |
||
69 | * Calls the consumer and assigns the parsed parts to member variables. |
||
70 | * |
||
71 | * The default implementation assigns the returned value to $this->part. |
||
72 | * |
||
73 | * @param AbstractConsumer $consumer |
||
74 | */ |
||
75 | 24 | protected function setParseHeaderValue(AbstractConsumer $consumer) |
|
79 | |||
80 | /** |
||
81 | * Returns an array of HeaderPart objects associated with this header. |
||
82 | * |
||
83 | * @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[] |
||
84 | */ |
||
85 | 8 | public function getParts() |
|
89 | |||
90 | /** |
||
91 | * Returns the parsed value of the header -- calls getValue on $this->part |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | 11 | public function getValue() |
|
96 | { |
||
97 | 11 | if (!empty($this->parts)) { |
|
98 | 10 | return $this->parts[0]->getValue(); |
|
99 | } |
||
100 | 1 | return null; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Returns the raw value of the header prior to any processing. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 1 | public function getRawValue() |
|
112 | |||
113 | /** |
||
114 | * Returns the name of the header. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 2 | public function getName() |
|
122 | |||
123 | /** |
||
124 | * Returns the string representation of the header. At the moment this is |
||
125 | * just in the form of: |
||
126 | * |
||
127 | * <HeaderName>: <RawValue> |
||
128 | * |
||
129 | * No additional processing is performed (for instance to wrap long lines.) |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 4 | public function __toString() |
|
137 | } |
||
138 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.