eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest::fromUrl PHP Method

fromUrl() public static method

Constructs a SimplifiedRequest object from a standard URL (http://www.example.com/foo/bar?queryParam=value).
public static fromUrl ( string $url ) : SimplifiedRequest
$url string
return SimplifiedRequest
    public static function fromUrl($url)
    {
        $elements = parse_url($url);
        $elements['pathinfo'] = isset($elements['path']) ? $elements['path'] : '';
        if (isset($elements['query'])) {
            parse_str($elements['query'], $queryParams);
            $elements['queryParams'] = $queryParams;
        }
        // Remove unwanted keys returned by parse_url() so that we don't have them as properties.
        unset($elements['path'], $elements['query'], $elements['user'], $elements['pass'], $elements['fragment']);
        return new static($elements);
    }

Usage Example

 public function testAnalyseLink()
 {
     $siteAccessURI = '/footestbar';
     $semanticURI = '/something/hoho';
     $matcher = new URITextMatcher(array('prefix' => 'foo', 'suffix' => 'bar'));
     $matcher->setRequest(SimplifiedRequest::fromUrl('http://phoenix-rises.fm/footestbar/blabla'));
     $this->assertSame($siteAccessURI . $semanticURI, $matcher->analyseLink($semanticURI));
 }
All Usage Examples Of eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest::fromUrl