Skip to content

Commit 256e76f

Browse files
committed
change ProxyPackages and ProxyUrlRewriteListener to inject the ProxyUrlMatcher object instead of ProxyUrlCollection
1 parent e236840 commit 256e76f

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/Asset/ProxyPackages.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
namespace PHPMentors\ProxyURLRewriteBundle\Asset;
1414

15-
use PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlCollection;
1615
use PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlMatcher;
1716
use Symfony\Component\Asset\Packages;
1817
use Symfony\Component\Routing\Generator\UrlGenerator;
@@ -27,16 +26,20 @@
2726
class ProxyPackages extends Packages
2827
{
2928
/**
30-
* @var ProxyUrlCollection
29+
* @var ProxyUrlMatcher
30+
*
31+
* @since Property available since Release 1.1.0
3132
*/
32-
private $proxyUrlCollection;
33+
private $proxyUrlMatcher;
3334

3435
/**
35-
* @param ProxyUrlCollection $proxyUrlCollection
36+
* @param ProxyUrlMatcher $proxyUrlMatcher
37+
*
38+
* @since Method available since Release 1.1.0
3639
*/
37-
public function setProxyUrlCollection(ProxyUrlCollection $proxyUrlCollection)
40+
public function setProxyUrlMatcher(ProxyUrlMatcher $proxyUrlMatcher)
3841
{
39-
$this->proxyUrlCollection = $proxyUrlCollection;
42+
$this->proxyUrlMatcher = $proxyUrlMatcher;
4043
}
4144

4245
/**
@@ -56,8 +59,7 @@ public function getUrl($path, $packageName = null)
5659
return $url;
5760
}
5861

59-
$urlMatcher = new ProxyUrlMatcher($this->proxyUrlCollection);
60-
$matchedProxyUrl = $urlMatcher->match($url);
62+
$matchedProxyUrl = $this->proxyUrlMatcher->match($url);
6163
if ($matchedProxyUrl === null) {
6264
return $url;
6365
}

src/EventListener/ProxyUrlRewriteListener.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright (c) 2014 KUBO Atsuhiro <[email protected]>,
3+
* Copyright (c) 2014-2015 KUBO Atsuhiro <[email protected]>,
44
* All rights reserved.
55
*
66
* This file is part of PHPMentorsProxyURLRewriteBundle.
@@ -12,7 +12,6 @@
1212

1313
namespace PHPMentors\ProxyURLRewriteBundle\EventListener;
1414

15-
use PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlCollection;
1615
use PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlMatcher;
1716
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1817
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -21,21 +20,25 @@
2120
class ProxyUrlRewriteListener
2221
{
2322
/**
24-
* @var ProxyUrlCollection
23+
* @var ProxyUrlMatcher
24+
*
25+
* @since Property available since Release 1.1.0
2526
*/
26-
private $proxyUrlCollection;
27+
private $proxyUrlMatcher;
2728

2829
/**
2930
* @var RouterInterface
3031
*/
3132
private $router;
3233

3334
/**
34-
* @param ProxyUrlCollection $proxyUrlCollection
35+
* @param ProxyUrlMatcher $proxyUrlMatcher
36+
*
37+
* @since Method available since Release 1.1.0
3538
*/
36-
public function setProxyUrlCollection(ProxyUrlCollection $proxyUrlCollection)
39+
public function setProxyUrlMatcher(ProxyUrlMatcher $proxyUrlMatcher)
3740
{
38-
$this->proxyUrlCollection = $proxyUrlCollection;
41+
$this->proxyUrlMatcher = $proxyUrlMatcher;
3942
}
4043

4144
/**
@@ -52,8 +55,7 @@ public function setRouter(RouterInterface $router)
5255
public function onKernelRequest(GetResponseEvent $event)
5356
{
5457
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
55-
$urlMatcher = new ProxyUrlMatcher($this->proxyUrlCollection);
56-
$matchedProxyUrl = $urlMatcher->match($this->router->getContext()->getPathInfo());
58+
$matchedProxyUrl = $this->proxyUrlMatcher->match($this->router->getContext()->getPathInfo());
5759
if ($matchedProxyUrl !== null) {
5860
$this->router->getContext()->setBaseUrl($matchedProxyUrl->getPath().$this->router->getContext()->getBaseUrl());
5961

src/Resources/config/services.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
<parameter key="phpmentors_proxy_url_rewrite.proxy_url.class">PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrl</parameter>
77
<parameter key="phpmentors_proxy_url_rewrite.proxy_url_collection.class">PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlCollection</parameter>
88
<parameter key="phpmentors_proxy_url_rewrite.proxy_url_factory.class">PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlFactory</parameter>
9+
<parameter key="phpmentors_proxy_url_rewrite.proxy_url_matcher.class">PHPMentors\ProxyURLRewriteBundle\ProxyUrl\ProxyUrlMatcher</parameter>
910
<parameter key="phpmentors_proxy_url_rewrite.proxy_url_rewrite_listener.class">PHPMentors\ProxyURLRewriteBundle\EventListener\ProxyUrlRewriteListener</parameter>
1011
</parameters>
1112
<services>
1213
<service id="phpmentors_proxy_url_rewrite.proxy_packages" class="%phpmentors_proxy_url_rewrite.proxy_packages.class%" public="false">
13-
<call method="setProxyUrlCollection">
14-
<argument type="service" id="phpmentors_proxy_url_rewrite.proxy_url_collection"/>
14+
<call method="setProxyUrlMatcher">
15+
<argument type="service" id="phpmentors_proxy_url_rewrite.proxy_url_matcher"/>
1516
</call>
1617
</service>
1718
<service id="phpmentors_proxy_url_rewrite.proxy_asset_extension" class="%phpmentors_proxy_url_rewrite.proxy_asset_extension.class%" public="false"/>
@@ -20,9 +21,12 @@
2021
</service>
2122
<service id="phpmentors_proxy_url_rewrite.proxy_url_collection" class="%phpmentors_proxy_url_rewrite.proxy_url_collection.class%" public="false"/>
2223
<service id="phpmentors_proxy_url_rewrite.proxy_url_factory" class="%phpmentors_proxy_url_rewrite.proxy_url_factory.class%" public="false"/>
24+
<service id="phpmentors_proxy_url_rewrite.proxy_url_matcher" class="%phpmentors_proxy_url_rewrite.proxy_url_matcher.class%" public="false">
25+
<argument type="service" id="phpmentors_proxy_url_rewrite.proxy_url_collection"/>
26+
</service>
2327
<service id="phpmentors_proxy_url_rewrite.proxy_url_rewrite_listener" class="%phpmentors_proxy_url_rewrite.proxy_url_rewrite_listener.class%">
24-
<call method="setProxyUrlCollection">
25-
<argument type="service" id="phpmentors_proxy_url_rewrite.proxy_url_collection"/>
28+
<call method="setProxyUrlMatcher">
29+
<argument type="service" id="phpmentors_proxy_url_rewrite.proxy_url_matcher"/>
2630
</call>
2731
<call method="setRouter">
2832
<argument type="service" id="router"/>

0 commit comments

Comments
 (0)