PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.10
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.10
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / base-data.php

base-data.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.10, at Inc/base-data.php

88 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 abstract class Base_Data {
10
11 private $data;
12
13 final public function get( $data = null ) {
14 $this->ensure_data();
15
16 return self::get_items( $this->data, $data );
17 }
18
19 final public function set( $key, $value = null ) {
20 if ( is_array( $key ) ) {
21 $this->data = array_merge( $this->get_defaults(), $key );
22 } else {
23 $this->ensure_data();
24 $this->data[ $key ] = $value;
25 }
26 }
27
28 public function delete( $key = null ) {
29 if ( $key ) {
30 unset( $this->data[ $key ] );
31 } else {
32 $this->data = [];
33 }
34 }
35
36 final public function set_recursive( $key, array $value ) {
37 $this->ensure_data();
38
39 $data = &$this->data[ $key ];
40
41 $data = $this->merge_properties( $data, $value );
42 }
43
44 final public function merge_properties( array $default_props, array $custom_props, array $allowed_props_keys = [] ) {
45 $props = array_replace_recursive( $default_props, $custom_props );
46
47 if ( $allowed_props_keys ) {
48 $props = array_intersect_key( $props, array_flip( $allowed_props_keys ) );
49 }
50
51 return $props;
52 }
53
54 final protected static function get_items( array $haystack, $needle = null ) {
55 if ( $needle ) {
56 return isset( $haystack[ $needle ] ) ? $haystack[ $needle ] : null;
57 }
58
59 return $haystack;
60 }
61
62 protected function get_defaults() {
63 return [];
64 }
65
66 private function ensure_data() {
67 if ( null === $this->data ) {
68 $this->data = $this->get_defaults();
69 }
70 }
71
72 public function has_own_method( $method_name, $base_class_name = null ) {
73 try {
74 $reflection_method = new \ReflectionMethod( $this, $method_name );
75 $declaring_class = $reflection_method->getDeclaringClass();
76 } catch ( \Exception $e ) {
77 return false;
78 }
79
80 if ( $base_class_name ) {
81 return $base_class_name !== $declaring_class->name;
82 }
83
84 return get_called_class() === $declaring_class->name;
85 }
86
87 }
88