Preferences.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 self
  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 $this
  40. */
  41. public function setCharset($charset)
  42. {
  43. Swift_DependencyContainer::getInstance()->register('properties.charset')->asValue($charset);
  44. return $this;
  45. }
  46. /**
  47. * Set the directory where temporary files can be saved.
  48. *
  49. * @param string $dir
  50. *
  51. * @return $this
  52. */
  53. public function setTempDir($dir)
  54. {
  55. Swift_DependencyContainer::getInstance()->register('tempdir')->asValue($dir);
  56. return $this;
  57. }
  58. /**
  59. * Set the type of cache to use (i.e. "disk" or "array").
  60. *
  61. * @param string $type
  62. *
  63. * @return $this
  64. */
  65. public function setCacheType($type)
  66. {
  67. Swift_DependencyContainer::getInstance()->register('cache')->asAliasOf(sprintf('cache.%s', $type));
  68. return $this;
  69. }
  70. /**
  71. * Set the QuotedPrintable dot escaper preference.
  72. *
  73. * @param bool $dotEscape
  74. *
  75. * @return $this
  76. */
  77. public function setQPDotEscape($dotEscape)
  78. {
  79. $dotEscape = !empty($dotEscape);
  80. Swift_DependencyContainer::getInstance()
  81. ->register('mime.qpcontentencoder')
  82. ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder')
  83. ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer'])
  84. ->addConstructorValue($dotEscape);
  85. return $this;
  86. }
  87. }