PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.27.0-beta1
Elementor Website Builder – more than just a page builder v3.27.0-beta1
4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / core / base / base-object.php
elementor / core / base Last commit date
background-process 1 year ago elements-iteration-actions 1 year ago providers 1 year ago traits 1 year ago app.php 3 years ago background-task-manager.php 3 years ago background-task.php 1 year ago base-object.php 3 years ago db-upgrades-manager.php 3 years ago document.php 1 year ago module.php 1 year ago
base-object.php
194 lines
1 <?php
2
3 namespace Elementor\Core\Base;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly
7 }
8
9 /**
10 * Base Object
11 *
12 * Base class that provides basic settings handling functionality.
13 *
14 * @since 2.3.0
15 */
16 class Base_Object {
17
18 /**
19 * Settings.
20 *
21 * Holds the object settings.
22 *
23 * @access private
24 *
25 * @var array
26 */
27 private $settings;
28
29 /**
30 * Get Settings.
31 *
32 * @since 2.3.0
33 * @access public
34 *
35 * @param string $setting Optional. The key of the requested setting. Default is null.
36 *
37 * @return mixed An array of all settings, or a single value if `$setting` was specified.
38 */
39 final public function get_settings( $setting = null ) {
40 $this->ensure_settings();
41
42 return self::get_items( $this->settings, $setting );
43 }
44
45 /**
46 * Set settings.
47 *
48 * @since 2.3.0
49 * @access public
50 *
51 * @param array|string $key If key is an array, the settings are overwritten by that array. Otherwise, the
52 * settings of the key will be set to the given `$value` param.
53 *
54 * @param mixed $value Optional. Default is null.
55 */
56 final public function set_settings( $key, $value = null ) {
57 $this->ensure_settings();
58
59 if ( is_array( $key ) ) {
60 $this->settings = $key;
61 } else {
62 $this->settings[ $key ] = $value;
63 }
64 }
65
66 /**
67 * Delete setting.
68 *
69 * Deletes the settings array or a specific key of the settings array if `$key` is specified.
70 * @since 2.3.0
71 * @access public
72 *
73 * @param string $key Optional. Default is null.
74 */
75 public function delete_setting( $key = null ) {
76 if ( $key ) {
77 unset( $this->settings[ $key ] );
78 } else {
79 $this->settings = [];
80 }
81 }
82
83 final public function merge_properties( array $default_props, array $custom_props, array $allowed_props_keys = [] ) {
84 $props = array_replace_recursive( $default_props, $custom_props );
85
86 if ( $allowed_props_keys ) {
87 $props = array_intersect_key( $props, array_flip( $allowed_props_keys ) );
88 }
89
90 return $props;
91 }
92
93 /**
94 * Get items.
95 *
96 * Utility method that receives an array with a needle and returns all the
97 * items that match the needle. If needle is not defined the entire haystack
98 * will be returned.
99 *
100 * @since 2.3.0
101 * @access protected
102 * @static
103 *
104 * @param array $haystack An array of items.
105 * @param string $needle Optional. Needle. Default is null.
106 *
107 * @return mixed The whole haystack or the needle from the haystack when requested.
108 */
109 final protected static function get_items( array $haystack, $needle = null ) {
110 if ( $needle ) {
111 return isset( $haystack[ $needle ] ) ? $haystack[ $needle ] : null;
112 }
113
114 return $haystack;
115 }
116
117 /**
118 * Get init settings.
119 *
120 * Used to define the default/initial settings of the object. Inheriting classes may implement this method to define
121 * their own default/initial settings.
122 *
123 * @since 2.3.0
124 * @access protected
125 *
126 * @return array
127 */
128 protected function get_init_settings() {
129 return [];
130 }
131
132 /**
133 * Ensure settings.
134 *
135 * Ensures that the `$settings` member is initialized
136 *
137 * @since 2.3.0
138 * @access private
139 */
140 private function ensure_settings() {
141 if ( null === $this->settings ) {
142 $this->settings = $this->get_init_settings();
143 }
144 }
145
146 /**
147 * Has Own Method
148 *
149 * Used for check whether the method passed as a parameter was declared in the current instance or inherited.
150 * If a base_class_name is passed, it checks whether the method was declared in that class. If the method's
151 * declaring class is the class passed as $base_class_name, it returns false. Otherwise (method was NOT declared
152 * in $base_class_name), it returns true.
153 *
154 * Example #1 - only $method_name is passed:
155 * The initial declaration of `register_controls()` happens in the `Controls_Stack` class. However, all
156 * widgets which have their own controls declare this function as well, overriding the original
157 * declaration. If `has_own_method()` would be called by a Widget's class which implements `register_controls()`,
158 * with 'register_controls' passed as the first parameter - `has_own_method()` will return true. If the Widget
159 * does not declare `register_controls()`, `has_own_method()` will return false.
160 *
161 * Example #2 - both $method_name and $base_class_name are passed
162 * In this example, the widget class inherits from a base class `Widget_Base`, and the base implements
163 * `register_controls()` to add certain controls to all widgets inheriting from it. `has_own_method()` is called by
164 * the widget, with the string 'register_controls' passed as the first parameter, and 'Elementor\Widget_Base' (its full name
165 * including the namespace) passed as the second parameter. If the widget class implements `register_controls()`,
166 * `has_own_method` will return true. If the widget class DOESN'T implement `register_controls()`, it will return
167 * false (because `Widget_Base` is the declaring class for `register_controls()`, and not the class that called
168 * `has_own_method()`).
169 *
170 * @since 3.1.0
171 *
172 * @param string $method_name
173 * @param string $base_class_name
174 *
175 * @return bool True if the method was declared by the current instance, False if it was inherited.
176 */
177 public function has_own_method( $method_name, $base_class_name = null ) {
178 try {
179 $reflection_method = new \ReflectionMethod( $this, $method_name );
180
181 // If a ReflectionMethod is successfully created, get its declaring class.
182 $declaring_class = $reflection_method->getDeclaringClass();
183 } catch ( \Exception $e ) {
184 return false;
185 }
186
187 if ( $base_class_name ) {
188 return $base_class_name !== $declaring_class->name;
189 }
190
191 return get_called_class() === $declaring_class->name;
192 }
193 }
194