Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
 
14
/**
15
 * An ID MIME Header for something like Message-ID or Content-ID.
16
 * @package Swift
17
 * @subpackage Mime
18
 * @author Chris Corbyn
19
 */
20
class Swift_Mime_Headers_IdentificationHeader
21
  extends Swift_Mime_Headers_AbstractHeader
22
{
23
 
24
  /**
25
   * The IDs used in the value of this Header.
26
   * This may hold multiple IDs or just a single ID.
27
   * @var string[]
28
   * @access private
29
   */
30
  private $_ids = array();
31
 
32
  /**
33
   * Creates a new IdentificationHeader with the given $name and $id.
34
   * @param string $name
35
   */
36
  public function __construct($name)
37
  {
38
    $this->setFieldName($name);
39
    $this->initializeGrammar();
40
  }
41
 
42
  /**
43
   * Get the type of Header that this instance represents.
44
   * @return int
45
   * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
46
   * @see TYPE_DATE, TYPE_ID, TYPE_PATH
47
   */
48
  public function getFieldType()
49
  {
50
    return self::TYPE_ID;
51
  }
52
 
53
  /**
54
   * Set the model for the field body.
55
   * This method takes a string ID, or an array of IDs
56
   * @param mixed $model
57
   * @throws Swift_RfcComplianceException
58
   */
59
  public function setFieldBodyModel($model)
60
  {
61
    $this->setId($model);
62
  }
63
 
64
  /**
65
   * Get the model for the field body.
66
   * This method returns an array of IDs
67
   * @return array
68
   */
69
  public function getFieldBodyModel()
70
  {
71
    return $this->getIds();
72
  }
73
 
74
  /**
75
   * Set the ID used in the value of this header.
76
   * @param string $id
77
   * @throws Swift_RfcComplianceException
78
   */
79
  public function setId($id)
80
  {
81
    return $this->setIds(array($id));
82
  }
83
 
84
  /**
85
   * Get the ID used in the value of this Header.
86
   * If multiple IDs are set only the first is returned.
87
   * @return string
88
   */
89
  public function getId()
90
  {
91
    if (count($this->_ids) > 0)
92
    {
93
      return $this->_ids[0];
94
    }
95
  }
96
 
97
  /**
98
   * Set a collection of IDs to use in the value of this Header.
99
   * @param string[] $ids
100
   * @throws Swift_RfcComplianceException
101
   */
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
      {
118
        throw new Swift_RfcComplianceException(
119
          'Invalid ID given <' . $id . '>'
120
          );
121
      }
122
    }
123
 
124
    $this->clearCachedValueIf($this->_ids != $actualIds);
125
    $this->_ids = $actualIds;
126
  }
127
 
128
  /**
129
   * Get the list of IDs used in this Header.
130
   * @return string[]
131
   */
132
  public function getIds()
133
  {
134
    return $this->_ids;
135
  }
136
 
137
  /**
138
   * Get the string value of the body in this Header.
139
   * This is not necessarily RFC 2822 compliant since folding white space will
140
   * not be added at this stage (see {@link toString()} for that).
141
   * @return string
142
   * @see toString()
143
   * @throws Swift_RfcComplianceException
144
   */
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
}