-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a ViewParameters ResponseTagger
Tags the response with any Repository Value Object added to the response.
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
spec/ResponseTagger/Delegator/ViewParametersTaggerSpec.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,49 @@ | ||
<?php | ||
|
||
namespace spec\EzSystems\PlatformHttpCacheBundle\ResponseTagger\Delegator; | ||
|
||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
use eZ\Publish\Core\MVC\Symfony\View\View; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseConfigurator\ResponseCacheConfigurator; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseTagger\Delegator\ViewParametersTagger; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use stdClass; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ViewParametersTaggerSpec extends ObjectBehavior | ||
{ | ||
function let(ResponseTagger $dispatcherTagger) | ||
{ | ||
$this->beConstructedWith($dispatcherTagger); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ViewParametersTagger::class); | ||
} | ||
|
||
function it_delegates_tagging_of_parameters_that_are_value_objects( | ||
ResponseCacheConfigurator $configurator, | ||
Response $response, | ||
ResponseTagger $dispatcherTagger, | ||
View $view, | ||
ValueObject $someValueObject, | ||
stdClass $someObject | ||
) { | ||
$view->getParameters()->willReturn([ | ||
'value_object' => $someValueObject, | ||
'object' => $someObject, | ||
'string' => 'some_string', | ||
'array' => ['a', 'b', 'c'], | ||
]); | ||
|
||
$this->tag($configurator, $response, $view); | ||
|
||
$dispatcherTagger->tag($configurator, $response, $someValueObject)->shouldHaveBeenCalled(); | ||
$dispatcherTagger->tag($configurator, $response, $someObject)->shouldNotHaveBeenCalled(); | ||
$dispatcherTagger->tag($configurator, $response, 'some_string')->shouldNotHaveBeenCalled(); | ||
$dispatcherTagger->tag($configurator, $response, ['a', 'b', 'c'])->shouldNotHaveBeenCalled(); | ||
} | ||
} |
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
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,42 @@ | ||
<?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 EzSystems\PlatformHttpCacheBundle\ResponseTagger\Delegator; | ||
|
||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
use eZ\Publish\Core\MVC\Symfony\View\View; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseConfigurator\ResponseCacheConfigurator; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ViewParametersTagger implements ResponseTagger | ||
{ | ||
/** | ||
* @var \EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger | ||
*/ | ||
private $dispatcherTagger; | ||
|
||
public function __construct(ResponseTagger $dispatcherTagger) | ||
{ | ||
$this->dispatcherTagger = $dispatcherTagger; | ||
} | ||
|
||
public function tag(ResponseCacheConfigurator $configurator, Response $response, $view) | ||
{ | ||
if (!$view instanceof View) { | ||
return $this; | ||
} | ||
|
||
foreach ($view->getParameters() as $parameter) { | ||
if (!$parameter instanceof ValueObject) { | ||
continue; | ||
} | ||
|
||
$this->dispatcherTagger->tag($configurator, $response, $parameter); | ||
} | ||
|
||
return $this; | ||
} | ||
} |