Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core_cache;
18
 
19
/**
20
 * A cached object wrapper.
21
 *
22
 * This class gets used when the data is an object that has implemented the cacheable_object_interface interface.
23
 *
24
 * @package    core_cache
25
 * @category   cache
26
 * @copyright  2012 Sam Hemelryk
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class cached_object {
30
    /**
31
     * The class of the cacheable object
32
     * @var string
33
     */
34
    protected $class;
35
 
36
    /**
37
     * The data returned by the cacheable_object_interface prepare_to_cache method.
38
     * @var mixed
39
     */
40
    protected $data;
41
 
42
    /**
43
     * Constructs a cached object wrapper.
44
     * @param cacheable_object_interface $obj
45
     */
46
    public function __construct(cacheable_object_interface $obj) {
47
        $this->class = get_class($obj);
48
        $this->data = $obj->prepare_to_cache();
49
    }
50
 
51
    /**
52
     * Restores the data as an instance of the cacheable_object_interface class.
53
     * @return object
54
     */
55
    public function restore_object() {
56
        $class = $this->class;
57
        return $class::wake_from_cache($this->data);
58
    }
59
}
60
 
61
// Alias this class to the old name.
62
// This file will be autoloaded by the legacyclasses autoload system.
63
// In future all uses of this class will be corrected and the legacy references will be removed.
64
class_alias(cached_object::class, \cache_cached_object::class);