1 | <?php |
||
49 | class Repository implements RepositoryInterface |
||
50 | { |
||
51 | /** |
||
52 | * Apparat base URL |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $_url = null; |
||
57 | /** |
||
58 | * Adapter strategy |
||
59 | * |
||
60 | * @var AdapterStrategyInterface |
||
61 | */ |
||
62 | protected $_adapterStrategy = null; |
||
63 | /** |
||
64 | * Instance specific object cache |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $_objectCache = []; |
||
69 | |||
70 | /******************************************************************************* |
||
71 | * PUBLIC METHODS |
||
72 | *******************************************************************************/ |
||
73 | |||
74 | /** |
||
75 | * Repository constructor |
||
76 | * |
||
77 | * @param string $url Apparat base URL |
||
78 | * @param array $config Adapter strategy configuration |
||
79 | */ |
||
80 | 10 | public function __construct( |
|
87 | |||
88 | /** |
||
89 | * Find objects by selector |
||
90 | * |
||
91 | * @param SelectorInterface $selector Object selector |
||
92 | * @return Collection Object collection |
||
93 | */ |
||
94 | 2 | public function findObjects(SelectorInterface $selector) |
|
98 | |||
99 | /** |
||
100 | * Add an object to the repository |
||
101 | * |
||
102 | * @param ObjectInterface $object Object |
||
103 | * @return boolean Success |
||
104 | */ |
||
105 | public function addObject(ObjectInterface $object) |
||
109 | |||
110 | /** |
||
111 | * Delete and object from the repository |
||
112 | * |
||
113 | * @param ObjectInterface $object Object |
||
114 | * @return boolean Success |
||
115 | */ |
||
116 | public function deleteObject(ObjectInterface $object) |
||
120 | |||
121 | /** |
||
122 | * Update an object in the repository |
||
123 | * |
||
124 | * @param ObjectInterface $object Object |
||
125 | * @return bool Success |
||
126 | */ |
||
127 | public function updateObject(ObjectInterface $object) |
||
131 | |||
132 | /** |
||
133 | * Load an object from this repository |
||
134 | * |
||
135 | * @param PathInterface $path Object path |
||
136 | * @return ObjectInterface Object |
||
137 | */ |
||
138 | 4 | public function loadObject(PathInterface $path) |
|
139 | { |
||
140 | // TODO: Really OK to cache? (Immutability ...) |
||
141 | 4 | if (empty($this->_objectCache[$path->getId()->getId()])) { |
|
142 | 2 | $this->_objectCache[$path->getId()->getId()] = Kernel::create(Service::class)->getObjectManager()->loadObject( |
|
143 | 2 | new RepositoryPath( |
|
144 | 2 | $this, |
|
145 | $path |
||
146 | 2 | ) |
|
147 | 2 | ); |
|
148 | 1 | } |
|
149 | |||
150 | 3 | return $this->_objectCache[$path->getId()->getId()]; |
|
151 | } |
||
152 | |||
153 | /** |
||
154 | * Return the repository's adapter strategy |
||
155 | * |
||
156 | * @return AdapterStrategyInterface Adapter strategy |
||
157 | */ |
||
158 | 2 | public function getAdapterStrategy() |
|
162 | |||
163 | /** |
||
164 | * Return the repository URL (relative to Apparat base URL) |
||
165 | * |
||
166 | * @return string Repository URL |
||
167 | */ |
||
168 | 1 | public function getUrl() |
|
172 | } |
||
173 |