Commit 12bb71b2 authored by Fabien Potencier's avatar Fabien Potencier

added a way for extension to automatically register autoloading rules

parent cda8dce8
...@@ -29,6 +29,7 @@ use Symfony\Component\Routing\RouteCollection; ...@@ -29,6 +29,7 @@ use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Matcher\Exception\NotFoundException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException;
use Symfony\Component\ClassLoader\UniversalClassLoader;
/** /**
* The Silex framework class. * The Silex framework class.
...@@ -44,9 +45,17 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -44,9 +45,17 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
{ {
$sc = $this; $sc = $this;
$this['autoloader'] = $this->asShared(function () {
$loader = new UniversalClassLoader();
$loader->register();
return $loader;
});
$this['routes'] = $this->asShared(function () { $this['routes'] = $this->asShared(function () {
return new RouteCollection(); return new RouteCollection();
}); });
$this['controllers'] = $this->asShared(function () use ($sc) { $this['controllers'] = $this->asShared(function () use ($sc) {
return new ControllerCollection($sc['routes']); return new ControllerCollection($sc['routes']);
}); });
......
...@@ -25,5 +25,9 @@ class TwigExtension implements ExtensionInterface ...@@ -25,5 +25,9 @@ class TwigExtension implements ExtensionInterface
$app['twig.loader'] = $app->asShared(function () use ($app) { $app['twig.loader'] = $app->asShared(function () use ($app) {
return new \Twig_Loader_Filesystem($app['twig.path']); return new \Twig_Loader_Filesystem($app['twig.path']);
}); });
if (isset($app['twig.class_path'])) {
$app['autoloader']->registerPrefix('Twig_', $app['twig.class_path']);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment