Preferences.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * Changes some global preference settings in Swift Mailer.
  11. *
  12. * @package Swift
  13. * @author Chris Corbyn
  14. */
  15. class Swift_Preferences
  16. {
  17. /** Singleton instance */
  18. private static $_instance = null;
  19. /** Constructor not to be used */
  20. private function __construct()
  21. {
  22. }
  23. /**
  24. * Gets the instance of Preferences.
  25. *
  26. * @return Swift_Preferences
  27. */
  28. public static function getInstance()
  29. {
  30. if (!isset(self::$_instance)) {
  31. self::$_instance = new self();
  32. }
  33. return self::$_instance;
  34. }
  35. /**
  36. * Set the default charset used.
  37. *
  38. * @param string $charset
  39. *
  40. * @return Swift_Preferences
  41. */
  42. public function setCharset($charset)
  43. {
  44. Swift_DependencyContainer::getInstance()
  45. ->register('properties.charset')->asValue($charset);
  46. return $this;
  47. }
  48. /**
  49. * Set the directory where temporary files can be saved.
  50. *
  51. * @param string $dir
  52. *
  53. * @return Swift_Preferences
  54. */
  55. public function setTempDir($dir)
  56. {
  57. Swift_DependencyContainer::getInstance()
  58. ->register('tempdir')->asValue($dir);
  59. return $this;
  60. }
  61. /**
  62. * Set the type of cache to use (i.e. "disk" or "array").
  63. *
  64. * @param string $type
  65. *
  66. * @return Swift_Preferences
  67. */
  68. public function setCacheType($type)
  69. {
  70. Swift_DependencyContainer::getInstance()
  71. ->register('cache')->asAliasOf(sprintf('cache.%s', $type));
  72. return $this;
  73. }
  74. /**
  75. * Set the QuotedPrintable dot escaper preference.
  76. *
  77. * @param boolean $dotEscape
  78. *
  79. * @return Swift_Preferences
  80. */
  81. public function setQPDotEscape($dotEscape)
  82. {
  83. $dotEscape = !empty($dotEscape);
  84. Swift_DependencyContainer::getInstance()
  85. -> register('mime.qpcontentencoder')
  86. -> asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder')
  87. -> withDependencies(array('mime.charstream', 'mime.bytecanonicalizer'))
  88. -> addConstructorValue($dotEscape);
  89. return $this;
  90. }
  91. }