Skip to content
Browse files

added a special autoloader for Swiftmailer

This removed the need to get the 'mailer' service before doing anything with Swiftmailer.
  • Loading branch information...
1 parent ed7e0bc commit 69a78d30b07b5563ba972f2cc8f43326f64db8e2 @fabpot fabpot committed May 26, 2011
Showing with 17 additions and 1 deletion.
  1. +17 −1 app/autoload.php
View
18 app/autoload.php
@@ -18,9 +18,25 @@
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
- 'Swift_' => __DIR__.'/../vendor/swiftmailer/lib/classes',
));
$loader->register();
$loader->registerPrefixFallback(array(
__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs',
));
+
+// Swiftmailer needs a special autoloader to allow
+// the lazy loading of the init file (which is expensive)
+spl_autoload_register(function ($class) {
+ static $initialized = false;
+
+ $src = __DIR__.'/../vendor/swiftmailer/lib';
+
+ if (0 === strpos($class, 'Swift_') && file_exists($path = $src.'/classes/'.str_replace('_', '/', $class).'.php')) {
+ if (!$initialized) {
+ $initialized = true;
+ require $src.'/swift_init.php';
+ }
+
+ require $path;
+ }
+});

0 comments on commit 69a78d3

Please sign in to comment.
Something went wrong with that request. Please try again.