Added Flex[Name]::getFlexType() to all flex classes to have the interface for all Flex classes

This commit is contained in:
Matias Griese
2019-03-26 07:50:54 +02:00
parent 5fbd252db9
commit 354d6f307c
7 changed files with 33 additions and 13 deletions

View File

@@ -5,6 +5,7 @@
* Added `Content-Type: application/json` body support for PSR-7 `ServerRequest`
1. [](#bugfix)
* Fixed `Undefined method closure::fields()` when getting avatar for user, thanks @Romarain [#2422](https://github.com/getgrav/grav/issues/2422)
* Grav 1.6: Added `Flex[Class]::getFlexType()` to all flex classes to have the interface for all Flex classes
# v1.6.0-rc.4
## 03/20/2019

View File

@@ -63,7 +63,7 @@ class Flex implements \Countable
*/
public function addDirectory(FlexDirectory $directory)
{
$this->types[$directory->getType()] = $directory;
$this->types[$directory->getFlexType()] = $directory;
return $this;
}

View File

@@ -87,7 +87,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
parent::__construct($entries);
if ($directory) {
$this->setFlexDirectory($directory)->setKey($directory->getType());
$this->setFlexDirectory($directory)->setKey($directory->getFlexType());
}
}
@@ -129,7 +129,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
*/
public function getFlexType(): string
{
return $this->_flexDirectory->getType();
return $this->_flexDirectory->getFlexType();
}
/**

View File

@@ -91,8 +91,19 @@ class FlexDirectory implements FlexAuthorizeInterface
/**
* @return string
* @deprecated 1.6 Use ->getFlexType() method instead.
*/
public function getType(): string
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use ->getFlexType() method instead', E_USER_DEPRECATED);
return $this->type;
}
/**
* @return string
*/
public function getFlexType(): string
{
return $this->type;
}
@@ -102,7 +113,7 @@ class FlexDirectory implements FlexAuthorizeInterface
*/
public function getTitle(): string
{
return $this->getBlueprintInternal()->get('title', ucfirst($this->getType()));
return $this->getBlueprintInternal()->get('title', ucfirst($this->getFlexType()));
}
/**
@@ -312,13 +323,13 @@ class FlexDirectory implements FlexAuthorizeInterface
if (Utils::isAdminPlugin()) {
$key = substr($key, 0, -1);
}
$cache = new DoctrineCache($gravCache->getCacheDriver(), 'flex-objects-' . $this->getType() . $key, $timeout);
$cache = new DoctrineCache($gravCache->getCacheDriver(), 'flex-objects-' . $this->getFlexType() . $key, $timeout);
} catch (\Exception $e) {
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
$debugger->addException($e);
$cache = new MemoryCache('flex-objects-' . $this->getType());
$cache = new MemoryCache('flex-objects-' . $this->getFlexType());
}
// Disable cache key validation.

View File

@@ -45,7 +45,7 @@ class FlexForm implements FlexFormInterface
{
$this->name = $name;
$this->form = $form;
$uniqueId = $object->exists() ? $object->getStorageKey() : "{$object->getType()}:new";
$uniqueId = $object->exists() ? $object->getStorageKey() : "{$object->getFlexType()}:new";
$this->setObject($object);
$this->setId($this->getName());
$this->setUniqueId(md5($uniqueId));
@@ -73,7 +73,7 @@ class FlexForm implements FlexFormInterface
$object = $this->getObject();
$name = $this->name ?: 'object';
return "flex-{$object->getType()}-{$name}";
return "flex-{$object->getFlexType()}-{$name}";
}
/**
@@ -101,6 +101,14 @@ class FlexForm implements FlexFormInterface
return $value ?? $this->getObject()->value($name);
}
/**
* @return string
*/
public function getFlexType(): string
{
return $this->object->getFlexType();
}
/**
* @return FlexObjectInterface
*/

View File

@@ -104,7 +104,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
public function getFlexType(): string
{
return $this->_flexDirectory->getType();
return $this->_flexDirectory->getFlexType();
}
/**
@@ -171,7 +171,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
{
// Get storage keys for the objects.
$keys = [];
$type = $this->_flexDirectory->getType() . '.obj:';
$type = $this->_flexDirectory->getFlexType() . '.obj:';
foreach ($this->getEntries() as $key => $value) {
$keys[$key] = $value['flex_key'] ?? $type . $value['storage_key'];
@@ -191,7 +191,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
return $this;
}
$type = $keyField === 'flex_key' ? $this->_flexDirectory->getType() . '.obj:' : '';
$type = $keyField === 'flex_key' ? $this->_flexDirectory->getFlexType() . '.obj:' : '';
$entries = [];
foreach ($this->getEntries() as $key => $value) {
if (!isset($value['key'])) {

View File

@@ -115,7 +115,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*/
public function getFlexType(): string
{
return $this->_flexDirectory->getType();
return $this->_flexDirectory->getFlexType();
}
/**
@@ -186,7 +186,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*/
public function getFlexKey(): string
{
return $this->_storage['flex_key'] ?? $this->_flexDirectory->getType() . '.obj:' . $this->getStorageKey();
return $this->_storage['flex_key'] ?? $this->_flexDirectory->getFlexType() . '.obj:' . $this->getStorageKey();
}
/**