Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / View / Helper / Doctype.php
blobcb052ea8e2ca833e236a3564344f42ce319bd00e
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-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\View\Helper;
12 use ArrayObject;
13 use Zend\View\Exception;
15 /**
16 * Helper for setting and retrieving the doctype
18 class Doctype extends AbstractHelper
20 /**#@+
21 * DocType constants
23 const XHTML11 = 'XHTML11';
24 const XHTML1_STRICT = 'XHTML1_STRICT';
25 const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
26 const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
27 const XHTML1_RDFA = 'XHTML1_RDFA';
28 const XHTML1_RDFA11 = 'XHTML1_RDFA11';
29 const XHTML_BASIC1 = 'XHTML_BASIC1';
30 const XHTML5 = 'XHTML5';
31 const HTML4_STRICT = 'HTML4_STRICT';
32 const HTML4_LOOSE = 'HTML4_LOOSE';
33 const HTML4_FRAMESET = 'HTML4_FRAMESET';
34 const HTML5 = 'HTML5';
35 const CUSTOM_XHTML = 'CUSTOM_XHTML';
36 const CUSTOM = 'CUSTOM';
37 /**#@-*/
39 /**
40 * Default DocType
42 * @var string
44 protected $defaultDoctype = self::HTML4_LOOSE;
46 /**
47 * Registry containing current doctype and mappings
49 * @var ArrayObject
51 protected $registry;
53 /**
54 * @var ArrayObject Shared doctypes to use throughout all instances
56 protected static $registeredDoctypes;
58 /**
59 * Constructor
61 * Map constants to doctype strings, and set default doctype
63 public function __construct()
65 if (null === static::$registeredDoctypes) {
66 static::registerDefaultDoctypes();
67 $this->setDoctype($this->defaultDoctype);
69 $this->registry = static::$registeredDoctypes;
72 /**
73 * Set or retrieve doctype
75 * @param string $doctype
76 * @throws Exception\DomainException
77 * @return Doctype
79 public function __invoke($doctype = null)
81 if (null !== $doctype) {
82 switch ($doctype) {
83 case self::XHTML11:
84 case self::XHTML1_STRICT:
85 case self::XHTML1_TRANSITIONAL:
86 case self::XHTML1_FRAMESET:
87 case self::XHTML_BASIC1:
88 case self::XHTML1_RDFA:
89 case self::XHTML1_RDFA11:
90 case self::XHTML5:
91 case self::HTML4_STRICT:
92 case self::HTML4_LOOSE:
93 case self::HTML4_FRAMESET:
94 case self::HTML5:
95 $this->setDoctype($doctype);
96 break;
97 default:
98 if (substr($doctype, 0, 9) != '<!DOCTYPE') {
99 throw new Exception\DomainException('The specified doctype is malformed');
101 if (stristr($doctype, 'xhtml')) {
102 $type = self::CUSTOM_XHTML;
103 } else {
104 $type = self::CUSTOM;
106 $this->setDoctype($type);
107 $this->registry['doctypes'][$type] = $doctype;
108 break;
112 return $this;
116 * String representation of doctype
118 * @return string
120 public function __toString()
122 $doctypes = $this->getDoctypes();
124 return $doctypes[$this->getDoctype()];
128 * Register the default doctypes we understand
130 * @return void
132 protected static function registerDefaultDoctypes()
134 static::$registeredDoctypes = new ArrayObject(array(
135 'doctypes' => array(
136 self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
137 self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
138 self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
139 self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
140 self::XHTML1_RDFA => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
141 self::XHTML1_RDFA11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
142 self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
143 self::XHTML5 => '<!DOCTYPE html>',
144 self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
145 self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
146 self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
147 self::HTML5 => '<!DOCTYPE html>',
153 * Unset the static doctype registry
155 * Mainly useful for testing purposes. Sets {@link $registeredDoctypes} to
156 * a null value.
158 * @return void
160 public static function unsetDoctypeRegistry()
162 static::$registeredDoctypes = null;
166 * Set doctype
168 * @param string $doctype
169 * @return Doctype
171 public function setDoctype($doctype)
173 $this->registry['doctype'] = $doctype;
174 return $this;
178 * Retrieve doctype
180 * @return string
182 public function getDoctype()
184 if (!isset($this->registry['doctype'])) {
185 $this->setDoctype($this->defaultDoctype);
188 return $this->registry['doctype'];
192 * Get doctype => string mappings
194 * @return array
196 public function getDoctypes()
198 return $this->registry['doctypes'];
202 * Is doctype XHTML?
204 * @return bool
206 public function isXhtml()
208 return (stristr($this->getDoctype(), 'xhtml') ? true : false);
212 * Is doctype HTML5? (HeadMeta uses this for validation)
214 * @return bool
216 public function isHtml5()
218 return (stristr($this->__invoke(), '<!DOCTYPE html>') ? true : false);
222 * Is doctype RDFa?
224 * @return bool
226 public function isRdfa()
228 return ($this->isHtml5() || stristr($this->getDoctype(), 'rdfa') ? true : false);