Preferences.php 2.3 KB

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