1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Model
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Registry\Registry;
13
14 /**
15 * Joomla Platform Base Model Class
16 *
17 * @since 12.1
18 */
19 abstract class JModelBase implements JModel
20 {
21 /**
22 * The model state.
23 *
24 * @var Registry
25 * @since 12.1
26 */
27 protected $state;
28
29 /**
30 * Instantiate the model.
31 *
32 * @param Registry $state The model state.
33 *
34 * @since 12.1
35 */
36 public function __construct(Registry $state = null)
37 {
38 // Setup the model.
39 $this->state = isset($state) ? $state : $this->loadState();
40 }
41
42 /**
43 * Get the model state.
44 *
45 * @return Registry The state object.
46 *
47 * @since 12.1
48 */
49 public function getState()
50 {
51 return $this->state;
52 }
53
54 /**
55 * Set the model state.
56 *
57 * @param Registry $state The state object.
58 *
59 * @return void
60 *
61 * @since 12.1
62 */
63 public function setState(Registry $state)
64 {
65 $this->state = $state;
66 }
67
68 /**
69 * Load the model state.
70 *
71 * @return Registry The state object.
72 *
73 * @since 12.1
74 */
75 protected function loadState()
76 {
77 return new Registry;
78 }
79 }
80