TYPO3  7.6
IdentificationHeader.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 {
25  private $_ids = array();
26 
33  public function __construct($name, Swift_Mime_Grammar $grammar)
34  {
35  $this->setFieldName($name);
36  parent::__construct($grammar);
37  }
38 
47  public function getFieldType()
48  {
49  return self::TYPE_ID;
50  }
51 
61  public function setFieldBodyModel($model)
62  {
63  $this->setId($model);
64  }
65 
73  public function getFieldBodyModel()
74  {
75  return $this->getIds();
76  }
77 
85  public function setId($id)
86  {
87  $this->setIds(is_array($id) ? $id : array($id));
88  }
89 
97  public function getId()
98  {
99  if (count($this->_ids) > 0) {
100  return $this->_ids[0];
101  }
102  }
103 
111  public function setIds(array $ids)
112  {
113  $actualIds = array();
114 
115  foreach ($ids as $id) {
116  $this->_assertValidId($id);
117  $actualIds[] = $id;
118  }
119 
120  $this->clearCachedValueIf($this->_ids != $actualIds);
121  $this->_ids = $actualIds;
122  }
123 
129  public function getIds()
130  {
131  return $this->_ids;
132  }
133 
146  public function getFieldBody()
147  {
148  if (!$this->getCachedValue()) {
149  $angleAddrs = array();
150 
151  foreach ($this->_ids as $id) {
152  $angleAddrs[] = '<'.$id.'>';
153  }
154 
155  $this->setCachedValue(implode(' ', $angleAddrs));
156  }
157 
158  return $this->getCachedValue();
159  }
160 
168  private function _assertValidId($id)
169  {
170  if (!preg_match(
171  '/^'.$this->getGrammar()->getDefinition('id-left').'@'.
172  $this->getGrammar()->getDefinition('id-right').'$/D',
173  $id
174  )) {
176  'Invalid ID given <'.$id.'>'
177  );
178  }
179  }
180 }