Preferences.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * @package Swift
  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. * Get a new instance of Preferences.
  22. * @return Swift_Preferences
  23. */
  24. public static function getInstance()
  25. {
  26. if (!isset(self::$_instance)) {
  27. self::$_instance = new self();
  28. }
  29. return self::$_instance;
  30. }
  31. /**
  32. * Set the default charset used.
  33. * @param string
  34. * @return Swift_Preferences
  35. */
  36. public function setCharset($charset)
  37. {
  38. Swift_DependencyContainer::getInstance()
  39. ->register('properties.charset')->asValue($charset);
  40. return $this;
  41. }
  42. /**
  43. * Set the directory where temporary files can be saved.
  44. * @param string $dir
  45. * @return Swift_Preferences
  46. */
  47. public function setTempDir($dir)
  48. {
  49. Swift_DependencyContainer::getInstance()
  50. ->register('tempdir')->asValue($dir);
  51. return $this;
  52. }
  53. /**
  54. * Set the type of cache to use (i.e. "disk" or "array").
  55. * @param string $type
  56. * @return Swift_Preferences
  57. */
  58. public function setCacheType($type)
  59. {
  60. Swift_DependencyContainer::getInstance()
  61. ->register('cache')->asAliasOf(sprintf('cache.%s', $type));
  62. return $this;
  63. }
  64. /**
  65. * Add the
  66. * @param boolean $dotEscape
  67. * @return Swift_Preferences
  68. */
  69. public function setQPDotEscape($dotEscape)
  70. {
  71. $dotEscape=!empty($dotEscape);
  72. Swift_DependencyContainer::getInstance()
  73. -> register('mime.qpcontentencoder')
  74. -> asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder')
  75. -> withDependencies(array('mime.charstream', 'mime.bytecanonicalizer'))
  76. -> addConstructorValue($dotEscape);
  77. return $this;
  78. }
  79. }