UnstructuredHeader.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * @package Swift
  12. * @subpackage Mime
  13. * @author Chris Corbyn
  14. */
  15. class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader
  16. {
  17. /**
  18. * The value of this Header.
  19. * @var string
  20. * @access private
  21. */
  22. private $_value;
  23. /**
  24. * Creates a new SimpleHeader with $name.
  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. * @return int
  38. * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
  39. * @see TYPE_DATE, TYPE_ID, TYPE_PATH
  40. */
  41. public function getFieldType()
  42. {
  43. return self::TYPE_TEXT;
  44. }
  45. /**
  46. * Set the model for the field body.
  47. * This method takes a string for the field value.
  48. * @param string $model
  49. */
  50. public function setFieldBodyModel($model)
  51. {
  52. $this->setValue($model);
  53. }
  54. /**
  55. * Get the model for the field body.
  56. * This method returns a string.
  57. * @return string
  58. */
  59. public function getFieldBodyModel()
  60. {
  61. return $this->getValue();
  62. }
  63. /**
  64. * Get the (unencoded) value of this header.
  65. * @return string
  66. */
  67. public function getValue()
  68. {
  69. return $this->_value;
  70. }
  71. /**
  72. * Set the (unencoded) value of this header.
  73. * @param string $value
  74. */
  75. public function setValue($value)
  76. {
  77. $this->clearCachedValueIf($this->_value != $value);
  78. $this->_value = $value;
  79. }
  80. /**
  81. * Get the value of this header prepared for rendering.
  82. * @return string
  83. */
  84. public function getFieldBody()
  85. {
  86. if (!$this->getCachedValue()) {
  87. $this->setCachedValue(
  88. $this->encodeWords($this, $this->_value)
  89. );
  90. }
  91. return $this->getCachedValue();
  92. }
  93. }