Skip to content

Commit 6d1ec6b

Browse files
committed
bug #13919 Fixed micro kernel demo (Surfoo)
This PR was squashed before being merged into the 5.1 branch. Discussion ---------- Fixed micro kernel demo Hello, Here a fix on the documentation, about the micro kernel demo. I still have a other bug on the controller: ![mk](https://user-images.githubusercontent.com/553659/86048443-d4e2ba00-ba50-11ea-98af-d677947ccafe.png) What's missing to make it work? I'd like to fix it before the merge, can you help me please? Commits ------- 427d992 Fixed micro kernel demo
2 parents c9a72b9 + 427d992 commit 6d1ec6b

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

configuration/micro_kernel_trait.rst

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ Next, create an ``index.php`` file that defines the kernel class and executes it
5454

5555
protected function configureRoutes(RoutingConfigurator $routes)
5656
{
57-
// kernel is a service that points to this class
58-
// optional 3rd argument is the route name
59-
$routes->add('/random/{limit}', 'kernel::randomNumber');
57+
$routes->add('random_number', '/random/{limit}')->controller([$this, 'randomNumber']);
6058
}
6159

6260
public function randomNumber($limit)
@@ -151,7 +149,7 @@ hold the kernel. Now it looks like this::
151149
];
152150

153151
if ($this->getEnvironment() == 'dev') {
154-
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
152+
$bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
155153
}
156154

157155
return $bundles;
@@ -160,6 +158,7 @@ hold the kernel. Now it looks like this::
160158
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
161159
{
162160
$loader->load(__DIR__.'/../config/framework.yaml');
161+
$loader->load(__DIR__.'/../config/services.yaml');
163162

164163
// configure WebProfilerBundle only if the bundle is enabled
165164
if (isset($this->bundles['WebProfilerBundle'])) {
@@ -201,6 +200,61 @@ Before continuing, run this command to add support for the new dependencies:
201200
202201
$ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle doctrine/annotations
203202
203+
You need add the following service configuration, which is the default config for a new project:
204+
205+
.. configuration-block::
206+
207+
.. code-block:: yaml
208+
209+
# config/services.yaml
210+
services:
211+
# default configuration for services in *this* file
212+
_defaults:
213+
autowire: true # Automatically injects dependencies in your services.
214+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
215+
216+
# makes classes in src/ available to be used as services
217+
# this creates a service per class whose id is the fully-qualified class name
218+
App\:
219+
resource: '../src/*'
220+
221+
.. code-block:: xml
222+
223+
<!-- config/services.xml -->
224+
<?xml version="1.0" encoding="UTF-8" ?>
225+
<container xmlns="http://symfony.com/schema/dic/services"
226+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
227+
xsi:schemaLocation="http://symfony.com/schema/dic/services
228+
https://symfony.com/schema/dic/services/services-1.0.xsd">
229+
230+
<services>
231+
<!-- Default configuration for services in *this* file -->
232+
<defaults autowire="true" autoconfigure="true"/>
233+
234+
<!-- makes classes in src/ available to be used as services -->
235+
<!-- this creates a service per class whose id is the fully-qualified class name -->
236+
<prototype namespace="App\" resource="../src/*"/>
237+
</services>
238+
</container>
239+
240+
.. code-block:: php
241+
242+
// config/services.php
243+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
244+
245+
return function(ContainerConfigurator $configurator) {
246+
// default configuration for services in *this* file
247+
$services = $configurator->services()
248+
->defaults()
249+
->autowire() // Automatically injects dependencies in your services.
250+
->autoconfigure() // Automatically registers your services as commands, event subscribers, etc.
251+
;
252+
253+
// makes classes in src/ available to be used as services
254+
// this creates a service per class whose id is the fully-qualified class name
255+
$services->load('App\\', '../src/*');
256+
};
257+
204258
Unlike the previous kernel, this loads an external ``config/framework.yaml`` file,
205259
because the configuration started to get bigger:
206260

0 commit comments

Comments
 (0)