PluginProbe
CSS & JavaScript Toolbox / 6.1.2
CSS & JavaScript Toolbox v6.1.2
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
css-javascript-toolbox / framework / developer / interface / block / parameters / parameters.php

parameters.php in CSS & JavaScript Toolbox 6.1.2, at framework/developer/interface/block/parameters/parameters.php

143 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 /**
10 *
11 */
12 class CJT_Framework_Developer_Interface_Block_Parameters {
13
14 /**
15 * put your comment there...
16 *
17 * @var mixed
18 */
19 protected $params = array();
20
21 /**
22 * put your comment there...
23 *
24 * @var mixed
25 */
26 protected $uParams = null;
27
28 /**
29 * put your comment there...
30 *
31 * @param mixed $params
32 * @return CJT_Framework_Developer_Interface_Block_Parameters
33 */
34 public function __construct($params) {
35 $this->uParams = $params;
36 }
37
38 /**
39 * put your comment there...
40 *
41 * @param mixed $name
42 * @param mixed $type
43 * @param mixed $default
44 */
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;
52 }
53
54 /**
55 * put your comment there...
56 *
57 * @param mixed $name
58 */
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 }
64
65 /**
66 * put your comment there...
67 *
68 */
69 public function & getArray() {
70 return $this->uParams;
71 }
72
73 /**
74 * put your comment there...
75 *
76 */
77 public function & getDefinition() {
78 return $this->params;
79 }
80
81 /**
82 * put your comment there...
83 *
84 * @param mixed $excludes
85 * @return CJT_Framework_Developer_Interface_Block_Parameters_Transform_Json
86 */
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);
91 }
92
93 /**
94 * put your comment there...
95 *
96 */
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]);
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]);
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.
140 return $this;
141 }
142
143 } // End class.