forkcms/forkcms — pull request #323 by davelens (2012-10-02 14:55:46+00:00)
Title: Refactor bootstrap.php + proof of concept for service container in front/backend

This is a proof of concept for the new bootstrapper.

I tried to follow Symfony's way of handling things as good as possible, and started work from @jelmersnoeck's HttpKernelInterface implementation:

- Front controller is located in app/bootstrap.php for now (It's required by several files in Fork)
- AppKernel class that can hold registerBundles() whenever we want to start working with bundles.
- AppKernel extends from Kernel, which implements HttpKernelInterface. This is 100% how Symfony handle things, with a few interfaces that handle bundle-booting cut out.
- @jelmersnoeck's ApplicationRouting class loads Fork. I built on that to pass along the service container. It contains a few settings, and is proof of concept.
- AppKernel also accepts an environment and debug mode flag, just like Symfony:
```
$kernel = new AppKernel('dev', true);
```
If set, it reads a globals file from app/config/globals_.php. Again, this is conceptual until the Config component is looked at more closely.
- FrontendModel/BackendModel no longer have a getDB(), but inherit from app/BaseModel, which uses the service container to create its database connection. This is by no means proper, but shows a working implementation of the service container.

Frontend/Backend are modified to make the service container available in their actions:

```php
$page = Spoon::get('page');
$container = $page->getContainer();
$records = $container->get('database')->getRecords('...');
```

The way Symfony does it is loading bundles in the Kernel, "booting" them and passing along the initialized service container to each bundle. We can't do this yet, so I made it available through the FrontendPage object for now.