eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIElement::reverseMatch PHP Méthode

reverseMatch() public méthode

Limitation: If the element number is > 1, we cannot predict how URI segments are expected to be built. So we expect "_" will be reversed to "/" e.g. foo_bar => foo/bar with elementNumber == 2 Hence if number of elements is different than the element number, we report as non matched.
public reverseMatch ( string $siteAccessName ) : URIElement | null
$siteAccessName string
Résultat URIElement | null
    public function reverseMatch($siteAccessName)
    {
        $elements = $this->elementNumber > 1 ? explode('_', $siteAccessName) : array($siteAccessName);
        if (count($elements) !== $this->elementNumber) {
            return null;
        }
        $pathinfo = '/' . implode('/', $elements) . '/' . ltrim($this->request->pathinfo, '/');
        $this->request->setPathinfo($pathinfo);
        return $this;
    }

Usage Example

 /**
  * @dataProvider reverseMatchProvider
  */
 public function testReverseMatch($siteAccessName, $originalPathinfo)
 {
     $matcher = new URIElementMatcher(1);
     $matcher->setRequest(new SimplifiedRequest(array('pathinfo' => $originalPathinfo)));
     $result = $matcher->reverseMatch($siteAccessName);
     $this->assertInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher\\URIElement', $result);
     $this->assertSame("/{$siteAccessName}{$originalPathinfo}", $result->getRequest()->pathinfo);
     $this->assertSame("/{$siteAccessName}/some/linked/uri", $result->analyseLink('/some/linked/uri'));
     $this->assertSame('/foo/bar/baz', $result->analyseURI("/{$siteAccessName}/foo/bar/baz"));
 }
All Usage Examples Of eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIElement::reverseMatch