UnstructuredHeader.php 2.2KB

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