Пример #1
0
 public static function load($name)
 {
     // echo __METHOD__."('$name')\n";
     self::$load_trace = debug_backtrace();
     $name = str_replace('\\', '/', $name);
     $pathInfo = pathinfo($name);
     // print_r($pathInfo); echo "\n";
     $namespace = $pathInfo['dirname'];
     $class = $pathInfo['filename'];
     if ($namespace == '.') {
         $namespace = '';
     } else {
         if ($namespace[0] == '/') {
             $namespace = substr($namespace, 1);
         }
     }
     if (strlen($namespace) > 1 || $namespace == '.') {
         $namespace .= '/';
     }
     // echo '$namespace: '.$namespace."<br>\n";
     // echo '$class: '.$class."<br>\n";
     $fixes = array('class', 'lib', 'inc');
     $extensions = array('.php');
     // , '.inc', '.php3' etc.
     $result = self::cache_check($name);
     if ($result === false) {
         $result = self::search($namespace, $class, $fixes, $extensions, $name);
     }
     if ($result === false) {
         $lowerClass = strtolower($class);
         if ($class != $lowerClass) {
             $result = self::search($namespace, $lowerClass, $fixes, $extensions, $name);
         }
     }
     if ($result === false) {
         $upperClass = strtoupper($class);
         if ($class != $upperClass) {
             $result = self::search($namespace, $upperClass, $fixes, $extensions, $name);
         }
     }
     if ($result === false) {
         $msg = "Unable to load \"{$name}\".\n";
         $msg .= Util::loop(self::$load_trace);
         // header('Content-Type: text/plain');
         // throw new ClassLoader_Exception($msg);
     } else {
         include $result;
     }
 }
Пример #2
0
 /**
  * Parse A URL into it's constituent parts
  *
  * @param	$url	The URL string to parse or true to use the current URL accessing the script.
  * @return	Array with all active info.
  */
 public function parseURL($url)
 {
     $result = array('uri' => '');
     $uri_re = '/^(([^:\\/?#]+):)?(\\/\\/([^\\/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?/';
     // echo '<pre>$_SERVER: '.print_r($_SERVER, true)."</pre>\n";
     preg_match($uri_re, $url, $matches);
     // echo '<pre>$matches: '.print_r($matches, true)."</pre>\n";
     if (isset($matches[2])) {
         $result['scheme'] = $matches[2];
     }
     // Parse Authority Section
     if (isset($matches[4])) {
         $result['authority'] = array();
         $result['authority']['full'] = null;
         $result['authority']['userinfo'] = array();
         $authority = $matches[4];
         // Check for UserInfo
         if (strpos($authority, '@') !== false) {
             $parts = explode('@', $authority);
             // Set Host
             $result['host'] = array_pop($parts);
             $result['authority']['host'] = $result['host'];
             // Prep UserInfo
             $userinfo = explode(':', implode('', $parts));
             // Parse Port
             if (strpos($result['host'], ':') !== false) {
                 $parts = explode(':', $result['host']);
                 $result['host'] = $parts[0];
                 $result['authority']['host'] = $parts[0];
                 $result['port'] = $parts[1];
                 $result['authority']['port'] = $parts[1];
             } else {
                 $result['port'] = '80';
                 $result['authority']['port'] = '80';
             }
             $userinfo_length = count($userinfo);
             // Set Full Authority Reference
             $result['authority']['full'] = $matches[4] . ':' . $result['port'];
             // Parse UserInfo
             if ($userinfo_length > 0) {
                 $result['authority']['userinfo']['full'] = implode(':', $userinfo);
                 $result['authority']['userinfo']['user'] = array_shift($userinfo);
                 if ($userinfo_length > 1) {
                     $result['authority']['userinfo']['pass'] = array_shift($userinfo);
                     if ($userinfo_length > 2) {
                         $result['authority']['userinfo']['data'] = $userinfo;
                     }
                 }
             } else {
                 unset($result['authority']['userinfo']);
             }
         } else {
             // Set Minimal Authority Info
             $result['authority']['full'] = $authority;
             $result['authority']['host'] = $authority;
             $result['host'] = $authority;
         }
     }
     if (!empty($result['authority']['full'])) {
         $this->authority = $result['authority']['full'];
     }
     if (!empty($result['host'])) {
         $this->host = $result['host'];
     }
     // Parse Path Info
     if (!empty($matches[5])) {
         $result['path'] = $matches[5];
         $tmp = $this->parseMatrix($result['path']);
         if (!empty($tmp['matrix'])) {
             $result['path'] = $tmp['path'];
             $result['matrix'] = $tmp['matrix'];
             $this->matrix = $result['matrix'];
         }
         $path = array();
         $path['full'] = $result['path'];
         $path['segments'] = explode('/', $path['full']);
         array_shift($path['segments']);
         $result['path'] = $path;
         $this->path = $path['full'];
     }
     // Parse Query String
     if (isset($matches[7])) {
         parse_str($matches[7], $result['query']);
         $result['query'] = array_map('urldecode', $result['query']);
         $this->query = $result['query'];
     }
     // Set Fragment if Available
     if (isset($matches[9])) {
         $result['fragment'] = $matches[9];
         $this->fragment = $result['fragment'];
     }
     // Set Normalized URI Value
     $result['uri'] = $result['scheme'] . '://' . $result['host'];
     if (!empty($result['port']) && $result['port'] !== '80') {
         $result['uri'] .= ':' . $result['port'];
     }
     if (!empty($result['path'])) {
         $result['uri'] .= $result['path'];
     }
     if (!empty($matches[7])) {
         $result['uri'] .= '?' . $matches[7];
     }
     if (!empty($result['fragment'])) {
         $result['uri'] .= '#' . $result['fragment'];
     }
     $this->uri = $result['uri'];
     $result = Util::cleanArray($result);
     return $result;
 }