1: <?php
2:
3: /*
4: * This file is part of SwiftMailer.
5: * (c) 2004-2009 Chris Corbyn
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: /**
12: * General utility class in Swift Mailer, not to be instantiated.
13: *
14: * @package Swift
15: *
16: * @author Chris Corbyn
17: */
18: abstract class Swift
19: {
20: public static $initialized = false;
21: public static $inits = array();
22:
23: /** Swift Mailer Version number generated during dist release process */
24: const VERSION = '4.2.1';
25:
26: /**
27: * Registers an initializer callable that will be called the first time
28: * a SwiftMailer class is autoloaded.
29: *
30: * This enables you to tweak the default configuration in a lazy way.
31: *
32: * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
33: */
34: public static function init($callable)
35: {
36: self::$inits[] = $callable;
37: }
38:
39: /**
40: * Internal autoloader for spl_autoload_register().
41: *
42: * @param string $class
43: */
44: public static function autoload($class)
45: {
46: //Don't interfere with other autoloaders
47: if (0 !== strpos($class, 'Swift_')) {
48: return;
49: }
50:
51: $path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
52:
53: if (!file_exists($path)) {
54: return;
55: }
56:
57: require $path;
58:
59: if (self::$inits && !self::$initialized) {
60: self::$initialized = true;
61: foreach (self::$inits as $init) {
62: call_user_func($init);
63: }
64: }
65: }
66:
67: /**
68: * Configure autoloading using Swift Mailer.
69: *
70: * This is designed to play nicely with other autoloaders.
71: *
72: * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
73: */
74: public static function registerAutoload($callable = null)
75: {
76: if (null !== $callable) {
77: self::$inits[] = $callable;
78: }
79: spl_autoload_register(array('Swift', 'autoload'));
80: }
81: }
82: