Webiny\Component\Rest\Response\Router::getUrl PHP Method

getUrl() public method

Returns the current url path.
public getUrl ( ) : string
return string
    public function getUrl()
    {
        if (empty($this->url)) {
            $url = $this->httpRequest()->getCurrentUrl(true)->getPath();
            // we need to have the trailing slash because of the match inside matchRequest
            // and also when matching the default method, we can do an incorrect match if we don't have the start and end slash
            $this->url = $this->str($url)->trimRight('/')->val() . '/';
        }
        return $this->url;
    }

Usage Example

Example #1
0
 public function testSetGetUrl()
 {
     $url = 'http://api.example.com/mock-api-class-router/';
     $r = new Router('ExampleApi', 'Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClassRouter', true, self::$cache);
     $r->setUrl($url);
     $this->assertSame('/mock-api-class-router/', $r->getUrl());
 }