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

Commit9e19392

Browse files
committed
[FrameworkBundle][Routing] added Configurators to handle template and redirect controllers
1 parent9bfa258 commit9e19392

26 files changed

+815
-205
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.1.0
55
-----
66

7+
* Added`Routing\Loader` and`Routing\Loader\Configurator` namespaces to ease defining routes with default controllers
78
* Added the`framework.router.context` configuration node to configure the`RequestContext`
89
* Made`MicroKernelTrait::configureContainer()` compatible with`ContainerConfigurator`
910
* Added a new`mailer.message_bus` option to configure or disable the message bus to use to send mails.
@@ -29,7 +30,7 @@ CHANGELOG
2930
* Removed the`translator.selector` and`session.save_listener` services
3031
* Removed`SecurityUserValueResolver`, use`UserValueResolver` instead
3132
* Removed`routing.loader.service`.
32-
* Service route loaders must be tagged with`routing.route_loader`.
33+
* Service route loaders must be tagged with`routing.route_loader`.
3334
* Added`slugger` service and`SluggerInterface` alias
3435
* Removed the`lock.store.flock`,`lock.store.semaphore`,`lock.store.memcached.abstract` and`lock.store.redis.abstract` services.
3536
* Removed the`router.cache_class_prefix` parameter.
@@ -81,8 +82,8 @@ CHANGELOG
8182
options if you're using Symfony's serializer.
8283
*[BC Break] Removed the`framework.messenger.routing.send_and_handle` configuration.
8384
Instead of setting it to true, configure a`SyncTransport` and route messages to it.
84-
* Added information about deprecated aliases in`debug:autowiring`
85-
* Added php ini session options`sid_length` and`sid_bits_per_character`
85+
* Added information about deprecated aliases in`debug:autowiring`
86+
* Added php ini session options`sid_length` and`sid_bits_per_character`
8687
to the`session` section of the configuration
8788
* Added support for Translator paths, Twig paths in translation commands.
8889
* Added support for PHP files with translations in translation commands.

‎src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespaceSymfony\Bundle\FrameworkBundle\Kernel;
1313

14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
15+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\PhpFileLoaderasRoutingPhpFileLoader;
1416
useSymfony\Component\Config\Loader\LoaderInterface;
1517
useSymfony\Component\DependencyInjection\ContainerBuilder;
1618
useSymfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator;
1719
useSymfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1820
useSymfony\Component\DependencyInjection\Loader\PhpFileLoaderasContainerPhpFileLoader;
1921
useSymfony\Component\DependencyInjection\Reference;
20-
useSymfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
21-
useSymfony\Component\Routing\Loader\PhpFileLoaderasRoutingPhpFileLoader;
2222
useSymfony\Component\Routing\RouteCollection;
2323
useSymfony\Component\Routing\RouteCollectionBuilder;
2424

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<argumenttype="service"id="file_locator" />
2626
</service>
2727

28-
<serviceid="routing.loader.php"class="Symfony\Component\Routing\Loader\PhpFileLoader">
28+
<serviceid="routing.loader.php"class="Symfony\Bundle\FrameworkBundle\Routing\Loader\PhpFileLoader">
2929
<tagname="routing.loader" />
3030
<argumenttype="service"id="file_locator" />
3131
</service>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
15+
useSymfony\Component\Routing\Loader\Configurator\RouteConfiguratorasBaseRouteConfigurator;
16+
17+
/**
18+
* @author Jules Pietri <jules@heahprod.com>
19+
*/
20+
finalclass GoneRouteConfiguratorextends BaseRouteConfigurator
21+
{
22+
use AddTrait;
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
15+
useSymfony\Component\Routing\Loader\Configurator\RouteConfiguratorasBaseRouteConfigurator;
16+
17+
/**
18+
* @author Jules Pietri <jules@heahprod.com>
19+
*/
20+
finalclass NotFoundRouteConfiguratorextends BaseRouteConfigurator
21+
{
22+
use AddTrait;
23+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
15+
useSymfony\Component\Routing\Loader\Configurator\RouteConfigurator;
16+
17+
/**
18+
* @author Jules Pietri <jules@heahprod.com>
19+
*/
20+
class RedirectRouteConfiguratorextends RouteConfigurator
21+
{
22+
use AddTrait;
23+
24+
/**
25+
* @param bool $permanent Whether the redirection is permanent
26+
*
27+
* @return $this
28+
*/
29+
finalpublicfunctionpermanent(bool$permanent =true)
30+
{
31+
return$this->defaults(['permanent' =>$permanent]);
32+
}
33+
34+
/**
35+
* @param bool|array $ignoreAttributes Whether to ignore attributes or an array of attributes to ignore
36+
*
37+
* @return $this
38+
*/
39+
finalpublicfunctionignoreAttributes($ignoreAttributes =true)
40+
{
41+
return$this->defaults(['ignoreAttributes' =>$ignoreAttributes]);
42+
}
43+
44+
/**
45+
* @param bool $keepRequestMethod Whether redirect action should keep HTTP request method
46+
*
47+
* @return $this
48+
*/
49+
finalpublicfunctionkeepRequestMethod(bool$keepRequestMethod =true)
50+
{
51+
return$this->defaults(['keepRequestMethod' =>$keepRequestMethod]);
52+
}
53+
54+
/**
55+
* @param bool $keepQueryParams Whether redirect action should keep query parameters
56+
*
57+
* @return $this
58+
*/
59+
finalpublicfunctionkeepQueryParams(bool$keepQueryParams =true)
60+
{
61+
return$this->defaults(['keepQueryParams' =>$keepQueryParams]);
62+
}
63+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Controller\RedirectController;
15+
useSymfony\Bundle\FrameworkBundle\Controller\TemplateController;
16+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
17+
useSymfony\Component\Routing\Loader\Configurator\RouteConfiguratorasBaseRouteConfigurator;
18+
19+
/**
20+
* @author Jules Pietri <jules@heahprod.com>
21+
*/
22+
class RouteConfiguratorextends BaseRouteConfigurator
23+
{
24+
use AddTrait;
25+
26+
/**
27+
* @param string $template The template name
28+
* @param array $context The template variables
29+
*/
30+
finalpublicfunctiontemplate(string$template,array$context = []):TemplateRouteConfigurator
31+
{
32+
return (newTemplateRouteConfigurator($this->collection,$this->route,$this->name,$this->parentConfigurator,$this->prefixes))
33+
->defaults([
34+
'_controller' => TemplateController::class,
35+
'template' =>$template,
36+
'context' =>$context,
37+
])
38+
;
39+
}
40+
41+
/**
42+
* @param string $route The route name to redirect to
43+
*/
44+
finalpublicfunctionredirectToRoute(string$route):RedirectRouteConfigurator
45+
{
46+
return (newRedirectRouteConfigurator($this->collection,$this->route,$this->name,$this->parentConfigurator,$this->prefixes))
47+
->defaults([
48+
'_controller' => RedirectController::class.'::redirectAction',
49+
'route' =>$route,
50+
])
51+
;
52+
}
53+
54+
/**
55+
* @param string $url The relative path or URL to redirect to
56+
*/
57+
finalpublicfunctionredirectToUrl(string$url):UrlRedirectRouteConfigurator
58+
{
59+
return (newUrlRedirectRouteConfigurator($this->collection,$this->route,$this->name,$this->parentConfigurator,$this->prefixes))
60+
->defaults([
61+
'_controller' => RedirectController::class.'::urlRedirectAction',
62+
'path' =>$url,
63+
])
64+
;
65+
}
66+
67+
finalpublicfunctionnotFound():NotFoundRouteConfigurator
68+
{
69+
return (newNotFoundRouteConfigurator($this->collection,$this->route,$this->name,$this->parentConfigurator,$this->prefixes))
70+
->defaults([
71+
'_controller' => RedirectController::class.'::redirectAction',
72+
'route' =>'',
73+
])
74+
;
75+
}
76+
77+
finalpublicfunctiongone():GoneRouteConfigurator
78+
{
79+
return (newGoneRouteConfigurator($this->collection,$this->route,$this->name,$this->parentConfigurator,$this->prefixes))
80+
->defaults([
81+
'_controller' => RedirectController::class.'::redirectAction',
82+
'route' =>'',
83+
'permanent' =>true,
84+
])
85+
;
86+
}
87+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
15+
useSymfony\Component\Routing\Loader\Configurator\RoutingConfiguratorasBaseRoutingConfigurator;
16+
17+
class RoutingConfiguratorextends BaseRoutingConfigurator
18+
{
19+
use AddTrait;
20+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits\AddTrait;
15+
useSymfony\Component\Routing\Loader\Configurator\RouteConfigurator;
16+
17+
/**
18+
* @author Jules Pietri <jules@heahprod.com>
19+
*/
20+
class TemplateRouteConfiguratorextends RouteConfigurator
21+
{
22+
use AddTrait;
23+
24+
/**
25+
* @param int|null $maxAge Max age for client caching
26+
*
27+
* @return $this
28+
*/
29+
finalpublicfunctionmaxAge(?int$maxAge)
30+
{
31+
return$this->defaults(['maxAge' =>$maxAge]);
32+
}
33+
34+
/**
35+
* @param int|null $sharedMaxAge Max age for shared (proxy) caching
36+
*
37+
* @return $this
38+
*/
39+
finalpublicfunctionsharedMaxAge(?int$sharedMaxAge)
40+
{
41+
return$this->defaults(['sharedAge' =>$sharedMaxAge]);
42+
}
43+
44+
/**
45+
* @param bool|null $private Whether or not caching should apply for client caches only
46+
*
47+
* @return $this
48+
*/
49+
finalpublicfunctionprivate(?bool$private =true)
50+
{
51+
return$this->defaults(['private' =>$private]);
52+
}
53+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\Traits;
13+
14+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RouteConfigurator;
15+
useSymfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
16+
useSymfony\Component\Routing\Loader\Configurator\CollectionConfigurator;
17+
useSymfony\Component\Routing\Loader\Configurator\RouteConfiguratorasBaseRouteConfigurator;
18+
19+
trait AddTrait
20+
{
21+
/**
22+
* Adds a route.
23+
*
24+
* @param string|array $path the path, or the localized paths of the route
25+
*
26+
* @return RouteConfigurator
27+
*/
28+
publicfunctionadd(string$name,$path):BaseRouteConfigurator
29+
{
30+
$parentConfigurator =$thisinstanceof CollectionConfigurator ?$this : ($thisinstanceof RouteConfigurator ?$this->parentConfigurator :null);
31+
$route =$this->createLocalizedRoute($this->collection,$name,$path,$this->name,$this->prefixes);
32+
33+
returnnewRouteConfigurator($this->collection,$route,$this->name,$parentConfigurator,$this->prefixes);
34+
}
35+
36+
/**
37+
* Adds a route.
38+
*
39+
* @param string|array $path the path, or the localized paths of the route
40+
*
41+
* @return RouteConfigurator
42+
*/
43+
finalpublicfunction__invoke(string$name,$path):BaseRouteConfigurator
44+
{
45+
return$this->add($name,$path);
46+
}
47+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp