first version

This commit is contained in:
Bastian Allgeier
2019-01-13 23:17:34 +01:00
commit 01277f79f2
595 changed files with 82913 additions and 0 deletions

74
kirby/src/Toolkit/Silo.php Executable file
View File

@@ -0,0 +1,74 @@
<?php
namespace Kirby\Toolkit;
/**
* The Silo class is a core class to handle
* setting, getting and removing static data of
* a singleton.
*
* @package Kirby Toolkit
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class Silo
{
/**
* @var array
*/
public static $data = [];
/**
* Setter for new data.
*
* @param string|array $key
* @param mixed $value
* @return array
*/
public static function set($key, $value = null): array
{
if (is_array($key) === true) {
return static::$data = array_merge(static::$data, $key);
} else {
static::$data[$key] = $value;
return static::$data;
}
}
/**
* @param string|array $key
* @param mixed $default
* @return mixed
*/
public static function get($key = null, $default = null)
{
if ($key === null) {
return static::$data;
}
return A::get(static::$data, $key, $default);
}
/**
* Removes an item from the data array
*
* @param string|null $key
* @return array
*/
public static function remove(string $key = null): array
{
// reset the entire array
if ($key === true) {
return static::$data = [];
}
// unset a single key
unset(static::$data[$key]);
// return the array without the removed key
return static::$data;
}
}