Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69a78d3

Browse files
committed
added a special autoloader for Swiftmailer
This removed the need to get the 'mailer' service before doing anything with Swiftmailer.
1 parent ed7e0bc commit 69a78d3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

app/autoload.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,25 @@
1818
$loader->registerPrefixes(array(
1919
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
2020
'Twig_' => __DIR__.'/../vendor/twig/lib',
21-
'Swift_' => __DIR__.'/../vendor/swiftmailer/lib/classes',
2221
));
2322
$loader->register();
2423
$loader->registerPrefixFallback(array(
2524
__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs',
2625
));
26+
27+
// Swiftmailer needs a special autoloader to allow
28+
// the lazy loading of the init file (which is expensive)
29+
spl_autoload_register(function ($class) {
30+
static $initialized = false;
31+
32+
$src = __DIR__.'/../vendor/swiftmailer/lib';
33+
34+
if (0 === strpos($class, 'Swift_') && file_exists($path = $src.'/classes/'.str_replace('_', '/', $class).'.php')) {
35+
if (!$initialized) {
36+
$initialized = true;
37+
require $src.'/swift_init.php';
38+
}
39+
40+
require $path;
41+
}
42+
});

0 commit comments

Comments
 (0)