Skip to content

Commit 02a0ebc

Browse files
committed
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
2 parents aa9657c + 6a7468d commit 02a0ebc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

symfony/framework-bundle/3.3/src/Kernel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
/**
1212
* @author Fabien Potencier <fabien@symfony.com>
1313
*/
14-
class Kernel extends BaseKernel
14+
final class Kernel extends BaseKernel
1515
{
1616
use MicroKernelTrait;
1717

18-
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
18+
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
1919

20-
public function getCacheDir()
20+
public function getCacheDir(): string
2121
{
2222
return dirname(__DIR__).'/var/cache/'.$this->environment;
2323
}
2424

25-
public function getLogDir()
25+
public function getLogDir(): string
2626
{
2727
return dirname(__DIR__).'/var/logs';
2828
}
2929

30-
public function registerBundles()
30+
public function registerBundles(): iterable
3131
{
3232
$contents = require dirname(__DIR__).'/etc/bundles.php';
3333
foreach ($contents as $class => $envs) {
@@ -37,7 +37,7 @@ public function registerBundles()
3737
}
3838
}
3939

40-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
40+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
4141
{
4242
$confDir = dirname(__DIR__).'/etc';
4343
$loader->import($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
@@ -47,7 +47,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
4747
$loader->import($confDir.'/container'.self::CONFIG_EXTS, 'glob');
4848
}
4949

50-
protected function configureRoutes(RouteCollectionBuilder $routes)
50+
protected function configureRoutes(RouteCollectionBuilder $routes): void
5151
{
5252
$confDir = dirname(__DIR__).'/etc';
5353
if (is_dir($confDir.'/routing/')) {

0 commit comments

Comments
 (0)