|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00030 abstract class Zend_Uri 00031 { 00037 protected $_scheme = ''; 00038 00044 static protected $_config = array( 00045 'allow_unwise' => false 00046 ); 00047 00054 public function __toString() 00055 { 00056 return $this->getUri(); 00057 } 00058 00067 public static function check($uri) 00068 { 00069 try { 00070 $uri = self::factory($uri); 00071 } catch (Exception $e) { 00072 return false; 00073 } 00074 00075 return $uri->valid(); 00076 } 00077 00091 public static function factory($uri = 'http', $className = null) 00092 { 00093 // Separate the scheme from the scheme-specific parts 00094 $uri = explode(':', $uri, 2); 00095 $scheme = strtolower($uri[0]); 00096 $schemeSpecific = isset($uri[1]) === true ? $uri[1] : ''; 00097 00098 if (strlen($scheme) === 0) { 00099 require_once 'Zend/Uri/Exception.php'; 00100 throw new Zend_Uri_Exception('An empty string was supplied for the scheme'); 00101 } 00102 00103 // Security check: $scheme is used to load a class file, so only alphanumerics are allowed. 00104 if (ctype_alnum($scheme) === false) { 00105 require_once 'Zend/Uri/Exception.php'; 00106 throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted'); 00107 } 00108 00109 if ($className === null) { 00114 switch ($scheme) { 00115 case 'http': 00116 // Break intentionally omitted 00117 case 'https': 00118 $className = 'Zend_Uri_Http'; 00119 break; 00120 00121 case 'mailto': 00122 // TODO 00123 default: 00124 require_once 'Zend/Uri/Exception.php'; 00125 throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported"); 00126 break; 00127 } 00128 } 00129 00130 if (!class_exists($className)) { 00131 require_once 'Zend/Loader.php'; 00132 try { 00133 Zend_Loader::loadClass($className); 00134 } catch (Exception $e) { 00135 require_once 'Zend/Uri/Exception.php'; 00136 throw new Zend_Uri_Exception("\"$className\" not found"); 00137 } 00138 } 00139 00140 $schemeHandler = new $className($scheme, $schemeSpecific); 00141 00142 if (! $schemeHandler instanceof Zend_Uri) { 00143 require_once 'Zend/Uri/Exception.php'; 00144 throw new Zend_Uri_Exception("\"$className\" is not an instance of Zend_Uri"); 00145 } 00146 00147 return $schemeHandler; 00148 } 00149 00155 public function getScheme() 00156 { 00157 if (empty($this->_scheme) === false) { 00158 return $this->_scheme; 00159 } else { 00160 return false; 00161 } 00162 } 00163 00169 static public function setConfig($config) 00170 { 00171 if ($config instanceof Zend_Config) { 00172 $config = $config->toArray(); 00173 } elseif (!is_array($config)) { 00174 throw new Zend_Uri_Exception("Config must be an array or an instance of Zend_Config."); 00175 } 00176 00177 foreach ($config as $k => $v) { 00178 self::$_config[$k] = $v; 00179 } 00180 } 00181 00189 abstract protected function __construct($scheme, $schemeSpecific = ''); 00190 00196 abstract public function getUri(); 00197 00203 abstract public function valid(); 00204 }