Beispiel #1
0
 /**
  * @param string $name
  * @return string|URLSearchParams
  */
 public function __get($name)
 {
     switch ($name) {
         case 'href':
             $value = $this->url->serializeURL();
             break;
         case 'origin':
             $value = self::unicodeSerialiseOrigin($this->url->getOrigin());
             break;
         case 'protocol':
             $value = $this->url->scheme . ':';
             break;
         case 'username':
             $value = $this->url->username;
             break;
         case 'password':
             $value = is_null($this->url->password) ? '' : $this->url->password;
             break;
         case 'host':
             $value = is_null($this->url->host) ? '' : lib\HostProcessing::serializeHost($this->url->host) . (is_null($this->url->port) ? '' : ':' . $this->url->port);
             break;
         case 'hostname':
             $value = is_null($this->url->host) ? '' : lib\HostProcessing::serializeHost($this->url->host);
             break;
         case 'port':
             $value = is_null($this->url->port) ? '' : (string) $this->url->port;
             break;
         case 'pathname':
             $value = $this->url->nonRelativeFlag ? $this->url->path[0] : '/' . implode('/', $this->url->path);
             break;
         case 'search':
             $value = is_null($this->url->query) || $this->url->query === '' ? '' : '?' . $this->url->query;
             break;
         case 'searchParams':
             $value = $this->queryObject;
             break;
         case 'hash':
             $value = is_null($this->url->fragment) || $this->url->fragment === '' ? '' : '#' . $this->url->fragment;
             break;
         default:
             TypeHinter::triggerVisibilityErrorOrUndefinedNotice();
             $value = null;
     }
     return $value;
 }
Beispiel #2
0
 /**
  * If there are any name-value pairs whose name is name, set the value of the first such name-value pair to value and remove the others.
  * Otherwise, append a new name-value pair whose name is name and value is value, to the list of name-value pairs.
  * @link https://url.spec.whatwg.org/#dom-urlsearchparams-setname-value URL Standard
  * @param string $name A USVString.
  * @param string $value A USVString.
  */
 public function set($name, $value)
 {
     $nameString = TypeHinter::to('USVString', $name, 0);
     $valueString = TypeHinter::to('USVString', $value, 1);
     $already = false;
     foreach ($this->list as $key => &$pair) {
         if ($pair[0] === $nameString) {
             if ($already) {
                 unset($this->list[$key]);
             } else {
                 $pair[1] = $valueString;
                 $already = true;
             }
         }
     }
     unset($pair);
     if ($already) {
         $this->list = array_values($this->list);
         array_splice($this->list, 0, count($this->list), $this->list);
     } else {
         $this->list[] = [$nameString, $valueString];
     }
     $this->update();
 }