Skip to content

Commit

Permalink
Use PHP to define the services and routes of the app
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 10, 2020
1 parent 602a78b commit 1d2916c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
1 change: 0 additions & 1 deletion symfony/framework-bundle/5.1/config

This file was deleted.

1 change: 1 addition & 0 deletions symfony/framework-bundle/5.1/config/bootstrap.php
1 change: 1 addition & 0 deletions symfony/framework-bundle/5.1/config/packages
3 changes: 3 additions & 0 deletions symfony/framework-bundle/5.1/config/routes/dev/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error
34 changes: 31 additions & 3 deletions symfony/framework-bundle/5.1/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

Expand All @@ -15,14 +16,41 @@ protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
$container->import('../config/{services}.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');

// Put parameters here that don't need to change on each machine where the app is deployed
// https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
//$parameters = $container->parameters();
//$parameters->set(...);

$services = $container->services();

// makes classes in src/ available to be used as services
$services
->load('App\\', './*')
->exclude('./{DependencyInjection,Entity,Migrations,Tests,Kernel.php}');

// controllers are imported separately to make sure services can be injected
// as action arguments even if you don't extend any base controller class
$services
->load('App\\Controller\\', './Controller')
->tag('controller.service_arguments');

// add more service definitions when explicit configuration is needed
// please note that last definitions always *replace* previous ones
//$services->set(...);
}

protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');
$routes->import('../config/{routes}.yaml');

$routes->add('hello', '/hello')
->controller([$this, 'helloAction']);
}

public function helloAction()
{
return new Response('Hello World');
}
}
1 change: 1 addition & 0 deletions symfony/routing/5.1/config/packages
6 changes: 6 additions & 0 deletions symfony/routing/5.1/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"copy-from-recipe": {
"config/": "%CONFIG_DIR%/"
},
"aliases": ["router"]
}

0 comments on commit 1d2916c

Please sign in to comment.