XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Mime/HeaderFactory.php';
12 //@require 'Swift/Mime/HeaderEncoder.php';
13 //@require 'Swift/Encoder.php';
14 //@require 'Swift/Mime/Headers/MailboxHeader.php';
15 //@require 'Swift/Mime/Headers/DateHeader.php';
16 //@require 'Swift/Mime/Headers/UnstructuredHeader.php';
17 //@require 'Swift/Mime/Headers/ParameterizedHeader.php';
18 //@require 'Swift/Mime/Headers/IdentificationHeader.php';
19 //@require 'Swift/Mime/Headers/PathHeader.php';
20 
28 {
29 
31  private $_encoder;
32 
34  private $_paramEncoder;
35 
37  private $_charset;
38 
45  public function __construct(Swift_Mime_HeaderEncoder $encoder,
46  Swift_Encoder $paramEncoder, $charset = null)
47  {
48  $this->_encoder = $encoder;
49  $this->_paramEncoder = $paramEncoder;
50  $this->_charset = $charset;
51  }
52 
59  public function createMailboxHeader($name, $addresses = null)
60  {
61  $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder);
62  if (isset($addresses))
63  {
64  $header->setFieldBodyModel($addresses);
65  }
66  $this->_setHeaderCharset($header);
67  return $header;
68  }
69 
76  public function createDateHeader($name, $timestamp = null)
77  {
78  $header = new Swift_Mime_Headers_DateHeader($name);
79  if (isset($timestamp))
80  {
81  $header->setFieldBodyModel($timestamp);
82  }
83  $this->_setHeaderCharset($header);
84  return $header;
85  }
86 
93  public function createTextHeader($name, $value = null)
94  {
95  $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder);
96  if (isset($value))
97  {
98  $header->setFieldBodyModel($value);
99  }
100  $this->_setHeaderCharset($header);
101  return $header;
102  }
103 
111  public function createParameterizedHeader($name, $value = null,
112  $params = array())
113  {
114  $header = new Swift_Mime_Headers_ParameterizedHeader($name,
115  $this->_encoder, (strtolower($name) == 'content-disposition')
116  ? $this->_paramEncoder
117  : null
118  );
119  if (isset($value))
120  {
121  $header->setFieldBodyModel($value);
122  }
123  foreach ($params as $k => $v)
124  {
125  $header->setParameter($k, $v);
126  }
127  $this->_setHeaderCharset($header);
128  return $header;
129  }
130 
137  public function createIdHeader($name, $ids = null)
138  {
139  $header = new Swift_Mime_Headers_IdentificationHeader($name);
140  if (isset($ids))
141  {
142  $header->setFieldBodyModel($ids);
143  }
144  $this->_setHeaderCharset($header);
145  return $header;
146  }
147 
154  public function createPathHeader($name, $path = null)
155  {
156  $header = new Swift_Mime_Headers_PathHeader($name);
157  if (isset($path))
158  {
159  $header->setFieldBodyModel($path);
160  }
161  $this->_setHeaderCharset($header);
162  return $header;
163  }
164 
169  public function charsetChanged($charset)
170  {
171  $this->_charset = $charset;
172  $this->_encoder->charsetChanged($charset);
173  $this->_paramEncoder->charsetChanged($charset);
174  }
175 
176  // -- Private methods
177 
179  private function _setHeaderCharset(Swift_Mime_Header $header)
180  {
181  if (isset($this->_charset))
182  {
183  $header->setCharset($this->_charset);
184  }
185  }
186 
187 }