1
0

downgrade to kirby v3

This commit is contained in:
Philip Wagner
2024-09-01 10:47:15 +02:00
parent a4b2aece7b
commit af86acb7a1
1085 changed files with 54743 additions and 65042 deletions

View File

@@ -2,7 +2,6 @@
namespace Kirby\Cms;
use Closure;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\F;
use Kirby\Toolkit\Controller;
@@ -28,20 +27,25 @@ class Collections
* has been called, to avoid further
* processing on sequential calls to
* the same collection.
*
* @var array
*/
protected array $cache = [];
protected $cache = [];
/**
* Store of all collections
*
* @var array
*/
protected array $collections = [];
protected $collections = [];
/**
* Magic caller to enable something like
* `$collections->myCollection()`
*
* @return \Kirby\Toolkit\Collection|null
* @todo 5.0 Add return type declaration
* @param string $name
* @param array $arguments
* @return \Kirby\Cms\Collection|null
*/
public function __call(string $name, array $arguments = [])
{
@@ -51,19 +55,23 @@ class Collections
/**
* Loads a collection by name if registered
*
* @return \Kirby\Toolkit\Collection|null
* @todo 5.0 Add deprecation warning when anything else than a Collection is returned
* @todo 6.0 Add PHP return type declaration for `Toolkit\Collection`
* @param string $name
* @param array $data
* @return \Kirby\Cms\Collection|null
*/
public function get(string $name, array $data = [])
{
// if not yet loaded
$this->collections[$name] ??= $this->load($name);
if (isset($this->collections[$name]) === false) {
$this->collections[$name] = $this->load($name);
}
// if not yet cached
if (($this->cache[$name]['data'] ?? null) !== $data) {
if (
isset($this->cache[$name]) === false ||
$this->cache[$name]['data'] !== $data
) {
$controller = new Controller($this->collections[$name]);
$this->cache[$name] = [
'result' => $controller->call(null, $data),
'data' => $data
@@ -80,6 +88,9 @@ class Collections
/**
* Checks if a collection exists
*
* @param string $name
* @return bool
*/
public function has(string $name): bool
{
@@ -90,7 +101,7 @@ class Collections
try {
$this->load($name);
return true;
} catch (NotFoundException) {
} catch (NotFoundException $e) {
return false;
}
}
@@ -99,9 +110,11 @@ class Collections
* Loads collection from php file in a
* given directory or from plugin extension.
*
* @param string $name
* @return mixed
* @throws \Kirby\Exception\NotFoundException
*/
public function load(string $name): mixed
public function load(string $name)
{
$kirby = App::instance();
@@ -109,9 +122,9 @@ class Collections
$file = $kirby->root('collections') . '/' . $name . '.php';
if (is_file($file) === true) {
$collection = F::load($file, allowOutput: false);
$collection = F::load($file);
if ($collection instanceof Closure) {
if (is_a($collection, 'Closure')) {
return $collection;
}
}
@@ -119,7 +132,10 @@ class Collections
// fallback to collections from plugins
$collections = $kirby->extensions('collections');
return $collections[$name] ??
throw new NotFoundException('The collection cannot be found');
if (isset($collections[$name]) === true) {
return $collections[$name];
}
throw new NotFoundException('The collection cannot be found');
}
}