Exemple #1
0
 /**
  * @param string $uri       The uri to parse
  * @param bool   $normalize If true, uri will be normalized to a string
  *
  * @return array|string
  */
 public static function parse($uri, $normalize = false)
 {
     //  Don't parse empty uris
     if (empty($uri)) {
         return true;
     }
     //  Let PHP have a whack at it
     $_parts = parse_url($uri);
     //  Unparsable or missing host or path, we bail
     if (false === $_parts || !(isset($_parts['host']) || isset($_parts['path']))) {
         return false;
     }
     $_scheme = IfSet::get($_parts, 'scheme', Scalar::boolVal(IfSet::get($_SERVER, 'HTTPS')) ? 'https' : 'http');
     $_port = IfSet::get($_parts, 'port');
     $_host = IfSet::get($_parts, 'host');
     $_path = IfSet::get($_parts, 'path');
     //  Set ports to defaults for scheme if empty
     if (empty($_port)) {
         $_port = null;
         switch ($_parts['scheme']) {
             case 'http':
                 $_port = 80;
                 break;
             case 'https':
                 $_port = 443;
                 break;
         }
     }
     //  If standard port 80 or 443 and there is no port in uri, clear from parse...
     if (!empty($_port)) {
         if (empty($_host) || ($_port == 80 || $_port == 443) && false === strpos($uri, ':' . $_port)) {
             $_port = null;
         }
     }
     if (!empty($_path) && empty($_host)) {
         //	Special case, handle this generically later
         if ('null' == $_path) {
             return 'null';
         }
         $_host = $_path;
         $_path = null;
     }
     $_uri = ['scheme' => $_scheme, 'host' => $_host, 'port' => $_port];
     return $normalize ? static::normalize($_uri) : $_uri;
 }
Exemple #2
0
 /**
  * Returns the first non-empty argument or null if none found.
  * Allows for multiple nvl chains. Example:
  *
  *<code>
  *    if ( null !== Option::nvl( $x, $y, $z ) ) {
  *        //    none are null
  *    } else {
  *        //    One of them is null
  *    }
  *
  * IMPORTANT NOTE!
  * Since PHP evaluates the arguments before calling a function, this is NOT a short-circuit method.
  *
  * @return mixed
  */
 public static function nvl()
 {
     $_default = null;
     $_args = func_num_args();
     $_haystack = func_get_args();
     for ($_i = 0; $_i < $_args; $_i++) {
         if (null !== ($_default = IfSet::get($_haystack, $_i))) {
             break;
         }
     }
     return $_default;
 }