Phly\Http\Uri::withUserInfo PHP Method

withUserInfo() public method

public withUserInfo ( $user, $password = null )
    public function withUserInfo($user, $password = null)
    {
        $info = $user;
        if ($password) {
            $info .= ':' . $password;
        }
        if ($info === $this->userInfo) {
            // Do nothing if no change was made.
            return clone $this;
        }
        $new = clone $this;
        $new->userInfo = $info;
        return $new;
    }

Usage Example

Example #1
0
 public function testWithUserInfoReturnsNewInstanceWithProvidedUserAndPassword()
 {
     $uri = new Uri('https://*****:*****@local.example.com:3001/foo?bar=baz#quz');
     $new = $uri->withUserInfo('matthew', 'zf2');
     $this->assertNotSame($uri, $new);
     $this->assertEquals('matthew:zf2', $new->getUserInfo());
     $this->assertEquals('https://*****:*****@local.example.com:3001/foo?bar=baz#quz', (string) $new);
 }
All Usage Examples Of Phly\Http\Uri::withUserInfo