PluginProbe
Customify / 1.2.3
Customify v1.2.3
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 / Meta.php

Meta.php in Customify 1.2.3, at core/classes/Meta.php

120 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 /* This file is property of Pixel Grade Media. You may NOT copy, or redistribute
4 * it. Please see the license that came with your copy for more information.
5 */
6
7 /**
8 * @package pixcustomify
9 * @category core
10 * @author Pixel Grade Team
11 * @copyright (c) 2013, Pixel Grade Media
12 */
13 class PixCustomifyMetaImpl implements PixCustomifyMeta {
14
15 /** @var array metadat */
16 protected $metadata = array();
17
18 /**
19 * @param array metadata
20 * @return PixCustomifyMeta
21 */
22 static function instance($metadata) {
23 $i = new self;
24 $i->metadata = $metadata;
25 return $i;
26 }
27
28 /**
29 * @param string meta key
30 * @return boolean true if key exists, false otherwise
31 */
32 function has($key) {
33 return isset($this->metadata[$key]);
34 }
35
36 /**
37 * @param string key
38 * @param mixed default
39 * @return mixed
40 */
41 function get($key, $default = null) {
42 return $this->has($key) ? $this->metadata[$key] : $default;
43 }
44
45 /**
46 * @param string key
47 * @param mixed value
48 * @return static $this
49 */
50 function set($key, $value) {
51 $this->metadata[$key] = $value;
52 return $this;
53 }
54
55 /**
56 * Set the key if it's not already set.
57 *
58 * @param string key
59 * @param string value
60 */
61 function ensure($key, $value) {
62 if ( ! $this->has($key)) {
63 $this->set($key, $value);
64 }
65
66 return $this;
67 }
68
69 /**
70 * If the key is currently a non-array value it will be converted to an
71 * array maintaning the previous value (along with the new one).
72 *
73 * @param string name
74 * @param mixed value
75 * @return static $this
76 */
77 function add($name, $value) {
78
79 // Cleanup
80 // -------
81
82 if ( ! isset($this->metadata[$name])) {
83 $this->metadata[$name] = array();
84 }
85 else if ( ! is_array($this->metadata[$name]))
86 {
87 $this->metadata[$name] = array($this->metadata[$name]);
88 }
89 # else: array, no cleanup required
90
91 // Register new value
92 // ------------------
93
94 $this->metadata[$name][] = $value;
95
96 return $this;
97 }
98
99 /**
100 * @return array all metadata as array
101 */
102 function metadata_array() {
103 return $this->metadata;
104 }
105
106 /**
107 * Shorthand for a calling set on multiple keys.
108 *
109 * @return static $this
110 */
111 function overwritemeta($overwrites) {
112 foreach ($overwrites as $key => $value) {
113 $this->set($key, $value);
114 }
115
116 return $this;
117 }
118
119 } # class
120