diff --git a/system/src/Grav/Common/Object/ObjectInterface.php b/system/src/Grav/Common/Object/ObjectInterface.php index 2684f77d4..971ee1f57 100644 --- a/system/src/Grav/Common/Object/ObjectInterface.php +++ b/system/src/Grav/Common/Object/ObjectInterface.php @@ -1,7 +1,7 @@ path = $path; + $this->type = $type; + $this->extension = $extension; + } + + /** + * @param string $key * @return array */ - public function load(array $keys) + public function load($key) { - // TODO - return []; + if ($key === null) { + return []; + } + + $file = $this->getFile($key); + $content = (array)$file->content(); + $file->free(); + + return $content; } /** - * @param AbstractObject $object - * @return string|int Id + * @param string $key + * @param array $data + * @return string */ - public function save(AbstractObject $object) + public function save($key, array $data) { - // TODO - return 'xxx'; + $file = $this->getFile($key); + $file->save($data); + $file->free(); + + return $key; } /** - * @param AbstractObject $object + * @param string $key * @return bool */ - public function delete(AbstractObject $object) + public function delete($key) { - // TODO - return false; + $file = $this->getFile($key); + $result = $file->delete(); + $file->free(); + + return $result; } /** - * @param array|int[]|string[] $list + * @param string[] $list * @return array */ public function loadList(array $list) { - // TODO - return []; + $results = []; + foreach ($list as $id) { + $results[$id] = $this->load(['id' => $id]); + } + + return $results; } /** @@ -57,11 +104,32 @@ class FilesystemStorage implements StorageInterface /** * @param array $query - * @return array|int[]|string[] + * @return string[] */ - public function find(array $query) + public function find(array $query, $start = 0, $limit = 0) { // TODO return []; } + + /** + * @param string $key + * @return FileInterface + */ + protected function getFile($key) + { + if ($key === null) { + throw new \RuntimeException('Id not defined'); + } + + $filename = "{$this->path}/{$key}{$this->extension}"; + + /** @var UniformResourceLocator $locator */ + $locator = Grav::instance()['locator']; + + /** @var FileInterface $type */ + $type = $this->type; + + return $type::instance($locator->findResource($filename, true) ?: $locator->findResource($filename, true, true)); + } } diff --git a/system/src/Grav/Common/Object/Storage/StorageInterface.php b/system/src/Grav/Common/Object/Storage/StorageInterface.php index f1889f8f7..c1f72124e 100644 --- a/system/src/Grav/Common/Object/Storage/StorageInterface.php +++ b/system/src/Grav/Common/Object/Storage/StorageInterface.php @@ -1,30 +1,29 @@