[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Uri 17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 18 * @license http://framework.zend.com/license/new-bsd New BSD License 19 * @version $Id$ 20 */ 21 22 /** 23 * Abstract class for all Zend_Uri handlers 24 * 25 * @category Zend 26 * @package Zend_Uri 27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 28 * @license http://framework.zend.com/license/new-bsd New BSD License 29 */ 30 abstract class Zend_Uri 31 { 32 /** 33 * Scheme of this URI (http, ftp, etc.) 34 * 35 * @var string 36 */ 37 protected $_scheme = ''; 38 39 /** 40 * Global configuration array 41 * 42 * @var array 43 */ 44 static protected $_config = array( 45 'allow_unwise' => false 46 ); 47 48 /** 49 * Return a string representation of this URI. 50 * 51 * @see getUri() 52 * @return string 53 */ 54 public function __toString() 55 { 56 return $this->getUri(); 57 } 58 59 /** 60 * Convenience function, checks that a $uri string is well-formed 61 * by validating it but not returning an object. Returns TRUE if 62 * $uri is a well-formed URI, or FALSE otherwise. 63 * 64 * @param string $uri The URI to check 65 * @return boolean 66 */ 67 public static function check($uri) 68 { 69 try { 70 $uri = self::factory($uri); 71 } catch (Exception $e) { 72 return false; 73 } 74 75 return $uri->valid(); 76 } 77 78 /** 79 * Create a new Zend_Uri object for a URI. If building a new URI, then $uri should contain 80 * only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI. 81 * 82 * @param string $uri The URI form which a Zend_Uri instance is created 83 * @param string $className The name of the class to use in order to manipulate URI 84 * @throws Zend_Uri_Exception When an empty string was supplied for the scheme 85 * @throws Zend_Uri_Exception When an illegal scheme is supplied 86 * @throws Zend_Uri_Exception When the scheme is not supported 87 * @throws Zend_Uri_Exception When $className doesn't exist or doesn't implements Zend_Uri 88 * @return Zend_Uri 89 * @link http://www.faqs.org/rfcs/rfc2396.html 90 */ 91 public static function factory($uri = 'http', $className = null) 92 { 93 // Separate the scheme from the scheme-specific parts 94 $uri = explode(':', $uri, 2); 95 $scheme = strtolower($uri[0]); 96 $schemeSpecific = isset($uri[1]) === true ? $uri[1] : ''; 97 98 if (strlen($scheme) === 0) { 99 require_once 'Zend/Uri/Exception.php'; 100 throw new Zend_Uri_Exception('An empty string was supplied for the scheme'); 101 } 102 103 // Security check: $scheme is used to load a class file, so only alphanumerics are allowed. 104 if (ctype_alnum($scheme) === false) { 105 require_once 'Zend/Uri/Exception.php'; 106 throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted'); 107 } 108 109 if ($className === null) { 110 /** 111 * Create a new Zend_Uri object for the $uri. If a subclass of Zend_Uri exists for the 112 * scheme, return an instance of that class. Otherwise, a Zend_Uri_Exception is thrown. 113 */ 114 switch ($scheme) { 115 case 'http': 116 // Break intentionally omitted 117 case 'https': 118 $className = 'Zend_Uri_Http'; 119 break; 120 121 case 'mailto': 122 // TODO 123 default: 124 require_once 'Zend/Uri/Exception.php'; 125 throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported"); 126 break; 127 } 128 } 129 130 if (!class_exists($className)) { 131 require_once 'Zend/Loader.php'; 132 try { 133 Zend_Loader::loadClass($className); 134 } catch (Exception $e) { 135 require_once 'Zend/Uri/Exception.php'; 136 throw new Zend_Uri_Exception("\"$className\" not found"); 137 } 138 } 139 140 $schemeHandler = new $className($scheme, $schemeSpecific); 141 142 if (! $schemeHandler instanceof Zend_Uri) { 143 require_once 'Zend/Uri/Exception.php'; 144 throw new Zend_Uri_Exception("\"$className\" is not an instance of Zend_Uri"); 145 } 146 147 return $schemeHandler; 148 } 149 150 /** 151 * Get the URI's scheme 152 * 153 * @return string|false Scheme or false if no scheme is set. 154 */ 155 public function getScheme() 156 { 157 if (empty($this->_scheme) === false) { 158 return $this->_scheme; 159 } else { 160 return false; 161 } 162 } 163 164 /** 165 * Set global configuration options 166 * 167 * @param Zend_Config|array $config 168 */ 169 static public function setConfig($config) 170 { 171 if ($config instanceof Zend_Config) { 172 $config = $config->toArray(); 173 } elseif (!is_array($config)) { 174 throw new Zend_Uri_Exception("Config must be an array or an instance of Zend_Config."); 175 } 176 177 foreach ($config as $k => $v) { 178 self::$_config[$k] = $v; 179 } 180 } 181 182 /** 183 * Zend_Uri and its subclasses cannot be instantiated directly. 184 * Use Zend_Uri::factory() to return a new Zend_Uri object. 185 * 186 * @param string $scheme The scheme of the URI 187 * @param string $schemeSpecific The scheme-specific part of the URI 188 */ 189 abstract protected function __construct($scheme, $schemeSpecific = ''); 190 191 /** 192 * Return a string representation of this URI. 193 * 194 * @return string 195 */ 196 abstract public function getUri(); 197 198 /** 199 * Returns TRUE if this URI is valid, or FALSE otherwise. 200 * 201 * @return boolean 202 */ 203 abstract public function valid(); 204 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |