You are here

public function Uri::isValid in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Uri.php \Zend\Feed\Uri::isValid()

Is the URI valid?

Return value

bool

File

vendor/zendframework/zend-feed/src/Uri.php, line 137

Class

Uri

Namespace

Zend\Feed

Code

public function isValid() {
  if (false === $this->valid) {
    return false;
  }
  if ($this->scheme && !in_array($this->scheme, $this->validSchemes)) {
    return false;
  }
  if ($this->host) {
    if ($this->path && substr($this->path, 0, 1) != '/') {
      return false;
    }
    return true;
  }

  // no host, but user and/or port... what?
  if ($this->user || $this->port) {
    return false;
  }
  if ($this->path) {

    // Check path-only (no host) URI
    if (substr($this->path, 0, 2) == '//') {
      return false;
    }
    return true;
  }
  if (!($this->query || $this->fragment)) {

    // No host, path, query or fragment - this is not a valid URI
    return false;
  }
  return true;
}