1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette;
9:
10: use Nette;
11:
12:
13: /**
14: * Defines an object that has a modifiable and a read-only (frozen) state.
15: *
16: * @author David Grudl
17: *
18: * @property-read bool $frozen
19: * @deprecated
20: */
21: abstract class FreezableObject extends Object implements IFreezable
22: {
23: /** @var bool */
24: private $frozen = FALSE;
25:
26:
27: /**
28: * Makes the object unmodifiable.
29: * @return void
30: */
31: public function freeze()
32: {
33: $this->frozen = TRUE;
34: }
35:
36:
37: /**
38: * Is the object unmodifiable?
39: * @return bool
40: */
41: public function isFrozen()
42: {
43: return $this->frozen;
44: }
45:
46:
47: /**
48: * Creates a modifiable clone of the object.
49: * @return void
50: */
51: public function __clone()
52: {
53: $this->frozen = FALSE;
54: }
55:
56:
57: /**
58: * @return void
59: */
60: protected function updating()
61: {
62: if ($this->frozen) {
63: $class = get_class($this);
64: throw new InvalidStateException("Cannot modify a frozen object $class.");
65: }
66: }
67:
68: }
69: