UnstructuredHeader.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * A Simple MIME Header.
  11. *
  12. * @package Swift
  13. * @subpackage Mime
  14. * @author Chris Corbyn
  15. */
  16. class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader
  17. {
  18. /**
  19. * The value of this Header.
  20. *
  21. * @var string
  22. */
  23. private $_value;
  24. /**
  25. * Creates a new SimpleHeader with $name.
  26. *
  27. * @param string $name
  28. * @param Swift_Mime_HeaderEncoder $encoder
  29. * @param Swift_Mime_Grammar $grammar
  30. */
  31. public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Mime_Grammar $grammar)
  32. {
  33. $this->setFieldName($name);
  34. $this->setEncoder($encoder);
  35. parent::__construct($grammar);
  36. }
  37. /**
  38. * Get the type of Header that this instance represents.
  39. *
  40. * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
  41. * @see TYPE_DATE, TYPE_ID, TYPE_PATH
  42. *
  43. * @return int
  44. */
  45. public function getFieldType()
  46. {
  47. return self::TYPE_TEXT;
  48. }
  49. /**
  50. * Set the model for the field body.
  51. *
  52. * This method takes a string for the field value.
  53. *
  54. * @param string $model
  55. */
  56. public function setFieldBodyModel($model)
  57. {
  58. $this->setValue($model);
  59. }
  60. /**
  61. * Get the model for the field body.
  62. *
  63. * This method returns a string.
  64. *
  65. * @return string
  66. */
  67. public function getFieldBodyModel()
  68. {
  69. return $this->getValue();
  70. }
  71. /**
  72. * Get the (unencoded) value of this header.
  73. *
  74. * @return string
  75. */
  76. public function getValue()
  77. {
  78. return $this->_value;
  79. }
  80. /**
  81. * Set the (unencoded) value of this header.
  82. *
  83. * @param string $value
  84. */
  85. public function setValue($value)
  86. {
  87. $this->clearCachedValueIf($this->_value != $value);
  88. $this->_value = $value;
  89. }
  90. /**
  91. * Get the value of this header prepared for rendering.
  92. *
  93. * @return string
  94. */
  95. public function getFieldBody()
  96. {
  97. if (!$this->getCachedValue()) {
  98. $this->setCachedValue(
  99. $this->encodeWords($this, $this->_value)
  100. );
  101. }
  102. return $this->getCachedValue();
  103. }
  104. }