SimplePie_IRI::set_scheme PHP Method

set_scheme() public method

Set the scheme. Returns true on success, false on failure (if there are any invalid characters).
public set_scheme ( string $scheme ) : boolean
$scheme string
return boolean
    function set_scheme($scheme)
    {
        if ($scheme === null || $scheme === '') {
            $this->scheme = null;
        } else {
            $len = strlen($scheme);
            switch (true) {
                case $len > 1:
                    if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.', 1)) {
                        $this->scheme = null;
                        $this->valid[__FUNCTION__] = false;
                        return false;
                    }
                case $len > 0:
                    if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 0, 1)) {
                        $this->scheme = null;
                        $this->valid[__FUNCTION__] = false;
                        return false;
                    }
            }
            $this->scheme = strtolower($scheme);
        }
        $this->valid[__FUNCTION__] = true;
        return true;
    }

Usage Example

Esempio n. 1
0
 public static function absolutize($base, $relative)
 {
     $relative = (string) $relative;
     if ($relative !== '') {
         $relative = new SimplePie_IRI($relative);
         if ($relative->get_scheme() !== null) {
             $target = $relative;
         } elseif ($base->get_iri() !== null) {
             if ($relative->get_authority() !== null) {
                 $target = $relative;
                 $target->set_scheme($base->get_scheme());
             } else {
                 $target = new SimplePie_IRI('');
                 $target->set_scheme($base->get_scheme());
                 $target->set_userinfo($base->get_userinfo());
                 $target->set_host($base->get_host());
                 $target->set_port($base->get_port());
                 if ($relative->get_path() !== null) {
                     if (strpos($relative->get_path(), '/') === 0) {
                         $target->set_path($relative->get_path());
                     } elseif (($base->get_userinfo() !== null || $base->get_host() !== null || $base->get_port() !== null) && $base->get_path() === null) {
                         $target->set_path('/' . $relative->get_path());
                     } elseif (($last_segment = strrpos($base->get_path(), '/')) !== false) {
                         $target->set_path(substr($base->get_path(), 0, $last_segment + 1) . $relative->get_path());
                     } else {
                         $target->set_path($relative->get_path());
                     }
                     $target->set_query($relative->get_query());
                 } else {
                     $target->set_path($base->get_path());
                     if ($relative->get_query() !== null) {
                         $target->set_query($relative->get_query());
                     } elseif ($base->get_query() !== null) {
                         $target->set_query($base->get_query());
                     }
                 }
             }
             $target->set_fragment($relative->get_fragment());
         } else {
             $target = $relative;
         }
     } else {
         $target = $base;
     }
     return $target;
 }
All Usage Examples Of SimplePie_IRI::set_scheme