eZ\Bundle\EzPublishCoreBundle\Matcher\BlockMatcherFactory::setSiteAccess PHP Method

setSiteAccess() public method

Changes internal configuration to use the one for passed SiteAccess.
public setSiteAccess ( SiteAccess $siteAccess = null )
$siteAccess eZ\Publish\Core\MVC\Symfony\SiteAccess
    public function setSiteAccess(SiteAccess $siteAccess = null)
    {
        if ($siteAccess === null) {
            return;
        }
        $this->matchConfig = $this->configResolver->getParameter('block_view', 'ezsettings', $siteAccess->name);
    }

Usage Example

 public function testSetSiteAccess()
 {
     $matcherServiceIdentifier = 'my.matcher.service';
     $resolverMock = $this->getMock('eZ\\Publish\\Core\\MVC\\ConfigResolverInterface');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $siteAccessName = 'siteaccess_name';
     $updatedMatchConfig = array('full' => array('matchRule2' => array('template' => 'my_other_template.html.twig', 'match' => array('foo' => array('bar')))));
     $resolverMock->expects($this->atLeastOnce())->method('getParameter')->will($this->returnValueMap(array(array('block_view', null, null, array('full' => array('matchRule' => array('template' => 'my_template.html.twig', 'match' => array($matcherServiceIdentifier => 'someValue'))))), array('block_view', 'ezsettings', $siteAccessName, $updatedMatchConfig))));
     $matcherFactory = new BlockMatcherFactory($resolverMock, $this->getMock('eZ\\Publish\\API\\Repository\\Repository'));
     $matcherFactory->setContainer($container);
     $matcherFactory->setSiteAccess(new SiteAccess($siteAccessName));
     $refObj = new \ReflectionObject($matcherFactory);
     $refProp = $refObj->getProperty('matchConfig');
     $refProp->setAccessible(true);
     $this->assertSame($updatedMatchConfig, $refProp->getValue($matcherFactory));
 }