← Back
Editing: class-wp-service-container.php
<?php /** * Lightweight service container used by the optimization pipeline. * * @package WP_Cache_Optimizer */ if (!defined('ABSPATH') && !defined('WP_CACHE_DIRECT')) { return; } if (!class_exists('WP_Cache_Service_Container')) { class WP_Cache_Service_Container { private static $instance = null; protected $bindings = array(); protected $resolved = array(); public static function instance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } public function bind($id, $factory = null, $shared = false) { $this->bindings[$id] = array('factory' => $factory ? $factory : $id, 'shared' => (bool) $shared); unset($this->resolved[$id]); return $this; } public function get($id) { if (isset($this->resolved[$id])) { return $this->resolved[$id]; } $factory = isset($this->bindings[$id]) ? $this->bindings[$id]['factory'] : $id; try { $object = is_callable($factory) ? call_user_func($factory, $this) : new $factory(); } catch (Exception $e) { return null; } if (isset($this->bindings[$id]) && $this->bindings[$id]['shared']) { $this->resolved[$id] = $object; } return $object; } public function forget($id = null) { if ($id === null) { $this->resolved = array(); return $this; } unset($this->resolved[$id]); return $this; } } }
Save File
Cancel