eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Compound\LogicalAnd::reverseMatch PHP Method

reverseMatch() public method

public reverseMatch ( $siteAccessName )
    public function reverseMatch($siteAccessName)
    {
        foreach ($this->config as $i => $rule) {
            if ($rule['match'] === $siteAccessName) {
                $subMatchers = array();
                foreach ($this->matchersMap[$i] as $subMatcher) {
                    if (!$subMatcher instanceof VersatileMatcher) {
                        return null;
                    }
                    $reverseMatcher = $subMatcher->reverseMatch($siteAccessName);
                    if (!$reverseMatcher) {
                        return null;
                    }
                    $subMatchers[] = $subMatcher;
                }
                $this->setSubMatchers($subMatchers);
                return $this;
            }
        }
    }

Usage Example

 public function testReverseMatch()
 {
     $request = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\Routing\\SimplifiedRequest');
     $siteAccessName = 'fr_eng';
     $mapUriConfig = array('eng' => true);
     $mapHostConfig = array('fr.ezpublish.dev' => true);
     $compoundMatcher = new LogicalAnd(array(array('matchers' => array('Map\\URI' => $mapUriConfig, 'Map\\Host' => $mapHostConfig), 'match' => $siteAccessName)));
     $compoundMatcher->setRequest($request);
     $matcher1 = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher');
     $matcher2 = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher');
     $this->matcherBuilder->expects($this->exactly(2))->method('buildMatcher')->will($this->returnValueMap(array(array('Map\\URI', $mapUriConfig, $request, $matcher1), array('Map\\Host', $mapHostConfig, $request, $matcher2))));
     $reverseMatchedMatcher1 = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher');
     $matcher1->expects($this->once())->method('reverseMatch')->with($siteAccessName)->will($this->returnValue($reverseMatchedMatcher1));
     $reverseMatchedMatcher2 = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher');
     $matcher2->expects($this->once())->method('reverseMatch')->with($siteAccessName)->will($this->returnValue($reverseMatchedMatcher2));
     $compoundMatcher->setMatcherBuilder($this->matcherBuilder);
     $result = $compoundMatcher->reverseMatch($siteAccessName);
     $this->assertInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher\\Compound\\LogicalAnd', $result);
     foreach ($result->getSubMatchers() as $subMatcher) {
         $this->assertInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\VersatileMatcher', $subMatcher);
     }
 }