-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
313 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
eZ/Bundle/EzPublishCoreBundle/Imagine/Cache/Resolver/RelativeResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver; | ||
|
||
use Liip\ImagineBundle\Binary\BinaryInterface; | ||
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; | ||
|
||
class RelativeResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface | ||
*/ | ||
private $resolver; | ||
|
||
/** | ||
* @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver | ||
*/ | ||
public function __construct(ResolverInterface $resolver) | ||
{ | ||
$this->resolver = $resolver; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isStored($path, $filter) | ||
{ | ||
return $this->resolver->isStored($path, $filter); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve($path, $filter) | ||
{ | ||
return $this->rewriteUrl($this->resolver->resolve($path, $filter)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function store(BinaryInterface $binary, $path, $filter) | ||
{ | ||
return $this->resolver->store($binary, $path, $filter); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove(array $paths, array $filters) | ||
{ | ||
return $this->resolver->remove($paths, $filters); | ||
} | ||
|
||
/** | ||
* Returns relative image path. | ||
* | ||
* @param $url string | ||
* @return string | ||
*/ | ||
protected function rewriteUrl($url) | ||
{ | ||
return parse_url($url, PHP_URL_PATH); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
eZ/Bundle/EzPublishCoreBundle/Imagine/Cache/ResolverFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache; | ||
|
||
use eZ\Publish\Core\MVC\ConfigResolverInterface; | ||
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; | ||
|
||
class ResolverFactory | ||
{ | ||
/** | ||
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface | ||
*/ | ||
private $configResolver; | ||
|
||
/** | ||
* @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface | ||
*/ | ||
private $resolver; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $resolverDecoratorClass; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $proxyResolverClass; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $relativeResolverClass; | ||
|
||
/** | ||
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver | ||
* @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver | ||
* @param string $proxyResolverClass | ||
* @param string $relativeResolverClass | ||
*/ | ||
public function __construct( | ||
ConfigResolverInterface $configResolver, | ||
ResolverInterface $resolver, | ||
$proxyResolverClass, | ||
$relativeResolverClass | ||
) { | ||
$this->configResolver = $configResolver; | ||
$this->resolver = $resolver; | ||
$this->proxyResolverClass = $proxyResolverClass; | ||
$this->relativeResolverClass = $relativeResolverClass; | ||
} | ||
|
||
/** | ||
* @return \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface | ||
*/ | ||
public function createCacheResolver() | ||
{ | ||
$imageHost = $this->configResolver->hasParameter('image_host') ? | ||
$this->configResolver->getParameter('image_host') : | ||
''; | ||
|
||
if ($imageHost === '') { | ||
return $this->resolver; | ||
} | ||
|
||
if ($imageHost === '/') { | ||
$this->resolverDecoratorClass = $this->relativeResolverClass; | ||
} else { | ||
$this->resolverDecoratorClass = $this->proxyResolverClass; | ||
} | ||
|
||
return new $this->resolverDecoratorClass($this->resolver, [$imageHost]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
eZ/Bundle/EzPublishCoreBundle/Tests/Imagine/Cache/Resolver/RelativeResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Imagine\Cache\Resolver; | ||
|
||
use eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver\RelativeResolver; | ||
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RelativeResolverTest extends TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface | ||
*/ | ||
private $liipResolver; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->liipResolver = $this->getMockBuilder(ResolverInterface::class)->getMock(); | ||
} | ||
|
||
public function testResolve() | ||
{ | ||
$resolver = new RelativeResolver($this->liipResolver); | ||
|
||
$path = '7/4/2/0/247-1-eng-GB/test.png'; | ||
$filter = 'big'; | ||
|
||
$absolute = 'http://ez.no/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png'; | ||
$expected = '/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png'; | ||
|
||
$this->liipResolver | ||
->expects($this->once()) | ||
->method('resolve') | ||
->with($path, $filter) | ||
->willReturn($absolute); | ||
|
||
$this->assertSame($expected, $resolver->resolve($path, $filter)); | ||
} | ||
} |
Oops, something went wrong.