Swift.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * General utility class in Swift Mailer, not to be instantiated.
  11. *
  12. * @package Swift
  13. *
  14. * @author Chris Corbyn
  15. */
  16. abstract class Swift
  17. {
  18. static $initialized = false;
  19. static $initPath;
  20. /** Swift Mailer Version number generated during dist release process */
  21. const VERSION = '@SWIFT_VERSION_NUMBER@';
  22. /**
  23. * Internal autoloader for spl_autoload_register().
  24. *
  25. * @param string $class
  26. */
  27. public static function autoload($class)
  28. {
  29. //Don't interfere with other autoloaders
  30. if (0 !== strpos($class, 'Swift_'))
  31. {
  32. return;
  33. }
  34. $path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
  35. if (!file_exists($path))
  36. {
  37. return;
  38. }
  39. if (self::$initPath && !self::$initialized)
  40. {
  41. self::$initialized = true;
  42. require self::$initPath;
  43. }
  44. require $path;
  45. }
  46. /**
  47. * Configure autoloading using Swift Mailer.
  48. *
  49. * This is designed to play nicely with other autoloaders.
  50. *
  51. * @param string $initPath The init script to load when autoloading the first Swift class
  52. */
  53. public static function registerAutoload($initPath = null)
  54. {
  55. self::$initPath = $initPath;
  56. spl_autoload_register(array('Swift', 'autoload'));
  57. }
  58. }