Microservices are a huge trend, and microframeworks are perfect for them: put together just a few files, write some code, and your done!
But Symfony is a big framework, right? Wrong! Symfony can be as small as a single file!
In this talk, we'll learn how to use Symfony as a micro-framework for your next project. Your app will stay small and clear, but without needing to give up the features or third-party bundles that you love. And if the project grows, it can evolve naturally into a full Symfony project.
So yes, Symfony can also be a microframework. Tell the world!
2. KnpUniversity.com
github.com/weaverryan
Who is this guy?
> Lead for the Symfony documentation
> KnpLabs US - Symfony Consulting,
training & general Kumbaya
> Writer for KnpUniversity.com Tutorials
> Husband of the much more
talented @leannapelham
27. <?php
use SymfonyComponentHttpKernelKernel;
use SymfonyComponentConfigLoaderLoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
new SymfonyBundleFrameworkBundleFrameworkBundle(),
new SymfonyBundleTwigBundleTwigBundle(),
);
}
public function registerContainerConfiguration($loader)
{
$loader->load(
__DIR__.'/config/config_'.$this->getEnvironment().'.yml'
);
}
}
50. public function registerBundles()
{
$bundles = array(
new FrameworkBundle(),
new TwigBundle(),
new SensioFrameworkExtraBundle()
);
if ($this->getEnvironment() == 'dev') {
$bundles[] = new WebProfilerBundle();
}
return $bundles;
}
app/AppKernel.php
75. // app/ApiKernel.php
class ApiKernel extends Kernel
{
use MicroKernelTrait;
public function registerBundles()
{
$bundles = array(
new FrameworkBundle(),
new SensioFrameworkExtraBundle()
);
return $bundles;
}
}
No TwigBundle
76. class ApiKernel extends Kernel
{
// ...
protected function configureContainer($c, $loader)
{
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/api.yml');
}
}
Use PHP logic to load share
config, and custom config
77. class ApiKernel extends Kernel
{
// ...
protected function configureRoutes($routes)
{
$routes->import(
__DIR__.'/../src/Api/Controller/',
'/api',
'annotation'
);
}
public function getCacheDir()
{
return __DIR__.’/../var/cache/api/'
.$this->getEnvironment();
}
}
Load different routes
cacheDir ~= the cache key