1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Victor Dubiniuk <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Owncloud\Updater\Utils; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Registry |
27
|
|
|
* |
28
|
|
|
* @package Owncloud\Updater\Utils |
29
|
|
|
*/ |
30
|
|
|
class Registry { |
31
|
|
|
|
32
|
|
|
protected $objects = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @param string $name |
37
|
|
|
* @param mixed $object |
38
|
|
|
*/ |
39
|
3 |
|
public function set($name, $object){ |
40
|
3 |
|
$this->objects[$name] = $object; |
41
|
3 |
|
$_SESSION[$name] = serialize($object); |
42
|
3 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @param string $name |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
4 |
|
public function get($name){ |
50
|
4 |
|
if (isset($this->objects[$name])){ |
51
|
3 |
|
return $this->objects[$name]; |
52
|
1 |
|
} else if (isset($_SESSION[$name])){ |
53
|
|
|
$this->objects[$name] = unserialize($_SESSION[$name]); |
54
|
|
|
return $this->objects[$name]; |
55
|
|
|
} |
56
|
1 |
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
* @param string $name |
62
|
|
|
*/ |
63
|
|
|
public function clear($name){ |
64
|
|
|
unset($this->objects[$name]); |
65
|
|
|
unset($_SESSION[$name]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function clearAll(){ |
69
|
|
|
foreach ($this->objects as $name=>$value){ |
70
|
|
|
$this->clear($name); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|