$closure) { $closures[$name] = $closure->bindTo($this, $this); } $this->_extended_methods = $closures; } if (method_exists($this, 'initialize')) { $this->initialize($core_instance); }; } /** * Proxy methods to WordPress core instance * * @param string $name * @param array $args * * @return mixed * @access public * * @since 7.0.0 */ public function __call($name, $args) { $response = null; if (array_key_exists($name, $this->_extended_methods)) { $response = call_user_func_array( $this->_extended_methods[$name], $args ); } else { if (AAM_Framework_Manager::_()->has_service($name)) { $response = AAM_Framework_Manager::_()->{$name}($this, ...$args); } elseif (is_object($this->_proxy_instance)) { $response = call_user_func_array( array($this->_proxy_instance, $name), $args ); } else { throw new RuntimeException( sprintf('Method %s does not exist', esc_js($name)) ); } } return $response; } /** * Get a property of a core instance * * @param string $name * * @return mixed * @access public * * @version 7.0.0 */ public function __get($name) { $response = null; if ($name === 'type') { $response = $this->type; } elseif (is_object($this->_proxy_instance)) { $response = $this->_proxy_instance->{$name}; } else { _doing_it_wrong( static::class . '::' . $name, 'Property does not exist', AAM_VERSION ); } return $response; } /** * @inheritDoc */ public function get_resource($resource_type, $reload = null) { $result = $this->_get_cached_instance('resource', $resource_type, $reload); if (is_null($result)) { $result = apply_filters( 'aam_get_resource_filter', null, $this, $resource_type ); $this->_set_cached_instance($result); } return $result; } /** * @inheritDoc */ public function get_preference($preference_type, $reload = null) { $result = $this->_get_cached_instance( 'preference', $preference_type, $reload ); if (is_null($result)) { $result = apply_filters( 'aam_get_preference_filter', null, $this, $preference_type ); $this->_set_cached_instance($result); } return $result; } /** * @inheritDoc */ public function get_proxy_instance() { return $this->_proxy_instance; } /** * @inheritDoc */ public function get_id() { return null; } /** * @inheritDoc */ public function add_sibling(AAM_Framework_AccessLevel_Interface $sibling) { array_push($this->_siblings, $sibling); } /** * @inheritDoc */ public function has_siblings() { return count($this->_siblings) > 0; } /** * @inheritDoc */ public function get_siblings() { return $this->_siblings; } /** * Get already cached resource or preference instance * * @param string $instance_type * @param string $type * @param bool $reload * * @return mixed * @access private * * @version 7.0.0 */ private function _get_cached_instance($instance_type, $type, $reload) { $result = null; if ($reload !== true) { // Determine if we can use cache $exclude = wp_parse_list(AAM_Framework_Manager::_()->config->get( "core.settings.object_cache.ignore.{$instance_type}_types", '' )); if (!in_array($type, $exclude, true)) { $result = AAM_Framework_Manager::_()->object_cache->get([ $this->type, $this->get_id(), $instance_type, $type ]); } } return $result; } /** * Get already cached resource * * @param mixed $instance * * @return bool * @access private * * @version 7.0.0 */ private function _set_cached_instance($instance) { $result = true; if (!empty($instance)) { if (is_a($instance, AAM_Framework_Resource_Interface::class)) { $instance_type = 'resource'; } else { $instance_type = 'preference'; } $type = $instance->type; $exclude = wp_parse_list(AAM_Framework_Manager::_()->config->get( "core.settings.object_cache.ignore.{$instance_type}_types", '' )); if (!in_array($type, $exclude, true)) { $result = AAM_Framework_Manager::_()->object_cache->set([ $this->type, $this->get_id(), $instance_type, $type ], $instance); } } return $result; } }