<?php use Sirprize\Scrubble\Bootstrap; require_once 'vendor/sirprize/scrubble/lib/Sirprize/Scrubble/Bootstrap.php'; $services = Bootstrap::getServices(Bootstrap::run(__DIR__ . '/config/config.php')); $response = $services->get('kernel')->handle($services->get('request'))->send();
public static function getServices(array $config) { $services = new DiContainer(); $services['config'] = $config; // scribbles $services['scribble.directory'] = $services->share(function ($c) { return new ScribbleDirWithSubdirs($c['config']['scribble.directory']); }); $services['scribble.repository'] = $services->share(function ($c) { $repository = new ScribbleRepository($c['config']['scribble.repository']); $repository->setDirectory($c['scribble.directory']); return $repository; }); // pages $services['page.directory'] = $services->share(function ($c) { return new ScribbleDirWithFiles($c['config']['page.directory']); }); $services['page.repository'] = $services->share(function ($c) { $repository = new ScribbleRepository($c['config']['page.repository']); $repository->setDirectory($c['page.directory']); return $repository; }); // misc $services['theme'] = $services->share(function ($c) { return new Theme($c['config']['theme']); }); $services['google'] = $services->share(function ($c) { return new Config($c['config']['google']); }); $services['facebook'] = $services->share(function ($c) { return new Config($c['config']['facebook']); }); // framework stuff $services['routes'] = $services->share(function ($c) { return Bootstrap::getDefaultRoutes(); }); $services['context'] = $services->share(function ($c) { $context = new RequestContext(); $context->fromRequest($c['request']); return $context; }); $services['matcher'] = $services->share(function ($c) { return new UrlMatcher($c['routes'], $c['context']); }); $services['dispatcher'] = $services->share(function ($c) { $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener($c['matcher'])); $dispatcher->addSubscriber(new ControllerServicesInjector($c)); #$dispatcher->addSubscriber(new ResponseFilter($c)); $dispatcher->addSubscriber(new ExceptionListener(array(new ErrorController(), 'indexAction'))); return $dispatcher; }); $services['urler'] = $services->share(function ($c) { return new UrlGenerator($c['routes'], $c['context']); }); $services['resolver'] = $services->share(function ($c) { return new ControllerResolver(); }); $services['kernel'] = $services->share(function ($c) { return new HttpKernel($c['dispatcher'], $c['resolver']); }); $services['request'] = $services->share(function ($c) { $request = Request::createFromGlobals(); $request->attributes->add(array('services' => $c)); return $request; }); $services['view'] = $services->share(function ($c) { $loader = new FilesystemLoader($c['theme']->getTemplateDir() . '/%name%'); return new PhpEngine(new TemplateNameParser(), $loader); }); return $services; }