Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3193a90

Browse files
committed
made the proxy path configurable
1 parent ad82893 commit 3193a90

File tree

8 files changed

+88
-10
lines changed

8 files changed

+88
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function getConfigTreeBuilder()
7373

7474
$this->addFormSection($rootNode);
7575
$this->addEsiSection($rootNode);
76+
$this->addProxySection($rootNode);
7677
$this->addProfilerSection($rootNode);
7778
$this->addRouterSection($rootNode);
7879
$this->addSessionSection($rootNode);
@@ -114,6 +115,21 @@ private function addEsiSection(ArrayNodeDefinition $rootNode)
114115
;
115116
}
116117

118+
private function addProxySection(ArrayNodeDefinition $rootNode)
119+
{
120+
$rootNode
121+
->children()
122+
->arrayNode('proxy')
123+
->info('proxy configuration')
124+
->canBeDisabled()
125+
->children()
126+
->scalarNode('path')->defaultValue('/_proxy')->end()
127+
->end()
128+
->end()
129+
->end()
130+
;
131+
}
132+
117133
private function addProfilerSection(ArrayNodeDefinition $rootNode)
118134
{
119135
$rootNode

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public function load(array $configs, ContainerBuilder $container)
9494
$this->registerEsiConfiguration($config['esi'], $loader);
9595
}
9696

97+
if (isset($config['proxy'])) {
98+
$this->registerProxyConfiguration($config['proxy'], $container, $loader);
99+
}
100+
97101
if (isset($config['profiler'])) {
98102
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
99103
}
@@ -184,6 +188,20 @@ private function registerEsiConfiguration(array $config, XmlFileLoader $loader)
184188
}
185189
}
186190

191+
/**
192+
* Loads the proxy configuration.
193+
*
194+
* @param array $config A proxy configuration array
195+
* @param XmlFileLoader $loader An XmlFileLoader instance
196+
*/
197+
private function registerProxyConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
198+
{
199+
if (!empty($config['enabled'])) {
200+
$loader->load('proxy.xml');
201+
$container->setParameter('http_content_renderer.proxy_path', $config['path']);
202+
}
203+
}
204+
187205
/**
188206
* Loads the profiler configuration.
189207
*

src/Symfony/Bundle/FrameworkBundle/Resources/config/content_generator.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parameter key="http_content_renderer.strategy.default.class">Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy</parameter>
1010
<parameter key="http_content_renderer.strategy.hinclude.class">Symfony\Component\HttpKernel\RenderingStrategy\HIncludeRenderingStrategy</parameter>
1111
<parameter key="http_content_renderer.strategy.hinclude.global_template"></parameter>
12-
<parameter key="http_content_renderer.listener.router_proxy.class">Symfony\Component\HttpKernel\EventListener\RouterProxyListener</parameter>
12+
<parameter key="http_content_renderer.proxy_path">/_proxy</parameter>
1313
</parameters>
1414

1515
<services>
@@ -22,19 +22,15 @@
2222
<service id="http_content_renderer.strategy.default" class="%http_content_renderer.strategy.default.class%">
2323
<tag name="kernel.content_renderer_strategy" />
2424
<argument type="service" id="http_kernel" />
25+
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
2526
</service>
2627

2728
<service id="http_content_renderer.strategy.hinclude" class="%http_content_renderer.strategy.hinclude.class%">
2829
<tag name="kernel.content_renderer_strategy" />
2930
<argument type="service" id="templating" on-invalid="null" />
3031
<argument type="service" id="uri_signer" />
3132
<argument>%http_content_renderer.strategy.hinclude.global_template%</argument>
32-
</service>
33-
34-
<!-- FIXME: make the listener registration optional via a configuration setting? -->
35-
<service id="http_content_renderer.listener.router_proxy" class="%http_content_renderer.listener.router_proxy.class%">
36-
<tag name="kernel.event_subscriber" />
37-
<argument type="service" id="uri_signer" />
33+
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
3834
</service>
3935

4036
</services>

src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<tag name="kernel.content_renderer_strategy" />
2323
<argument type="service" id="esi" />
2424
<argument type="service" id="http_content_renderer.strategy.default" />
25+
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
2526
</service>
2627
</services>
2728
</container>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="http_content_renderer.listener.router_proxy.class">Symfony\Component\HttpKernel\EventListener\RouterProxyListener</parameter>
9+
</parameters>
10+
11+
<services>
12+
<service id="http_content_renderer.listener.router_proxy" class="%http_content_renderer.listener.router_proxy.class%">
13+
<tag name="kernel.event_subscriber" />
14+
<argument type="service" id="uri_signer" />
15+
<argument>%http_content_renderer.proxy_path%</argument>
16+
</service>
17+
</services>
18+
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
1313
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
1414
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
15+
<xsd:element name="proxy" type="proxy" minOccurs="0" maxOccurs="1" />
1516
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
1617
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
1718
<xsd:element name="session" type="session" minOccurs="0" maxOccurs="1" />
@@ -44,6 +45,11 @@
4445
<xsd:attribute name="enabled" type="xsd:boolean" />
4546
</xsd:complexType>
4647

48+
<xsd:complexType name="proxy">
49+
<xsd:attribute name="enabled" type="xsd:boolean" />
50+
<xsd:attribute name="path" type="xsd:string" />
51+
</xsd:complexType>
52+
4753
<xsd:complexType name="profiler">
4854
<xsd:all>
4955
<xsd:element name="matcher" type="profiler_matcher" minOccurs="0" maxOccurs="1" />

src/Symfony/Component/HttpKernel/EventListener/RouterProxyListener.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@
3030
class RouterProxyListener implements EventSubscriberInterface
3131
{
3232
private $signer;
33+
private $proxyPath;
3334

34-
public function __construct(UriSigner $signer)
35+
/**
36+
* Constructor.
37+
*
38+
* @param UriSigner $signer A UriSigner instance
39+
* @param string $proxyPath The path that triggers this listener
40+
*/
41+
public function __construct(UriSigner $signer, $proxyPath = '/_proxy')
3542
{
3643
$this->signer = $signer;
44+
$this->proxyPath = $proxyPath;
3745
}
3846

3947
/**
@@ -47,7 +55,7 @@ public function onKernelRequest(GetResponseEvent $event)
4755
{
4856
$request = $event->getRequest();
4957

50-
if ('/_proxy' !== rawurldecode($request->getPathInfo())) {
58+
if ($this->proxyPath !== rawurldecode($request->getPathInfo())) {
5159
return;
5260
}
5361

src/Symfony/Component/HttpKernel/RenderingStrategy/ProxyAwareRenderingStrategy.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\HttpKernel\Controller\ControllerReference;
1515
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpKernel\EventListener\RouterProxyListener;
1617

1718
/**
1819
* Adds the possibility to generate a proxy URI for a given Controller.
@@ -21,6 +22,20 @@
2122
*/
2223
abstract class ProxyAwareRenderingStrategy implements RenderingStrategyInterface
2324
{
25+
private $proxyPath = '/_proxy';
26+
27+
/**
28+
* Sets the proxy path that triggers the proxy listener
29+
*
30+
* @param string $path The path
31+
*
32+
* @see RouterProxyListener
33+
*/
34+
public function setProxyPath($path)
35+
{
36+
$this->proxyPath = $path;
37+
}
38+
2439
/**
2540
* Generates a proxy URI for a given controller.
2641
*
@@ -39,6 +54,6 @@ protected function generateProxyUri(ControllerReference $reference, Request $req
3954

4055
$reference->query['path'] = http_build_query($reference->attributes, '', '&');
4156

42-
return $request->getUriForPath('/_proxy?'.http_build_query($reference->query, '', '&'));
57+
return $request->getUriForPath($this->proxyPath.'?'.http_build_query($reference->query, '', '&'));
4358
}
4459
}

0 commit comments

Comments
 (0)