mirror of
https://github.com/getgrav/grav.git
synced 2026-03-05 12:01:37 +01:00
Add FilesystemStorage::exists()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user