Phly\Http\Uri::withPort PHP Метод

withPort() публичный Метод

public withPort ( $port )
    public function withPort($port)
    {
        if (!(is_integer($port) || is_string($port) && is_numeric($port))) {
            throw new InvalidArgumentException(sprintf('Invalid port "%s" specified; must be an integer or integer string', is_object($port) ? get_class($port) : gettype($port)));
        }
        $port = (int) $port;
        if ($port === $this->port) {
            // Do nothing if no change was made.
            return clone $this;
        }
        if ($port < 1 || $port > 65535) {
            throw new InvalidArgumentException(sprintf('Invalid port "%d" specified; must be a valid TCP/UDP port', $port));
        }
        $new = clone $this;
        $new->port = $port;
        return $new;
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider invalidPorts
  */
 public function testWithPortRaisesExceptionForInvalidPorts($port)
 {
     $uri = new Uri('https://*****:*****@local.example.com:3001/foo?bar=baz#quz');
     $this->setExpectedException('InvalidArgumentException', 'Invalid port');
     $new = $uri->withPort($port);
 }
All Usage Examples Of Phly\Http\Uri::withPort