1 | <?php |
||
21 | abstract class AbstractDataStorage implements DataStorageInterface |
||
22 | { |
||
23 | /** @var DataAdapterInterface */ |
||
24 | private $defaultAdapter; |
||
25 | /** @var DataEntityInterface */ |
||
26 | private $entityPrototype; |
||
27 | /** @var string */ |
||
28 | protected $dataGroup; |
||
29 | /** @var string */ |
||
30 | protected $idKey; |
||
31 | /** @var bool */ |
||
32 | protected $initialized = false; |
||
33 | |||
34 | /** |
||
35 | * UserMetaStorage constructor. The DataEntity SHOULD not be used directly unless it is required to represent |
||
36 | * the same instance all the time. |
||
37 | * |
||
38 | * @param DataAdapterInterface $defaultAdapter |
||
39 | * @param DataEntityInterface $entityPrototype |
||
40 | */ |
||
41 | 1 | final public function __construct(DataAdapterInterface $defaultAdapter, DataEntityInterface $entityPrototype) |
|
48 | |||
49 | /** |
||
50 | * Special initialization method. The constructor MUST call it. |
||
51 | * |
||
52 | * @return DataStorageInterface |
||
53 | */ |
||
54 | 1 | public function init() |
|
66 | |||
67 | /** |
||
68 | * Checks if the storage is initialized. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 1 | final public function initialized() |
|
76 | |||
77 | /** |
||
78 | * Returns the DataAdapter instance. |
||
79 | * |
||
80 | * @return DataAdapterInterface |
||
81 | */ |
||
82 | 1 | final public function getDataAdapter() |
|
86 | |||
87 | /** |
||
88 | * Creates an empty entity. Should be use by getters. |
||
89 | * |
||
90 | * @return DataEntityInterface |
||
91 | */ |
||
92 | 1 | final public function createEntity() |
|
96 | |||
97 | /** |
||
98 | * Populates an entity with storage data. |
||
99 | * |
||
100 | * @param DataEntityInterface $entity |
||
101 | * @param array $data |
||
102 | */ |
||
103 | abstract protected function populateEntity(DataEntityInterface &$entity, array $data); |
||
104 | } |
||
105 |