Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit427d992

Browse files
Surfoowouterj
authored andcommitted
Fixed micro kernel demo
1 parent4153d5e commit427d992

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+
<containerxmlns="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+
<defaultsautowire="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+
<prototypenamespace="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)

[8]ページ先頭

©2009-2025 Movatter.jp