Example #1
0
 /**
  * Test if this URL matches all available parts of a given URL
  *
  * @param Url $url Comparison URL
  * @return bool This URL matches all available parts of the given URL
  */
 public function matches(Url $url)
 {
     // Test the scheme
     $urlScheme = $url->getScheme();
     if ($urlScheme !== null && $this->getScheme() !== $urlScheme) {
         return false;
     }
     // Test the user
     $urlUser = $url->getUser();
     if ($urlUser !== null && $this->getUser() !== $urlUser) {
         return false;
     }
     // Test the password
     $urlPassword = $url->getPassword();
     if ($urlPassword !== null && $this->getPassword() !== $urlPassword) {
         return false;
     }
     // Test the host
     $urlHost = $url->getHost();
     if ($urlHost !== null && $this->getHost() !== $urlHost) {
         return false;
     }
     // Test the port
     $urlPort = $url->getPort();
     if ($urlPort !== null && $this->getPort() !== $urlPort) {
         return false;
     }
     // Test the path
     $urlPath = $url->getPath();
     if ($urlPath !== null && $this->getPath() !== $urlPath) {
         return false;
     }
     // Test the query
     $urlQuery = $url->getQuery();
     if (serialize($this->getQuery()) !== serialize($urlQuery)) {
         return false;
     }
     // Test the fragment
     $urlFragment = $url->getFragment();
     if ($urlFragment !== null && $this->getFragment() !== $urlFragment) {
         return false;
     }
     return true;
 }