Preferences.php 2.0KB

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