TYPO3  7.6
SimpleHeaderFactory.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
17 {
19  private $_encoder;
20 
22  private $_paramEncoder;
23 
25  private $_grammar;
26 
28  private $_charset;
29 
38  public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, Swift_Mime_Grammar $grammar, $charset = null)
39  {
40  $this->_encoder = $encoder;
41  $this->_paramEncoder = $paramEncoder;
42  $this->_grammar = $grammar;
43  $this->_charset = $charset;
44  }
45 
54  public function createMailboxHeader($name, $addresses = null)
55  {
56  $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder, $this->_grammar);
57  if (isset($addresses)) {
58  $header->setFieldBodyModel($addresses);
59  }
60  $this->_setHeaderCharset($header);
61 
62  return $header;
63  }
64 
73  public function createDateHeader($name, $timestamp = null)
74  {
75  $header = new Swift_Mime_Headers_DateHeader($name, $this->_grammar);
76  if (isset($timestamp)) {
77  $header->setFieldBodyModel($timestamp);
78  }
79  $this->_setHeaderCharset($header);
80 
81  return $header;
82  }
83 
92  public function createTextHeader($name, $value = null)
93  {
94  $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder, $this->_grammar);
95  if (isset($value)) {
96  $header->setFieldBodyModel($value);
97  }
98  $this->_setHeaderCharset($header);
99 
100  return $header;
101  }
102 
112  public function createParameterizedHeader($name, $value = null,
113  $params = array())
114  {
115  $header = new Swift_Mime_Headers_ParameterizedHeader($name,
116  $this->_encoder, (strtolower($name) == 'content-disposition')
117  ? $this->_paramEncoder
118  : null,
119  $this->_grammar
120  );
121  if (isset($value)) {
122  $header->setFieldBodyModel($value);
123  }
124  foreach ($params as $k => $v) {
125  $header->setParameter($k, $v);
126  }
127  $this->_setHeaderCharset($header);
128 
129  return $header;
130  }
131 
140  public function createIdHeader($name, $ids = null)
141  {
142  $header = new Swift_Mime_Headers_IdentificationHeader($name, $this->_grammar);
143  if (isset($ids)) {
144  $header->setFieldBodyModel($ids);
145  }
146  $this->_setHeaderCharset($header);
147 
148  return $header;
149  }
150 
159  public function createPathHeader($name, $path = null)
160  {
161  $header = new Swift_Mime_Headers_PathHeader($name, $this->_grammar);
162  if (isset($path)) {
163  $header->setFieldBodyModel($path);
164  }
165  $this->_setHeaderCharset($header);
166 
167  return $header;
168  }
169 
175  public function charsetChanged($charset)
176  {
177  $this->_charset = $charset;
178  $this->_encoder->charsetChanged($charset);
179  $this->_paramEncoder->charsetChanged($charset);
180  }
181 
185  public function __clone()
186  {
187  $this->_encoder = clone $this->_encoder;
188  $this->_paramEncoder = clone $this->_paramEncoder;
189  }
190 
192  private function _setHeaderCharset(Swift_Mime_Header $header)
193  {
194  if (isset($this->_charset)) {
195  $header->setCharset($this->_charset);
196  }
197  }
198 }