Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix EZP-22597: Use composition on extended FragmentRenderers
- Loading branch information
1 parent
9a0c628
commit 3c97f85
Showing
8 changed files
with
170 additions
and
182 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
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
89 changes: 89 additions & 0 deletions
89
eZ/Bundle/EzPublishCoreBundle/Fragment/DecoratedFragmentRenderer.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,89 @@ | ||
<?php | ||
/** | ||
* File containing the DecoratedFragmentRenderer class. | ||
* | ||
* @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved. | ||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 | ||
* @version //autogentag// | ||
*/ | ||
|
||
namespace eZ\Bundle\EzPublishCoreBundle\Fragment; | ||
|
||
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware; | ||
use eZ\Publish\Core\MVC\Symfony\SiteAccess; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Controller\ControllerReference; | ||
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; | ||
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer; | ||
|
||
class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware | ||
{ | ||
/** | ||
* @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface | ||
*/ | ||
private $innerRenderer; | ||
|
||
/** | ||
* @var \eZ\Publish\Core\MVC\Symfony\SiteAccess | ||
*/ | ||
private $siteAccess; | ||
|
||
public function __construct( FragmentRendererInterface $innerRenderer ) | ||
{ | ||
$this->innerRenderer = $innerRenderer; | ||
} | ||
|
||
/** | ||
* @param \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteAccess | ||
*/ | ||
public function setSiteAccess( SiteAccess $siteAccess = null ) | ||
{ | ||
$this->siteAccess = $siteAccess; | ||
} | ||
|
||
public function setFragmentPath( $path ) | ||
{ | ||
if ( !$this->innerRenderer instanceof RoutableFragmentRenderer ) | ||
{ | ||
return null; | ||
} | ||
|
||
if ( $this->siteAccess && $this->siteAccess->matcher instanceof SiteAccess\URILexer ) | ||
{ | ||
$path = $this->siteAccess->matcher->analyseLink( $path ); | ||
} | ||
|
||
$this->innerRenderer->setFragmentPath( $path ); | ||
} | ||
|
||
/** | ||
* Renders a URI and returns the Response content. | ||
* | ||
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance | ||
* @param Request $request A Request instance | ||
* @param array $options An array of options | ||
* | ||
* @return Response A Response instance | ||
*/ | ||
public function render( $uri, Request $request, array $options = array() ) | ||
{ | ||
if ( $uri instanceof ControllerReference && $request->attributes->has( 'siteaccess' ) ) | ||
{ | ||
// Serialize the siteaccess to get it back after. | ||
// @see eZ\Publish\Core\MVC\Symfony\EventListener\SiteAccessMatchListener | ||
$uri->attributes['serialized_siteaccess'] = serialize( $request->attributes->get( 'siteaccess' ) ); | ||
} | ||
|
||
return $this->innerRenderer->render( $uri, $request, $options ); | ||
} | ||
|
||
/** | ||
* Gets the name of the strategy. | ||
* | ||
* @return string The strategy name | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->innerRenderer->getName(); | ||
} | ||
} |
58 changes: 0 additions & 58 deletions
58
eZ/Bundle/EzPublishCoreBundle/Fragment/EsiFragmentRenderer.php
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
eZ/Bundle/EzPublishCoreBundle/Fragment/FragmentUriGenerator.php
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
eZ/Bundle/EzPublishCoreBundle/Fragment/HincludeFragmentRenderer.php
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
Oops, something went wrong.