mirror of
https://github.com/symfony/recipes.git
synced 2026-09-16 01:26:25 +03:00
feature #20 [framework-bundle] use typehints when possible (dunglas)
This PR was squashed before being merged into the master branch (closes #20).
Discussion
----------
[framework-bundle] use typehints when possible
This PR targets PHP 7, but switching to PHP 7.1 would allow to generate stricter code:
```php
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class Kernel extends BaseKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir(): string
{
return dirname(__DIR__).'/var/cache/'.$this->environment;
}
public function getLogDir(): string
{
return dirname(__DIR__).'/var/logs';
}
public function registerBundles(): iterable
{
$contents = require dirname(__DIR__).'/etc/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->getEnvironment()])) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$confDir = dirname(__DIR__).'/etc';
$loader->import($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
if (is_dir($confDir.'/packages/'.$this->getEnvironment())) {
$loader->import($confDir.'/packages/'.$this->getEnvironment().'/**/*'.self::CONFIG_EXTS, 'glob');
}
$loader->import($confDir.'/container'.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = dirname(__DIR__).'/etc';
if (is_dir($confDir.'/routing/')) {
$routes->import($confDir.'/routing/*'.self::CONFIG_EXTS, '/', 'glob');
}
if (is_dir($confDir.'/routing/'.$this->getEnvironment())) {
$routes->import($confDir.'/routing/'.$this->getEnvironment().'/**/*'.self::CONFIG_EXTS, '/', 'glob');
}
$routes->import($confDir.'/routing'.self::CONFIG_EXTS, '/', 'glob');
}
}
```
Commits
-------
6a7468d [framework-bundle] use typehints when possible
This commit is contained in:
@@ -11,23 +11,23 @@ use Symfony\Component\Routing\RouteCollectionBuilder;
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Kernel extends BaseKernel
|
||||
final class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
|
||||
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
|
||||
|
||||
public function getCacheDir()
|
||||
public function getCacheDir(): string
|
||||
{
|
||||
return dirname(__DIR__).'/var/cache/'.$this->environment;
|
||||
}
|
||||
|
||||
public function getLogDir()
|
||||
public function getLogDir(): string
|
||||
{
|
||||
return dirname(__DIR__).'/var/logs';
|
||||
}
|
||||
|
||||
public function registerBundles()
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
$contents = require dirname(__DIR__).'/etc/bundles.php';
|
||||
foreach ($contents as $class => $envs) {
|
||||
@@ -37,7 +37,7 @@ class Kernel extends BaseKernel
|
||||
}
|
||||
}
|
||||
|
||||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
|
||||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
|
||||
{
|
||||
$confDir = dirname(__DIR__).'/etc';
|
||||
$loader->import($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
|
||||
@@ -47,7 +47,7 @@ class Kernel extends BaseKernel
|
||||
$loader->import($confDir.'/container'.self::CONFIG_EXTS, 'glob');
|
||||
}
|
||||
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes)
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes): void
|
||||
{
|
||||
$confDir = dirname(__DIR__).'/etc';
|
||||
if (is_dir($confDir.'/routing/')) {
|
||||
|
||||
Reference in New Issue
Block a user