Upgrade to 3.2.5
This commit is contained in:
@@ -19,7 +19,6 @@ use Exception;
|
||||
*/
|
||||
class A
|
||||
{
|
||||
|
||||
/**
|
||||
* Appends the given array
|
||||
*
|
||||
@@ -112,6 +111,8 @@ class A
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $separator
|
||||
* @return string
|
||||
*/
|
||||
public static function join($value, $separator = ', ')
|
||||
@@ -535,6 +536,7 @@ class A
|
||||
* // ];
|
||||
* </code>
|
||||
*
|
||||
* @param array ...$arrays
|
||||
* @return array
|
||||
*/
|
||||
public static function extend(...$arrays): array
|
||||
|
@@ -19,7 +19,6 @@ use Exception;
|
||||
*/
|
||||
class Collection extends Iterator implements Countable
|
||||
{
|
||||
|
||||
/**
|
||||
* All registered collection filters
|
||||
*
|
||||
@@ -60,7 +59,7 @@ class Collection extends Iterator implements Countable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debuginfo(): array
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return $this->keys();
|
||||
}
|
||||
@@ -117,13 +116,13 @@ class Collection extends Iterator implements Countable
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $item
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function append(...$args)
|
||||
{
|
||||
if (count($args) === 1) {
|
||||
$this->data[] = $args[0];
|
||||
} elseif (count($args) === 2) {
|
||||
} elseif (count($args) > 1) {
|
||||
$this->set($args[0], $args[1]);
|
||||
}
|
||||
|
||||
@@ -135,7 +134,7 @@ class Collection extends Iterator implements Countable
|
||||
* The last chunk may be smaller
|
||||
*
|
||||
* @param int $size Number of elements per chunk
|
||||
* @return Kirby\Toolkit\Collection A new collection with an element for each chunk and
|
||||
* @return \Kirby\Toolkit\Collection A new collection with an element for each chunk and
|
||||
* a sub collection in each chunk
|
||||
*/
|
||||
public function chunk(int $size)
|
||||
@@ -197,7 +196,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Clone and remove all elements from the collection
|
||||
*
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function empty()
|
||||
{
|
||||
@@ -210,6 +209,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Adds all elements to the collection
|
||||
*
|
||||
* @param mixed $items
|
||||
* @return self
|
||||
*/
|
||||
public function extend($items)
|
||||
@@ -250,6 +250,7 @@ class Collection extends Iterator implements Countable
|
||||
* predefined filter methods.
|
||||
*
|
||||
* @param string $field
|
||||
* @param array ...$args
|
||||
* @return self
|
||||
*/
|
||||
public function filterBy(string $field, ...$args)
|
||||
@@ -409,7 +410,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Returns the elements in reverse order
|
||||
*
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function flip()
|
||||
{
|
||||
@@ -525,7 +526,7 @@ class Collection extends Iterator implements Countable
|
||||
*
|
||||
* @param string $field
|
||||
* @param bool $i
|
||||
* @return Kirby\Toolkit\Collection A new collection with an element for each group and a subcollection in each group
|
||||
* @return \Kirby\Toolkit\Collection A new collection with an element for each group and a subcollection in each group
|
||||
*/
|
||||
public function groupBy($field, bool $i = true)
|
||||
{
|
||||
@@ -596,7 +597,7 @@ class Collection extends Iterator implements Countable
|
||||
* Returns a new object with a limited number of elements
|
||||
*
|
||||
* @param int $limit The number of elements to return
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function limit(int $limit)
|
||||
{
|
||||
@@ -607,7 +608,7 @@ class Collection extends Iterator implements Countable
|
||||
* Map a function to each element
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function map(callable $callback)
|
||||
{
|
||||
@@ -629,8 +630,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Returns a Collection without the given element(s)
|
||||
*
|
||||
* @param args any number of keys, passed as individual arguments
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @param string ...$keys any number of keys, passed as individual arguments
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function not(...$keys)
|
||||
{
|
||||
@@ -645,7 +646,7 @@ class Collection extends Iterator implements Countable
|
||||
* Returns a new object starting from the given offset
|
||||
*
|
||||
* @param int $offset The index to start from
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function offset(int $offset)
|
||||
{
|
||||
@@ -655,7 +656,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Add pagination
|
||||
*
|
||||
* @return Kirby\Toolkit\Collection a sliced set of data
|
||||
* @param array ...$arguments
|
||||
* @return \Kirby\Toolkit\Collection a sliced set of data
|
||||
*/
|
||||
public function paginate(...$arguments)
|
||||
{
|
||||
@@ -668,7 +670,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Get the previously added pagination object
|
||||
*
|
||||
* @return Kirby\Toolkit\Pagination|null
|
||||
* @return \Kirby\Toolkit\Pagination|null
|
||||
*/
|
||||
public function pagination()
|
||||
{
|
||||
@@ -716,7 +718,7 @@ class Collection extends Iterator implements Countable
|
||||
{
|
||||
if (count($args) === 1) {
|
||||
array_unshift($this->data, $args[0]);
|
||||
} elseif (count($args) === 2) {
|
||||
} elseif (count($args) > 1) {
|
||||
$data = $this->data;
|
||||
$this->data = [];
|
||||
$this->set($args[0], $args[1]);
|
||||
@@ -807,7 +809,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Shuffle all elements
|
||||
*
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function shuffle()
|
||||
{
|
||||
@@ -830,7 +832,7 @@ class Collection extends Iterator implements Countable
|
||||
*
|
||||
* @param int $offset The optional index to start the slice from
|
||||
* @param int $limit The optional number of elements to return
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function slice(int $offset = 0, int $limit = null)
|
||||
{
|
||||
@@ -942,7 +944,34 @@ class Collection extends Iterator implements Countable
|
||||
$params[] = $field['flags'] ?? SORT_NATURAL | SORT_FLAG_CASE;
|
||||
}
|
||||
|
||||
$params[] = &$array;
|
||||
// check what kind of collection items we have; only check for the first
|
||||
// item for better performance (we assume that all collection items are
|
||||
// of the same type)
|
||||
$firstItem = $collection->first();
|
||||
if (is_object($firstItem) === true) {
|
||||
// avoid the "Nesting level too deep - recursive dependency?" error
|
||||
// when PHP tries to sort by the objects directly (in case all other
|
||||
// fields are 100 % equal for some elements)
|
||||
if (method_exists($firstItem, '__toString') === true) {
|
||||
// PHP can easily convert the objects to strings, so it should
|
||||
// compare them as strings instead of as objects to avoid the recursion
|
||||
$params[] = &$array;
|
||||
$params[] = SORT_STRING;
|
||||
} else {
|
||||
// we can't convert the objects to strings, so we need a fallback:
|
||||
// custom fictional field that is guaranteed to have a unique value
|
||||
// for each item; WARNING: may lead to slightly wrong sorting results
|
||||
// and is therefore only used as a fallback if we don't have another way
|
||||
$params[] = range(1, count($array));
|
||||
$params[] = SORT_ASC;
|
||||
$params[] = SORT_NUMERIC;
|
||||
|
||||
$params[] = &$array;
|
||||
}
|
||||
} else {
|
||||
// collection items are scalar or array; no correction necessary
|
||||
$params[] = &$array;
|
||||
}
|
||||
|
||||
// array_multisort receives $params as separate params
|
||||
array_multisort(...$params);
|
||||
@@ -955,6 +984,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Converts the object into an array
|
||||
*
|
||||
* @param Closure $map
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(Closure $map = null): array
|
||||
@@ -1000,8 +1030,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Alias for $this->not()
|
||||
*
|
||||
* @param args any number of keys, passed as individual arguments
|
||||
* @return Kirby\Toolkit\Collection
|
||||
* @param string ...$keys any number of keys, passed as individual arguments
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function without(...$keys)
|
||||
{
|
||||
|
@@ -17,7 +17,6 @@ use TypeError;
|
||||
*/
|
||||
class Component
|
||||
{
|
||||
|
||||
/**
|
||||
* Registry for all component mixins
|
||||
*
|
||||
@@ -138,7 +137,7 @@ class Component
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debuginfo(): array
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
@@ -208,7 +207,9 @@ class Component
|
||||
protected function applyComputed(array $computed): void
|
||||
{
|
||||
foreach ($computed as $computedName => $computedFunction) {
|
||||
$this->$computedName = $this->computed[$computedName] = $computedFunction->call($this);
|
||||
if (is_callable($computedFunction) === true) {
|
||||
$this->$computedName = $this->computed[$computedName] = $computedFunction->call($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,6 @@ use Throwable;
|
||||
*/
|
||||
class Dir
|
||||
{
|
||||
|
||||
/**
|
||||
* Ignore when scanning directories
|
||||
*
|
||||
@@ -84,6 +83,7 @@ class Dir
|
||||
* Get all subdirectories
|
||||
*
|
||||
* @param string $dir
|
||||
* @param array $ignore
|
||||
* @param bool $absolute
|
||||
* @return array
|
||||
*/
|
||||
@@ -102,6 +102,7 @@ class Dir
|
||||
* Get all files
|
||||
*
|
||||
* @param string $dir
|
||||
* @param array $ignore
|
||||
* @param bool $absolute
|
||||
* @return array
|
||||
*/
|
||||
@@ -120,7 +121,9 @@ class Dir
|
||||
* Read the directory and all subdirectories
|
||||
*
|
||||
* @param string $dir
|
||||
* @param bool $recursive
|
||||
* @param array $ignore
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public static function index(string $dir, bool $recursive = false, array $ignore = null, string $path = null)
|
||||
@@ -145,6 +148,7 @@ class Dir
|
||||
/**
|
||||
* Checks if the folder has any contents
|
||||
*
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEmpty(string $dir): bool
|
||||
|
@@ -23,7 +23,6 @@ use Zend\Escaper\Escaper;
|
||||
*/
|
||||
class Escape
|
||||
{
|
||||
|
||||
/**
|
||||
* Escape common HTML attributes data
|
||||
*
|
||||
|
@@ -48,6 +48,7 @@ class F
|
||||
'py',
|
||||
'scss',
|
||||
'xml',
|
||||
'yaml',
|
||||
'yml',
|
||||
],
|
||||
'document' => [
|
||||
@@ -102,7 +103,7 @@ class F
|
||||
],
|
||||
];
|
||||
|
||||
public static $units = ['B','kB','MB','GB','TB','PB', 'EB', 'ZB', 'YB'];
|
||||
public static $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
/**
|
||||
* Appends new content to an existing file
|
||||
@@ -130,7 +131,7 @@ class F
|
||||
/**
|
||||
* Copy a file to a new location.
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
* @param boolean $force
|
||||
* @return boolean
|
||||
@@ -359,6 +360,7 @@ class F
|
||||
* Loads a file and returns the result
|
||||
*
|
||||
* @param string $file
|
||||
* @param mixed $fallback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function load(string $file, $fallback = null)
|
||||
@@ -573,6 +575,31 @@ class F
|
||||
return $realpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative path of the file
|
||||
* starting after $in
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
public static function relativepath(string $file, string $in = null): string
|
||||
{
|
||||
if (empty($in) === true) {
|
||||
return basename($file);
|
||||
}
|
||||
|
||||
// windows
|
||||
$file = str_replace('\\', '/', $file);
|
||||
$in = str_replace('\\', '/', $in);
|
||||
|
||||
if (Str::contains($file, $in) === false) {
|
||||
return basename($file);
|
||||
}
|
||||
|
||||
return Str::after($file, $in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file
|
||||
*
|
||||
@@ -633,6 +660,7 @@ class F
|
||||
* building a glob based on the path
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $pattern
|
||||
* @return array
|
||||
*/
|
||||
public static function similar(string $path, string $pattern = '*'): array
|
||||
@@ -708,7 +736,7 @@ class F
|
||||
throw new Exception('The ZipArchive class is not available');
|
||||
}
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$zip = new ZipArchive();
|
||||
|
||||
if ($zip->open($file) === true) {
|
||||
$zip->extractTo($to);
|
||||
|
@@ -14,7 +14,6 @@ namespace Kirby\Toolkit;
|
||||
*/
|
||||
abstract class Facade
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the instance that should be
|
||||
* available statically
|
||||
|
@@ -16,7 +16,6 @@ use Exception;
|
||||
*/
|
||||
class File
|
||||
{
|
||||
|
||||
/**
|
||||
* Absolute file path
|
||||
*
|
||||
@@ -39,7 +38,7 @@ class File
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debuginfo(): array
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@ use Kirby\Http\Url;
|
||||
*/
|
||||
class Html
|
||||
{
|
||||
|
||||
/**
|
||||
* An internal store for a html entities translation table
|
||||
*
|
||||
|
@@ -16,7 +16,6 @@ use Exception;
|
||||
*/
|
||||
class I18n
|
||||
{
|
||||
|
||||
/**
|
||||
* Custom loader function
|
||||
*
|
||||
@@ -116,7 +115,7 @@ class I18n
|
||||
return $key[$locale];
|
||||
}
|
||||
if (is_array($fallback)) {
|
||||
return $fallback[$locale] ?? null;
|
||||
return $fallback[$locale] ?? $fallback['en'] ?? reset($fallback);
|
||||
}
|
||||
return $fallback;
|
||||
}
|
||||
@@ -196,6 +195,7 @@ class I18n
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $count
|
||||
* @param string $locale
|
||||
* @return mixed
|
||||
*/
|
||||
public static function translateCount(string $key, int $count, string $locale = null)
|
||||
|
@@ -15,7 +15,6 @@ namespace Kirby\Toolkit;
|
||||
*/
|
||||
class Iterator implements \Iterator
|
||||
{
|
||||
|
||||
/**
|
||||
* The data array
|
||||
*
|
||||
@@ -162,7 +161,7 @@ class Iterator implements \Iterator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debuginfo(): array
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
@@ -106,6 +106,8 @@ class Mime
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
|
||||
'xsl' => 'text/xml',
|
||||
'yaml' => ['application/yaml', 'text/yaml'],
|
||||
'yml' => ['application/yaml', 'text/yaml'],
|
||||
'zip' => ['application/x-zip', 'application/zip', 'application/x-zip-compressed'],
|
||||
];
|
||||
|
||||
@@ -122,12 +124,12 @@ class Mime
|
||||
// fixing map
|
||||
$map = [
|
||||
'text/html' => [
|
||||
'svg' => [Mime::class, 'fromSvg'],
|
||||
'svg' => ['Kirby\Toolkit\Mime', 'fromSvg'],
|
||||
],
|
||||
'text/plain' => [
|
||||
'css' => 'text/css',
|
||||
'json' => 'application/json',
|
||||
'svg' => [Mime::class, 'fromSvg'],
|
||||
'svg' => ['Kirby\Toolkit\Mime', 'fromSvg'],
|
||||
],
|
||||
'text/x-asm' => [
|
||||
'css' => 'text/css'
|
||||
@@ -219,6 +221,8 @@ class Mime
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $mime
|
||||
* @param string $pattern
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isAccepted(string $mime, string $pattern): bool
|
||||
@@ -284,6 +288,7 @@ class Mime
|
||||
* Returns the mime type of a file
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $extension
|
||||
* @return string|false
|
||||
*/
|
||||
public static function type(string $file, string $extension = null)
|
||||
|
@@ -16,7 +16,6 @@ use stdClass;
|
||||
*/
|
||||
class Obj extends stdClass
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -46,7 +45,7 @@ class Obj extends stdClass
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debuginfo(): array
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
@@ -97,6 +96,7 @@ class Obj extends stdClass
|
||||
/**
|
||||
* Converts the object to a json string
|
||||
*
|
||||
* @param mixed ...$arguments
|
||||
* @return string
|
||||
*/
|
||||
public function toJson(...$arguments): string
|
||||
|
@@ -15,7 +15,6 @@ use Exception;
|
||||
*/
|
||||
class Pagination
|
||||
{
|
||||
|
||||
/**
|
||||
* The current page
|
||||
*
|
||||
@@ -54,8 +53,8 @@ class Pagination
|
||||
* Creates a pagination instance for the given
|
||||
* collection with a flexible argument api
|
||||
*
|
||||
* @param Kirby\CmToolkits\Collection $collection
|
||||
* @param ...mixed $arguments
|
||||
* @param \Kirby\Toolkit\Collection $collection
|
||||
* @param mixed ...$arguments
|
||||
* @return self
|
||||
*/
|
||||
public static function for(Collection $collection, ...$arguments)
|
||||
@@ -116,8 +115,8 @@ class Pagination
|
||||
/**
|
||||
* Getter and setter for the current page
|
||||
*
|
||||
* @param int|null $page
|
||||
* @return int|Pagination
|
||||
* @param int|null $page
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
*/
|
||||
public function page(int $page = null)
|
||||
{
|
||||
@@ -140,8 +139,8 @@ class Pagination
|
||||
/**
|
||||
* Getter and setter for the total number of items
|
||||
*
|
||||
* @param int|null $total
|
||||
* @return int|Pagination
|
||||
* @param int|null $total
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
*/
|
||||
public function total(int $total = null)
|
||||
{
|
||||
@@ -160,8 +159,8 @@ class Pagination
|
||||
/**
|
||||
* Getter and setter for the number of items per page
|
||||
*
|
||||
* @param int|null $limit
|
||||
* @return int|Pagination
|
||||
* @param int|null $limit
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
*/
|
||||
public function limit(int $limit = null)
|
||||
{
|
||||
@@ -256,6 +255,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if the given page exists
|
||||
*
|
||||
* @param int $page
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPage(int $page): bool
|
||||
@@ -344,6 +344,7 @@ class Pagination
|
||||
/**
|
||||
* Creates a range of page numbers for Google-like pagination
|
||||
*
|
||||
* @param int $range
|
||||
* @return array
|
||||
*/
|
||||
public function range(int $range = 5): array
|
||||
@@ -376,6 +377,7 @@ class Pagination
|
||||
/**
|
||||
* Returns the first page of the created range
|
||||
*
|
||||
* @param int $range
|
||||
* @return int
|
||||
*/
|
||||
public function rangeStart(int $range = 5): int
|
||||
@@ -386,6 +388,7 @@ class Pagination
|
||||
/**
|
||||
* Returns the last page of the created range
|
||||
*
|
||||
* @param int $range
|
||||
* @return int
|
||||
*/
|
||||
public function rangeEnd(int $range = 5): int
|
||||
|
@@ -15,19 +15,18 @@ namespace Kirby\Toolkit;
|
||||
*/
|
||||
class Silo
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $data = [];
|
||||
|
||||
/**
|
||||
* Setter for new data.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
* 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) {
|
||||
|
@@ -17,7 +17,6 @@ use Exception;
|
||||
*/
|
||||
class Str
|
||||
{
|
||||
|
||||
/**
|
||||
* Language translation table
|
||||
*
|
||||
@@ -804,7 +803,7 @@ class Str
|
||||
{
|
||||
if (!ctype_lower($value)) {
|
||||
$value = preg_replace('/\s+/u', '', ucwords($value));
|
||||
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
|
||||
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
@@ -883,6 +882,8 @@ class Str
|
||||
* @param array $data Associative array with placeholders as
|
||||
* keys and replacements as values
|
||||
* @param string $fallback A fallback if a token does not have any matches
|
||||
* @param string $start Placeholder start characters
|
||||
* @param string $end Placeholder end characters
|
||||
* @return string The filled-in string
|
||||
*/
|
||||
public static function template(string $string = null, array $data = [], string $fallback = null, string $start = '{{', string $end = '}}'): string
|
||||
@@ -896,6 +897,33 @@ class Str
|
||||
}, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a filesize string with shortcuts
|
||||
* like M, G or K to an integer value
|
||||
*
|
||||
* @param mixed $size
|
||||
* @return int
|
||||
*/
|
||||
public static function toBytes($size): int
|
||||
{
|
||||
$size = trim($size);
|
||||
$last = strtolower($size[strlen($size)-1] ?? null);
|
||||
$size = (int)$size;
|
||||
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$size *= 1024;
|
||||
// no break
|
||||
case 'm':
|
||||
$size *= 1024;
|
||||
// no break
|
||||
case 'k':
|
||||
$size *= 1024;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the string to the given type
|
||||
*
|
||||
@@ -917,10 +945,10 @@ class Str
|
||||
return filter_var($string, FILTER_VALIDATE_BOOLEAN);
|
||||
case 'double':
|
||||
case 'float':
|
||||
return floatval($string);
|
||||
return (float)$string;
|
||||
case 'int':
|
||||
case 'integer':
|
||||
return intval($string);
|
||||
return (int)$string;
|
||||
}
|
||||
|
||||
return (string)$string;
|
||||
@@ -1020,7 +1048,7 @@ class Str
|
||||
{
|
||||
return preg_replace_callback('|([^\s])\s+([^\s]+)\s*$|u', function ($matches) {
|
||||
if (static::contains($matches[2], '-')) {
|
||||
return $matches[1] . ' ' . str_replace('-', '‑', $matches[2]);
|
||||
return $matches[1] . ' ' . str_replace('-', '‑', $matches[2]);
|
||||
} else {
|
||||
return $matches[1] . ' ' . $matches[2];
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ use Throwable;
|
||||
*/
|
||||
class Tpl
|
||||
{
|
||||
|
||||
/**
|
||||
* Renders the template
|
||||
*
|
||||
|
@@ -4,7 +4,6 @@ namespace Kirby\Toolkit;
|
||||
|
||||
use Exception;
|
||||
use Kirby\Http\Idn;
|
||||
use Kirby\Toolkit\Str;
|
||||
use ReflectionFunction;
|
||||
use Throwable;
|
||||
|
||||
@@ -19,7 +18,6 @@ use Throwable;
|
||||
*/
|
||||
class V
|
||||
{
|
||||
|
||||
/**
|
||||
* An array with all installed validators
|
||||
*
|
||||
@@ -245,9 +243,9 @@ V::$validators = [
|
||||
*/
|
||||
'date' => function ($value): bool {
|
||||
$date = date_parse($value);
|
||||
return ($date !== false &&
|
||||
return $date !== false &&
|
||||
$date['error_count'] === 0 &&
|
||||
$date['warning_count'] === 0);
|
||||
$date['warning_count'] === 0;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -16,7 +16,6 @@ use Throwable;
|
||||
*/
|
||||
class View
|
||||
{
|
||||
|
||||
/**
|
||||
* The absolute path to the view file
|
||||
*
|
||||
|
@@ -13,7 +13,6 @@ namespace Kirby\Toolkit;
|
||||
*/
|
||||
class Xml
|
||||
{
|
||||
|
||||
/**
|
||||
* Conversion table for html entities
|
||||
*
|
||||
@@ -186,12 +185,13 @@ class Xml
|
||||
* @param string $name
|
||||
* @param mixed $content
|
||||
* @param array $attr
|
||||
* @param mixed $indent
|
||||
* @return string
|
||||
*/
|
||||
public static function tag(string $name, $content = null, array $attr = null, $indent = null): string
|
||||
{
|
||||
$attr = Html::attr($attr);
|
||||
$start = '<' . $name . ($attr ? ' ' . $attr : null) . '>';
|
||||
$start = '<' . $name . ($attr ? ' ' . $attr : null) . '>';
|
||||
$end = '</' . $name . '>';
|
||||
|
||||
if (is_array($content) === true) {
|
||||
|
Reference in New Issue
Block a user