PluginProbe
CSS & JavaScript Toolbox / 6.1
CSS & JavaScript Toolbox v6.1
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | framework/developer/interface/block/parameters/parameters.php +76 -38 106.1 View file →
@@ -8,9 +8,9 @@
8 8
9 9 /**
10 10 *
11 11 */
12 -abstract class CJT_Framework_Developer_Interface_Block_Parameters_Parameters {
12 +class CJT_Framework_Developer_Interface_Block_Parameters {
13 13
14 14 /**
15 15 * put your comment there...
16 16 *
@@ -15,9 +15,9 @@
15 15 * put your comment there...
16 16 *
17 17 * @var mixed
18 18 */
19 - protected $contentParameter = null;
19 + protected $params = array();
20 20
21 21 /**
22 22 * put your comment there...
23 23 *
@@ -22,84 +22,122 @@
22 22 * put your comment there...
23 23 *
24 24 * @var mixed
25 25 */
26 - protected $params = array();
26 + protected $uParams = null;
27 27
28 28 /**
29 29 * put your comment there...
30 30 *
31 - * @param mixed $parameters
32 - * @param mixed $fatory
33 - * @return CJT_Framework_Developer_Interface_Block_Parameters_Parameters
31 + * @param mixed $params
32 + * @return CJT_Framework_Developer_Interface_Block_Parameters
34 33 */
35 - public function __construct($parameters) {
36 - // Validate parameters.
37 - foreach ($parameters as $parameter) {
38 - // Create type object.
39 - $parameterModel = $this->params[$parameter->getName(true)] = $this->getFactory()->create($parameter->getType(), $parameter);
40 - // Hold reference to the CONTENT PARAMETER.
41 - $parameter->getContentParameter() && ($this->contentParameter = $parameterModel);
42 - }
34 + public function __construct($params) {
35 + $this->uParams = $params;
43 36 }
44 -
37 +
45 38 /**
46 39 * put your comment there...
47 40 *
41 + * @param mixed $name
42 + * @param mixed $type
43 + * @param mixed $default
48 44 */
49 - public function getContentParameter() {
50 - return $this->contentParameter;
45 + public function add($name, $type, $default = null) {
46 + // Add to params definition list.
47 + // Use lower case for ket as Wordpress shortcode parameters
48 + // is always transformed to lowercase.
49 + $this->params[strtolower($name)] = array('name' => $name, 'type' => $type, 'default' => $default);
50 + // Chaining.
51 + return $this;
51 52 }
52 53
53 54 /**
54 55 * put your comment there...
55 56 *
57 + * @param mixed $name
56 58 */
57 - protected abstract function getFactory();
59 + public function get($name) {
60 + // Allow writing it in the original case inside the code
61 + // however its only retrived by the lowercvase letter.
62 + return $this->uParams[strtolower($name)];
63 + }
58 64
59 65 /**
60 66 * put your comment there...
61 67 *
62 68 */
63 - public function & getParams() {
64 - return $this->params;
69 + public function & getArray() {
70 + return $this->uParams;
65 71 }
66 -
72 +
67 73 /**
68 74 * put your comment there...
69 75 *
70 76 */
71 - public function getMessages() {
72 -
77 + public function & getDefinition() {
78 + return $this->params;
73 79 }
74 80
75 81 /**
76 82 * put your comment there...
77 83 *
84 + * @param mixed $excludes
85 + * @return CJT_Framework_Developer_Interface_Block_Parameters_Transform_Json
78 86 */
79 - public function hasParams() {
80 - return !empty($this->params);
87 + public function json($excludes = null) {
88 + // Internal json trnsformer object caching!
89 + cssJSToolbox::import('framework:developer:interface:block:parameters:transform:json:json.php');
90 + return new CJT_Framework_Developer_Interface_Block_Parameters_Transform_Json($this, $excludes);
81 91 }
82 92
83 93 /**
84 94 * put your comment there...
85 95 *
86 - * @param mixed $values
87 96 */
88 - public function setValue($values) {
89 - foreach ($this->getParams() as $name => $param) {
90 - if (isset($values[$name])) {
91 - $param->setValue($values[$name]);
97 + public function validate() {
98 + // Get params definition copy!
99 + $dParams = $this->params;
100 + // Validate passed parameters agianst the definition.
101 + foreach ($this->uParams as $name => & $value) {
102 + // Check parameter existance.
103 + if (!isset($this->params[$name])) {
104 + // Warn user that the parameter is not exists!
105 + echo cssJSToolbox::getText("Invalid Block Shortcode parameters [{$name}]");
106 + // Remove from list.
107 + unset($this->uParams[$name]);
92 108 }
109 + // Get parameter type.
110 + $type = $dParams[$name]['type'];
111 + // Cast to correct type.
112 + switch ($type) {
113 + case 'array':
114 + case 'object':
115 + // Convert CJT JSON Array and Object to JSON object.
116 + $value = str_replace(array('{A', '{O', 'A}', 'O}'), array('[', '[', ']', ']'), $value);
117 + // Get PHP var for JSON text!
118 + $value = json_decode($value);
119 + break;
120 + case 'boolean':
121 + // Case boolean from string.
122 + $value = ($value == "true") ? true: false;
123 + break;
124 + default:
125 + // PHP native cast.
126 + settype($value, $type);
127 + break;
128 + }
129 + // As the parameter is passed by user don't need the default.
130 + unset($dParams[$name]);
93 131 }
132 + // Get other parameters not passed by user!
133 + // Get only parameters with default value !== null.
134 + foreach ($dParams as $name => $param) {
135 + if ($param['default'] !== null) {
136 + $this->uParams[$name] = $param['default'];
137 + }
138 + }
139 + // Chaining.
94 140 return $this;
95 141 }
96 142
97 - /**
98 - * put your comment there...
99 - *
100 - */
101 - public function validate() {
102 - return true;
103 - }
104 -
105 143 } // End class.