fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Uri / UriFactory.php
blob3641cdb2801c85d67b64cc93b6fcc05bc2816a39
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Uri;
12 /**
13 * URI Factory Class
15 * The URI factory can be used to generate URI objects from strings, using a
16 * different URI subclass depending on the input URI scheme. New scheme-specific
17 * classes can be registered using the registerScheme() method.
19 * Note that this class contains only static methods and should not be
20 * instantiated
22 abstract class UriFactory
24 /**
25 * Registered scheme-specific classes
27 * @var array
29 protected static $schemeClasses = array(
30 'http' => 'Zend\Uri\Http',
31 'https' => 'Zend\Uri\Http',
32 'mailto' => 'Zend\Uri\Mailto',
33 'file' => 'Zend\Uri\File',
34 'urn' => 'Zend\Uri\Uri',
35 'tag' => 'Zend\Uri\Uri',
38 /**
39 * Register a scheme-specific class to be used
41 * @param string $scheme
42 * @param string $class
44 public static function registerScheme($scheme, $class)
46 $scheme = strtolower($scheme);
47 static::$schemeClasses[$scheme] = $class;
50 /**
51 * Unregister a scheme
53 * @param string $scheme
55 public static function unregisterScheme($scheme)
57 $scheme = strtolower($scheme);
58 if (isset(static::$schemeClasses[$scheme])) {
59 unset(static::$schemeClasses[$scheme]);
63 /**
64 * Get the class name for a registered scheme
66 * If provided scheme is not registered, will return NULL
68 * @param string $scheme
69 * @return string|null
71 public static function getRegisteredSchemeClass($scheme)
73 if (isset(static::$schemeClasses[$scheme])) {
74 return static::$schemeClasses[$scheme];
77 return;
80 /**
81 * Create a URI from a string
83 * @param string $uriString
84 * @param string $defaultScheme
85 * @throws Exception\InvalidArgumentException
86 * @return \Zend\Uri\Uri
88 public static function factory($uriString, $defaultScheme = null)
90 if (!is_string($uriString)) {
91 throw new Exception\InvalidArgumentException(sprintf(
92 'Expecting a string, received "%s"',
93 (is_object($uriString) ? get_class($uriString) : gettype($uriString))
94 ));
97 $uri = new Uri($uriString);
98 $scheme = strtolower($uri->getScheme());
99 if (!$scheme && $defaultScheme) {
100 $scheme = $defaultScheme;
103 if ($scheme && ! isset(static::$schemeClasses[$scheme])) {
104 throw new Exception\InvalidArgumentException(sprintf(
105 'no class registered for scheme "%s"',
106 $scheme
109 if ($scheme && isset(static::$schemeClasses[$scheme])) {
110 $class = static::$schemeClasses[$scheme];
111 $uri = new $class($uri);
112 if (! $uri instanceof UriInterface) {
113 throw new Exception\InvalidArgumentException(
114 sprintf(
115 'class "%s" registered for scheme "%s" does not implement Zend\Uri\UriInterface',
116 $class,
117 $scheme
123 return $uri;