Esempio n. 1
0
 /**
  * @param string $name
  * @param string $value
  * @throws TypeError
  */
 public function __set($name, $value)
 {
     if (in_array($name, ['href', 'protocol', 'username', 'password', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'])) {
         $input = TypeHinter::to('USVString', $value);
     }
     switch ($name) {
         case 'href':
             $parsedURL = lib\URL::parseBasicURL($input);
             if (!$parsedURL) {
                 throw new TypeError(sprintf('<%s> is not a valid URL', $input));
             }
             $this->url = $parsedURL;
             break;
         case 'protocol':
             lib\URL::parseBasicURL($input . ':', null, null, ['url' => $this->url, 'state override' => 'scheme start state']);
             break;
         case 'username':
             if (!is_null($this->url->host) && !$this->url->nonRelativeFlag) {
                 $this->url->setUsername($input);
             }
             break;
         case 'password':
             if (!is_null($this->url->host) && !$this->url->nonRelativeFlag) {
                 $this->url->setPassword($input);
             }
             break;
         case 'host':
             if (!$this->url->nonRelativeFlag) {
                 lib\URL::parseBasicURL($input, null, null, ['url' => $this->url, 'state override' => 'host state']);
             }
             break;
         case 'hostname':
             if ($this->url && !$this->url->nonRelativeFlag) {
                 lib\URL::parseBasicURL($input, null, null, ['url' => $this->url, 'state override' => 'hostname state']);
             }
             break;
         case 'port':
             if (!is_null($this->url->host) && !$this->url->nonRelativeFlag && $this->url->scheme !== 'file') {
                 lib\URL::parseBasicURL($input, null, null, ['url' => $this->url, 'state override' => 'port state']);
             }
             break;
         case 'pathname':
             if (!$this->url->nonRelativeFlag) {
                 $this->url->path = [];
                 lib\URL::parseBasicURL($input, null, null, ['url' => $this->url, 'state override' => 'path start state']);
             }
             break;
         case 'search':
             if ($input === '') {
                 $this->url->query = null;
                 $list = [];
             } else {
                 $query = $input[0] === '?' ? substr($input, 1) : $input;
                 $this->url->query = '';
                 lib\URL::parseBasicURL($query, null, null, ['url' => $this->url, 'state override' => 'query state']);
                 $list = lib\URLencoding::parseURLencodedString($query);
             }
             \Closure::bind(function ($list, $queryObject) {
                 array_splice($queryObject->list, 0, count($queryObject->list), $list);
             }, null, $this->queryObject)->__invoke($list, $this->queryObject);
             break;
         case 'hash':
             if ($this->url->scheme !== 'javascript') {
                 if ($input === '') {
                     $this->url->fragment = null;
                 } else {
                     $fragment = $input[0] === '#' ? substr($input, 1) : $input;
                     $this->url->fragment = '';
                     lib\URL::parseBasicURL($fragment, null, null, ['url' => $this->url, 'state override' => 'fragment state']);
                 }
             }
             break;
         case 'origin':
         case 'searchParams':
             TypeHinter::throwReadonlyException();
             break;
         default:
             TypeHinter::triggerVisibilityErrorOrDefineProperty();
     }
 }