Phly\Http\Uri::withPath PHP Method

withPath() public method

public withPath ( $path )
    public function withPath($path)
    {
        if (!is_string($path)) {
            throw new InvalidArgumentException('Invalid path provided; must be a string');
        }
        if (strpos($path, '?') !== false) {
            throw new InvalidArgumentException('Invalid path provided; must not contain a query string');
        }
        if (strpos($path, '#') !== false) {
            throw new InvalidArgumentException('Invalid path provided; must not contain a URI fragment');
        }
        $path = $this->filterPath($path);
        if ($path === $this->path) {
            // Do nothing if no change was made.
            return clone $this;
        }
        $new = clone $this;
        $new->path = $path;
        return $new;
    }

Usage Example

示例#1
0
 /**
  * @group 48
  */
 public function testWithPathReturnsSameInstanceWhenPathDoesNotChange()
 {
     $uri = new Uri('http://example.com/test/path');
     $test = $uri->withPath('/test/path');
     $this->assertSame($uri, $test);
 }
All Usage Examples Of Phly\Http\Uri::withPath