eZ\Publish\Core\REST\Common\RequestParser\Pattern::parse PHP Method

parse() public method

Parse URL and return the IDs contained in the URL.
public parse ( string $url ) : array
$url string
return array
    public function parse($url)
    {
        foreach ($this->map as $pattern) {
            $pattern = $this->compile($pattern);
            if (preg_match($pattern, $url, $match)) {
                // remove numeric keys
                foreach ($match as $key => $value) {
                    if (is_numeric($key)) {
                        unset($match[$key]);
                    }
                }
                return $match;
            }
        }
        throw new Exceptions\InvalidArgumentException("URL '{$url}' did not match any route.");
    }

Usage Example

 /**
  * Test parsing when pattern does not match the end of the URL
  *
  * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  * @expectedExceptionMessage URL '/foo/23/bar' did not match any route.
  */
 public function testPatternDoesNotMatchTrailing()
 {
     $urlHandler = new Common\RequestParser\Pattern(array('pattern' => '/foo/{foo}'));
     $urlHandler->parse('/foo/23/bar');
 }