eZ\Bundle\EzPublishCoreBundle\SiteAccess\MatcherBuilder::buildMatcher PHP Метод

buildMatcher() публичный Метод

If $matchingClass begins with "@", it will be considered as a service identifier and loaded with the service container.
public buildMatcher ( $matchingClass, $matchingConfiguration, SimplifiedRequest $request ) : eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher
$matchingClass
$matchingConfiguration
$request eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest
Результат eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher
    public function buildMatcher($matchingClass, $matchingConfiguration, SimplifiedRequest $request)
    {
        if ($matchingClass[0] === '@') {
            /** @var $matcher \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher */
            $matcher = $this->container->get(substr($matchingClass, 1));
            if (!$matcher instanceof Matcher) {
                throw new RuntimeException('A service based siteaccess matcher MUST implement ' . __NAMESPACE__ . '\\Matcher interface.');
            }
            $matcher->setMatchingConfiguration($matchingConfiguration);
            $matcher->setRequest($request);
            return $matcher;
        }
        return parent::buildMatcher($matchingClass, $matchingConfiguration, $request);
    }

Usage Example

 /**
  * @covers eZ\Bundle\EzPublishCoreBundle\SiteAccess\MatcherBuilder::__construct
  * @covers eZ\Bundle\EzPublishCoreBundle\SiteAccess\MatcherBuilder::buildMatcher
  */
 public function testBuildMatcherService()
 {
     $serviceId = 'foo';
     $matcher = $this->getMock('eZ\\Bundle\\EzPublishCoreBundle\\SiteAccess\\Matcher');
     $this->container->expects($this->once())->method('get')->with($serviceId)->will($this->returnValue($matcher));
     $matchingConfig = array('foo' => 'bar');
     $request = new SimplifiedRequest();
     $matcher->expects($this->once())->method('setMatchingConfiguration')->with($matchingConfig);
     $matcher->expects($this->once())->method('setRequest')->with($request);
     $matcherBuilder = new MatcherBuilder($this->container);
     $matcherBuilder->buildMatcher("@{$serviceId}", $matchingConfig, $request);
 }