. namespace core_cache; /** * A cached object wrapper. * * This class gets used when the data is an object that has implemented the cacheable_object_interface interface. * * @package core_cache * @category cache * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cached_object { /** * The class of the cacheable object * @var string */ protected $class; /** * The data returned by the cacheable_object_interface prepare_to_cache method. * @var mixed */ protected $data; /** * Constructs a cached object wrapper. * @param cacheable_object_interface $obj */ public function __construct(cacheable_object_interface $obj) { $this->class = get_class($obj); $this->data = $obj->prepare_to_cache(); } /** * Restores the data as an instance of the cacheable_object_interface class. * @return object */ public function restore_object() { $class = $this->class; return $class::wake_from_cache($this->data); } } // Alias this class to the old name. // This file will be autoloaded by the legacyclasses autoload system. // In future all uses of this class will be corrected and the legacy references will be removed. class_alias(cached_object::class, \cache_cached_object::class);