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 / Tag / Item.php
blob4f41de55fd0b997232be6c72d19e454d9b3b62bd
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\Tag;
12 use Traversable;
13 use Zend\Stdlib\ArrayUtils;
15 class Item implements TaggableInterface
17 /**
18 * Title of the tag
20 * @var string
22 protected $title = null;
24 /**
25 * Weight of the tag
27 * @var float
29 protected $weight = null;
31 /**
32 * Custom parameters
34 * @var string
36 protected $params = array();
38 /**
39 * Option keys to skip when calling setOptions()
41 * @var array
43 protected $skipOptions = array(
44 'options',
45 'param'
48 /**
49 * Create a new tag according to the options
51 * @param array|Traversable $options
52 * @throws \Zend\Tag\Exception\InvalidArgumentException When invalid options are provided
53 * @throws \Zend\Tag\Exception\InvalidArgumentException When title was not set
54 * @throws \Zend\Tag\Exception\InvalidArgumentException When weight was not set
56 public function __construct($options)
58 if ($options instanceof Traversable) {
59 $options = ArrayUtils::iteratorToArray($options);
62 if (!is_array($options)) {
63 throw new Exception\InvalidArgumentException('Invalid options provided to constructor');
66 $this->setOptions($options);
68 if ($this->title === null) {
69 throw new Exception\InvalidArgumentException('Title was not set');
72 if ($this->weight === null) {
73 throw new Exception\InvalidArgumentException('Weight was not set');
77 /**
78 * Set options of the tag
80 * @param array $options
81 * @return \Zend\Tag\Item
83 public function setOptions(array $options)
85 foreach ($options as $key => $value) {
86 if (in_array(strtolower($key), $this->skipOptions)) {
87 continue;
90 $method = 'set' . $key;
91 if (method_exists($this, $method)) {
92 $this->$method($value);
96 return $this;
99 /**
100 * Defined by Zend\Tag\TaggableInterface
102 * @return string
104 public function getTitle()
106 return $this->title;
110 * Set the title
112 * @param string $title
113 * @throws \Zend\Tag\Exception\InvalidArgumentException When title is no string
114 * @return \Zend\Tag\Item
116 public function setTitle($title)
118 if (!is_string($title)) {
119 throw new Exception\InvalidArgumentException('Title must be a string');
122 $this->title = (string) $title;
123 return $this;
127 * Defined by Zend\Tag\TaggableInterface
129 * @return float
131 public function getWeight()
133 return $this->weight;
137 * Set the weight
139 * @param float $weight
140 * @throws \Zend\Tag\Exception\InvalidArgumentException When weight is not numeric
141 * @return \Zend\Tag\Item
143 public function setWeight($weight)
145 if (!is_numeric($weight)) {
146 throw new Exception\InvalidArgumentException('Weight must be numeric');
149 $this->weight = (float) $weight;
150 return $this;
154 * Set multiple params at once
156 * @param array $params
157 * @return \Zend\Tag\Item
159 public function setParams(array $params)
161 foreach ($params as $name => $value) {
162 $this->setParam($name, $value);
165 return $this;
169 * Defined by Zend\Tag\TaggableInterface
171 * @param string $name
172 * @param mixed $value
173 * @return \Zend\Tag\Item
175 public function setParam($name, $value)
177 $this->params[$name] = $value;
178 return $this;
182 * Defined by Zend\Tag\TaggableInterface
184 * @param string $name
185 * @return mixed
187 public function getParam($name)
189 if (isset($this->params[$name])) {
190 return $this->params[$name];
192 return null;