PluginProbe
Customify / 2.3.0
Customify v2.3.0
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / core / classes / HTMLElement.php

HTMLElement.php in Customify 2.3.0, at core/classes/HTMLElement.php

107 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('ABSPATH') or die;
2
3 /**
4 * A HTMLElement is a HTMLTag with meta support integrated into it. A normal
5 * HTMLTag only cares for it's attributes meta and nothing else, but more
6 * specialized tags such as forms or form fields require misc metadata to be
7 * attached on the object itself.
8 *
9 * @package pixcustomify
10 * @category core
11 * @author Pixelgrade Team
12 * @copyright (c) 2013, Pixelgrade
13 */
14 class PixCustomifyHTMLElementImpl extends PixCustomifyHTMLTagImpl implements PixCustomifyHTMLElement {
15
16 /** @var array configuration values */
17 protected $meta = null;
18
19 /**
20 * @param array config
21 */
22 static function instance($config = null) {
23 $i = new self;
24 $i->configure($config);
25 return $i;
26 }
27
28 /**
29 * Apply configuration.
30 */
31 protected function configure($config = null) {
32 // gurantee configuration
33 $config !== null or $config = array();
34
35 // invoke htmltag instance configuration
36 if (isset($config['attrs'])) {
37 parent::configure($config['attrs']);
38 unset($config['attrs']);
39 }
40 else { // no html attributes set
41 parent::configure(array());
42 }
43
44 // setup meta fields
45 $this->meta = pixcustomify::instance('PixCustomifyMeta', $config);
46 }
47
48
49 // Meta
50 // ------------------------------------------------------------------------
51
52 /**
53 * @param string meta key
54 * @return boolean true if key exists, false otherwise
55 */
56 function hasmeta($key) {
57 return $this->meta->has($key);
58 }
59
60 /**
61 * @return mixed value or default
62 */
63 function getmeta($key, $default = null) {
64 return $this->meta->get($key, $default);
65 }
66
67 /**
68 * @return static $this
69 */
70 function setmeta($key, $value) {
71 $this->meta->set($key, $value);
72 return $this;
73 }
74
75 /**
76 * Set the key if it's not already set.
77 *
78 * @param string key
79 * @param string value
80 */
81 function ensuremeta($key, $value) {
82 $this->meta->ensure($key, $value);
83 return $this;
84 }
85
86 /**
87 * If the key is currently a non-array value it will be converted to an
88 * array maintaning the previous value (along with the new one).
89 *
90 * @param string name
91 * @param mixed value
92 * @return static $this
93 */
94 function addmeta($name, $value) {
95 $this->meta->add($name, $value);
96 return $this;
97 }
98
99 /**
100 * @return PixCustomifyMeta
101 */
102 function meta() {
103 return $this->meta;
104 }
105
106 } # class
107