diff --git a/system/src/Grav/Common/Object/AbstractObject.php b/system/src/Grav/Common/Object/AbstractObject.php index 82cee22c8..c4ef3487b 100644 --- a/system/src/Grav/Common/Object/AbstractObject.php +++ b/system/src/Grav/Common/Object/AbstractObject.php @@ -99,7 +99,10 @@ abstract class AbstractObject implements ObjectInterface // If we are creating or loading a new item or we load instance by alternative keys, we need to create a new object. if (!$keys || is_array($keys) || (is_scalar($keys) && !isset(static::$instances[$keys]))) { $c = get_called_class(); - $instance = new $c($keys); + + /** @var ObjectStorageTrait $instance */ + $instance = new $c(); + $instance->load($keys); /** @var Object $instance */ if (!$instance->exists()) return $instance; @@ -258,7 +261,7 @@ abstract class AbstractObject implements ObjectInterface * set the instance key value is used. * @param bool $getKey Internal parameter, please do not use. * - * @return boolean True on success, false if the object doesn't exist. + * @return bool True on success, false if the object doesn't exist. */ public function load($keys = null, $getKey = true) { @@ -302,7 +305,8 @@ abstract class AbstractObject implements ObjectInterface * * Before saving the object, this method checks if object can be safely saved. * - * @return boolean True on success. + * @params bool $includeChildren + * @return bool True on success. */ public function save($includeChildren = false) { @@ -346,8 +350,8 @@ abstract class AbstractObject implements ObjectInterface /** * Method to delete the object from the database. * - * @param bool $includeChildren - * @return boolean True on success. + * @param bool $includeChildren + * @return bool True on success. */ public function delete($includeChildren = false) { @@ -379,7 +383,7 @@ abstract class AbstractObject implements ObjectInterface * Child classes should override this method to make sure the data they are storing in the storage is safe and as * expected before saving the object. * - * @return boolean True if the instance is sane and able to be stored in the storage. + * @return bool True if the instance is sane and able to be stored in the storage. */ public function check($includeChildren = false) { @@ -478,7 +482,7 @@ abstract class AbstractObject implements ObjectInterface * @param array * @return string */ - abstract protected function getStorageKey(array $keys = null); + abstract public function getStorageKey(array $keys = []); /** * @return StorageInterface diff --git a/system/src/Grav/Common/Object/Storage/FilesystemStorage.php b/system/src/Grav/Common/Object/Storage/FilesystemStorage.php index dd221478f..a9ee5495c 100644 --- a/system/src/Grav/Common/Object/Storage/FilesystemStorage.php +++ b/system/src/Grav/Common/Object/Storage/FilesystemStorage.php @@ -34,6 +34,21 @@ class FilesystemStorage implements StorageInterface $this->extension = $extension; } + /** + * @param string $key + * @return bool + */ + public function exists($key) + { + if ($key === null) { + return false; + } + + $file = $this->getFile($key); + + return $file->exists(); + } + /** * @param string $key * @return array @@ -104,6 +119,8 @@ class FilesystemStorage implements StorageInterface /** * @param array $query + * @param int $start + * @param int $limit * @return string[] */ public function find(array $query, $start = 0, $limit = 0) diff --git a/system/src/Grav/Common/Object/Storage/StorageInterface.php b/system/src/Grav/Common/Object/Storage/StorageInterface.php index c1f72124e..a13ad396c 100644 --- a/system/src/Grav/Common/Object/Storage/StorageInterface.php +++ b/system/src/Grav/Common/Object/Storage/StorageInterface.php @@ -3,6 +3,12 @@ namespace Grav\Common\Object\Storage; interface StorageInterface { + /** + * @param string $key + * @return bool + */ + public function exists($key); + /** * @param string $key * @return array