XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Mime/Headers/AbstractHeader.php';
12 //@require 'Swift/RfcComplianceException.php';
13 
22 {
23 
30  private $_ids = array();
31 
36  public function __construct($name)
37  {
38  $this->setFieldName($name);
39  $this->initializeGrammar();
40  }
41 
48  public function getFieldType()
49  {
50  return self::TYPE_ID;
51  }
52 
59  public function setFieldBodyModel($model)
60  {
61  $this->setId($model);
62  }
63 
69  public function getFieldBodyModel()
70  {
71  return $this->getIds();
72  }
73 
79  public function setId($id)
80  {
81  return $this->setIds(array($id));
82  }
83 
89  public function getId()
90  {
91  if (count($this->_ids) > 0)
92  {
93  return $this->_ids[0];
94  }
95  }
96 
102  public function setIds(array $ids)
103  {
104  $actualIds = array();
105 
106  foreach ($ids as $k => $id)
107  {
108  if (preg_match(
109  '/^' . $this->getGrammar('id-left') . '@' .
110  $this->getGrammar('id-right') . '$/D',
111  $id
112  ))
113  {
114  $actualIds[] = $id;
115  }
116  else
117  {
119  'Invalid ID given <' . $id . '>'
120  );
121  }
122  }
123 
124  $this->clearCachedValueIf($this->_ids != $actualIds);
125  $this->_ids = $actualIds;
126  }
127 
132  public function getIds()
133  {
134  return $this->_ids;
135  }
136 
145  public function getFieldBody()
146  {
147  if (!$this->getCachedValue())
148  {
149  $angleAddrs = array();
150 
151  foreach ($this->_ids as $id)
152  {
153  $angleAddrs[] = '<' . $id . '>';
154  }
155 
156  $this->setCachedValue(implode(' ', $angleAddrs));
157  }
158  return $this->getCachedValue();
159  }
160 
161 }