UnstructuredHeader.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * @author Chris Corbyn
  13. */
  14. class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader
  15. {
  16. /**
  17. * The value of this Header.
  18. *
  19. * @var string
  20. */
  21. private $_value;
  22. /**
  23. * Creates a new SimpleHeader with $name.
  24. *
  25. * @param string $name
  26. * @param Swift_Mime_HeaderEncoder $encoder
  27. * @param Swift_Mime_Grammar $grammar
  28. */
  29. public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Mime_Grammar $grammar)
  30. {
  31. $this->setFieldName($name);
  32. $this->setEncoder($encoder);
  33. parent::__construct($grammar);
  34. }
  35. /**
  36. * Get the type of Header that this instance represents.
  37. *
  38. * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
  39. * @see TYPE_DATE, TYPE_ID, TYPE_PATH
  40. *
  41. * @return int
  42. */
  43. public function getFieldType()
  44. {
  45. return self::TYPE_TEXT;
  46. }
  47. /**
  48. * Set the model for the field body.
  49. *
  50. * This method takes a string for the field value.
  51. *
  52. * @param string $model
  53. */
  54. public function setFieldBodyModel($model)
  55. {
  56. $this->setValue($model);
  57. }
  58. /**
  59. * Get the model for the field body.
  60. *
  61. * This method returns a string.
  62. *
  63. * @return string
  64. */
  65. public function getFieldBodyModel()
  66. {
  67. return $this->getValue();
  68. }
  69. /**
  70. * Get the (unencoded) value of this header.
  71. *
  72. * @return string
  73. */
  74. public function getValue()
  75. {
  76. return $this->_value;
  77. }
  78. /**
  79. * Set the (unencoded) value of this header.
  80. *
  81. * @param string $value
  82. */
  83. public function setValue($value)
  84. {
  85. $this->clearCachedValueIf($this->_value != $value);
  86. $this->_value = $value;
  87. }
  88. /**
  89. * Get the value of this header prepared for rendering.
  90. *
  91. * @return string
  92. */
  93. public function getFieldBody()
  94. {
  95. if (!$this->getCachedValue()) {
  96. $this->setCachedValue(
  97. $this->encodeWords($this, $this->_value)
  98. );
  99. }
  100. return $this->getCachedValue();
  101. }
  102. }