Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Asset/ProxyPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setProxyUrlMatcher(ProxyUrlMatcher $proxyUrlMatcher)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getUrl($path, $packageName = null)
{
Expand Down Expand Up @@ -71,8 +71,14 @@ public function getUrl($path, $packageName = null)
if ($matchedProxyUrl->getHost() !== null) {
$requestContext->setHost($matchedProxyUrl->getHost());
}
if ($matchedProxyUrl->getScheme() !== null) {
$requestContext->setScheme($matchedProxyUrl->getScheme());
$requestContext->setScheme($matchedProxyUrl->getScheme());

if ($matchedProxyUrl->getPort() !== null) {
if ($matchedProxyUrl->getScheme() == 'http') {
$requestContext->setHttpPort($matchedProxyUrl->getPort());
} elseif ($matchedProxyUrl->getScheme() == 'https') {
$requestContext->setHttpsPort($matchedProxyUrl->getPort());
}
}

$urlGenerator = new UrlGenerator($routeCollection, $requestContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class ReplaceAssetExtensionAndPakcagesDefinitionPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class PHPMentorsProxyURLRewriteExtension extends Extension
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand All @@ -35,7 +35,7 @@ public function load(array $configs, ContainerBuilder $container)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getAlias()
{
Expand Down
15 changes: 7 additions & 8 deletions src/EventListener/ProxyUrlRewriteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ public function onKernelRequest(GetResponseEvent $event)
$matchedProxyUrl = $this->proxyUrlMatcher->match($this->router->getContext()->getPathInfo());
if ($matchedProxyUrl !== null) {
$this->router->getContext()->setBaseUrl($matchedProxyUrl->getPath().$this->router->getContext()->getBaseUrl());

if ($matchedProxyUrl->getScheme() !== null) {
$this->router->getContext()->setScheme($matchedProxyUrl->getScheme());
}
$this->router->getContext()->setScheme($matchedProxyUrl->getScheme());

if ($matchedProxyUrl->getHost() !== null) {
$this->router->getContext()->setHost($matchedProxyUrl->getHost());
}

if ($this->router->getContext()->getScheme() == 'http') {
$this->router->getContext()->setHttpPort('80');
} elseif ($this->router->getContext()->getScheme() == 'https') {
$this->router->getContext()->setHttpsPort('443');
if ($matchedProxyUrl->getPort() !== null) {
if ($this->router->getContext()->getScheme() == 'http') {
$this->router->getContext()->setHttpPort($matchedProxyUrl->getPort());
} elseif ($this->router->getContext()->getScheme() == 'https') {
$this->router->getContext()->setHttpsPort($matchedProxyUrl->getPort());
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PHPMentorsProxyURLRewriteBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
class PHPMentorsProxyURLRewriteBundle extends Bundle
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ReplaceAssetExtensionAndPakcagesDefinitionPass());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getContainerExtension()
{
Expand Down
37 changes: 34 additions & 3 deletions src/ProxyUrl/ProxyUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,43 @@ class ProxyUrl implements EntityInterface, IdentifiableInterface
*/
private $target;

/**
* @var int
*
* @since Property available since Release 1.2.0
*/
private $port;

/**
* @param int|string $id
* @param string $target
* @param string $path
* @param string $host
* @param string $scheme
* @param int $port
*/
public function __construct($id, $target, $path, $host, $scheme)
public function __construct($id, $target, $path, $host, $scheme, $port)
{
$this->id = $id;
$this->target = $target;
$this->path = rtrim($path, '/');
$this->host = $host;
$this->scheme = $scheme;

if ($scheme === null) {
$this->scheme = 'http';
} else {
$this->scheme = $scheme;
}

if ($port === null) {
if ($this->scheme == 'http') {
$this->port = 80;
} elseif ($this->scheme == 'https') {
$this->port = 443;
}
} else {
$this->port = $port;
}
}

/**
Expand All @@ -69,7 +92,7 @@ public function getHost()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*
* @return int|string
*
Expand Down Expand Up @@ -103,4 +126,12 @@ public function getTarget()
{
return $this->target;
}

/**
* @return int
*/
public function getPort()
{
return $this->port;
}
}
12 changes: 6 additions & 6 deletions src/ProxyUrl/ProxyUrlCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProxyUrlCollection implements EntityCollectionInterface
private $proxyUrls = array();

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function add(EntityInterface $entity)
{
Expand All @@ -33,23 +33,23 @@ public function add(EntityInterface $entity)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function count()
{
return count($this->proxyUrls);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getIterator()
{
return new \ArrayIterator($this->proxyUrls);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function get($key)
{
Expand All @@ -61,15 +61,15 @@ public function get($key)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function remove(EntityInterface $entity)
{
assert($entity instanceof ProxyUrl);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function toArray()
{
Expand Down
11 changes: 4 additions & 7 deletions src/ProxyUrl/ProxyUrlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class ProxyUrlFactory implements ServiceInterface
*/
public function create($proxyUrlId, $path, $proxyUrl)
{
list($proxyUrlPath, $proxyUrlHost, $proxyUrlScheme) = static::parseUrl($proxyUrl);
list($proxyUrlPath, $proxyUrlHost, $proxyUrlScheme, $proxyUrlPort) = static::parseUrl($proxyUrl);

return new ProxyUrl($proxyUrlId, $path, $proxyUrlPath, $proxyUrlHost, $proxyUrlScheme);
return new ProxyUrl($proxyUrlId, $path, $proxyUrlPath, $proxyUrlHost, $proxyUrlScheme, $proxyUrlPort);
}

/**
Expand All @@ -46,13 +46,10 @@ public static function parseUrl($url)
throw new \UnexpectedValueException(sprintf('The proxy URL "%s" is malformed.', $url));
}

if (array_key_exists('port', $components)) {
throw new \UnexpectedValueException(sprintf('The proxy URL "%s" cannot contain port number.', $url));
}

$path = array_key_exists('path', $components) ? $components['path'] : null;
$host = array_key_exists('host', $components) ? $components['host'] : null;
$scheme = array_key_exists('scheme', $components) ? $components['scheme'] : null;
$port = array_key_exists('port', $components) ? $components['port'] : null;

if (strpos($path, '//') === 0) {
$endOfHostPosition = strpos($path, '/', 2);
Expand All @@ -67,6 +64,6 @@ public static function parseUrl($url)
}
}

return array($path, $host, $scheme);
return array($path, $host, $scheme, $port);
}
}
2 changes: 1 addition & 1 deletion src/Templating/ProxyAssetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ProxyAssetExtension extends AssetExtension
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null)
{
Expand Down
9 changes: 6 additions & 3 deletions tests/Functional/UrlRewritingInControllersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class UrlRewritingInControllersTest extends WebTestCase
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function setUp()
{
Expand All @@ -34,7 +34,7 @@ protected function setUp()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function tearDown()
{
Expand All @@ -44,7 +44,7 @@ protected function tearDown()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected static function createKernel(array $options = array())
{
Expand Down Expand Up @@ -77,6 +77,9 @@ public function rewriteUrlInGenerateUrlData()
array('https://example.com/foo/bar/', UrlGeneratorInterface::ABSOLUTE_PATH, '/foo/bar/url-rewriting-in-controllers/'),
array('https://example.com/foo/bar/', UrlGeneratorInterface::ABSOLUTE_URL, 'https://example.com/foo/bar/url-rewriting-in-controllers/'),
array('https://example.com/foo/bar/', UrlGeneratorInterface::NETWORK_PATH, '//example.com/foo/bar/url-rewriting-in-controllers/'),
array('http://example.com:8180/foo/bar/', UrlGeneratorInterface::ABSOLUTE_PATH, '/foo/bar/url-rewriting-in-controllers/'),
array('http://example.com:8180/foo/bar/', UrlGeneratorInterface::ABSOLUTE_URL, 'http://example.com:8180/foo/bar/url-rewriting-in-controllers/'),
array('http://example.com:8180/foo/bar/', UrlGeneratorInterface::NETWORK_PATH, '//example.com:8180/foo/bar/url-rewriting-in-controllers/'),
);
}

Expand Down
11 changes: 7 additions & 4 deletions tests/Functional/UrlRewritingInTemplatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class UrlRewritingInTemplatesTest extends WebTestCase
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function setUp()
{
Expand All @@ -34,7 +33,7 @@ protected function setUp()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function tearDown()
{
Expand All @@ -44,7 +43,7 @@ protected function tearDown()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected static function createKernel(array $options = array())
{
Expand Down Expand Up @@ -75,6 +74,10 @@ public function rewriteUrlInAssetData()
array('http://example.com/foo/bar/', true, 'http://example.com/foo/bar/bundles/test/foo.png'),
array('https://example.com/foo/bar/', false, '/foo/bar/bundles/test/foo.png'),
array('https://example.com/foo/bar/', true, 'https://example.com/foo/bar/bundles/test/foo.png'),
array('http://example.com:8180/foo/bar/', false, '/foo/bar/bundles/test/foo.png'),
array('http://example.com:8180/foo/bar/', true, 'http://example.com:8180/foo/bar/bundles/test/foo.png'),
array('https://example.com:8180/foo/bar/', false, '/foo/bar/bundles/test/foo.png'),
array('https://example.com:8180/foo/bar/', true, 'https://example.com:8180/foo/bar/bundles/test/foo.png'),
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AppKernel extends Kernel
private static $numberOfInitializations = 0;

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function registerBundles()
{
Expand All @@ -39,7 +39,7 @@ public function registerBundles()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
Expand All @@ -59,15 +59,15 @@ public function setConfig(\Closure $config)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getContainerClass()
{
return parent::getContainerClass().static::$numberOfInitializations;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function initializeContainer()
{
Expand Down