| @@ -79,8 +79,18 @@ | ||
| 79 | 79 | $this->settings = []; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 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 | + | |
| 83 | 93 | /** |
| 84 | 94 | * Get items. |
| 85 | 95 | * |
| 86 | 96 | * Utility method that receives an array with a needle and returns all the |
| @@ -130,6 +140,27 @@ | ||
| 130 | 140 | private function ensure_settings() { |
| 131 | 141 | if ( null === $this->settings ) { |
| 132 | 142 | $this->settings = $this->get_init_settings(); |
| 133 | 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 | + * | |
| 151 | + * @since 3.1.0 | |
| 152 | + * | |
| 153 | + * @param string $method_name | |
| 154 | + * | |
| 155 | + * @throws \ReflectionException | |
| 156 | + * @return bool True if the method was declared by the current instance, False if it was inherited. | |
| 157 | + */ | |
| 158 | + public function has_own_method( $method_name ) { | |
| 159 | + $reflection_method = new \ReflectionMethod( $this, $method_name ); | |
| 160 | + | |
| 161 | + // If a ReflectionMethod is successfully created, get its declaring class. | |
| 162 | + $declaring_class = $reflection_method->getDeclaringClass(); | |
| 163 | + | |
| 164 | + return get_called_class() === $declaring_class->name; | |
| 134 | 165 | } |
| 135 | 166 | } |