Upgrade to 3.3.0
This commit is contained in:
@@ -51,11 +51,11 @@ class A
|
||||
* // result: ['cat' => 'miao', 'dog' => 'wuff'];
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param mixed $key The key to look for
|
||||
* @param mixed $default Optional default value, which should be
|
||||
* returned if no element has been found
|
||||
* @return mixed
|
||||
* @param array $array The source array
|
||||
* @param mixed $key The key to look for
|
||||
* @param mixed $default Optional default value, which should be
|
||||
* returned if no element has been found
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($array, $key, $default = null)
|
||||
{
|
||||
@@ -130,12 +130,12 @@ class A
|
||||
/**
|
||||
* Merges arrays recursively
|
||||
*
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
* @param boolean $mode Behavior for elements with numeric keys;
|
||||
* A::MERGE_APPEND: elements are appended, keys are reset;
|
||||
* A::MERGE_OVERWRITE: elements are overwritten, keys are preserved
|
||||
* A::MERGE_REPLACE: non-associative arrays are completely replaced
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
* @param bool $mode Behavior for elements with numeric keys;
|
||||
* A::MERGE_APPEND: elements are appended, keys are reset;
|
||||
* A::MERGE_OVERWRITE: elements are overwritten, keys are preserved
|
||||
* A::MERGE_REPLACE: non-associative arrays are completely replaced
|
||||
* @return array
|
||||
*/
|
||||
public static function merge($array1, $array2, $mode = A::MERGE_APPEND)
|
||||
@@ -196,10 +196,10 @@ class A
|
||||
* // result: ['homer', 'marge', 'lisa'];
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param string $key The key name of the column to extract
|
||||
* @return array The result array with all values
|
||||
* from that column.
|
||||
* @param array $array The source array
|
||||
* @param string $key The key name of the column to extract
|
||||
* @return array The result array with all values
|
||||
* from that column.
|
||||
*/
|
||||
public static function pluck(array $array, string $key)
|
||||
{
|
||||
@@ -243,8 +243,8 @@ class A
|
||||
* // ];
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @return array The shuffled result array
|
||||
* @param array $array The source array
|
||||
* @return array The shuffled result array
|
||||
*/
|
||||
public static function shuffle(array $array): array
|
||||
{
|
||||
@@ -275,8 +275,8 @@ class A
|
||||
* // first: 'miao'
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @return mixed The first element
|
||||
* @param array $array The source array
|
||||
* @return mixed The first element
|
||||
*/
|
||||
public static function first(array $array)
|
||||
{
|
||||
@@ -297,8 +297,8 @@ class A
|
||||
* // last: 'tweet'
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @return mixed The last element
|
||||
* @param array $array The source array
|
||||
* @return mixed The last element
|
||||
*/
|
||||
public static function last(array $array)
|
||||
{
|
||||
@@ -326,12 +326,12 @@ class A
|
||||
* // ];
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param int $limit The number of elements the array should
|
||||
* contain after filling it up.
|
||||
* @param mixed $fill The element, which should be used to
|
||||
* fill the array
|
||||
* @return array The filled-up result array
|
||||
* @param array $array The source array
|
||||
* @param int $limit The number of elements the array should
|
||||
* contain after filling it up.
|
||||
* @param mixed $fill The element, which should be used to
|
||||
* fill the array
|
||||
* @return array The filled-up result array
|
||||
*/
|
||||
public static function fill(array $array, int $limit, $fill = 'placeholder'): array
|
||||
{
|
||||
@@ -394,10 +394,10 @@ class A
|
||||
* // ];
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param array $required An array of required keys
|
||||
* @return array An array of missing fields. If this
|
||||
* is empty, nothing is missing.
|
||||
* @param array $array The source array
|
||||
* @param array $required An array of required keys
|
||||
* @return array An array of missing fields. If this
|
||||
* is empty, nothing is missing.
|
||||
*/
|
||||
public static function missing(array $array, array $required = []): array
|
||||
{
|
||||
@@ -451,13 +451,13 @@ class A
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param string $field The name of the column
|
||||
* @param string $direction desc (descending) or asc (ascending)
|
||||
* @param int $method A PHP sort method flag or 'natural' for
|
||||
* natural sorting, which is not supported in
|
||||
* PHP by sort flags
|
||||
* @return array The sorted array
|
||||
* @param array $array The source array
|
||||
* @param string $field The name of the column
|
||||
* @param string $direction desc (descending) or asc (ascending)
|
||||
* @param int $method A PHP sort method flag or 'natural' for
|
||||
* natural sorting, which is not supported in
|
||||
* PHP by sort flags
|
||||
* @return array The sorted array
|
||||
*/
|
||||
public static function sort(array $array, string $field, string $direction = 'desc', $method = SORT_REGULAR): array
|
||||
{
|
||||
@@ -500,8 +500,8 @@ class A
|
||||
* // returns: true
|
||||
* </code>
|
||||
*
|
||||
* @param array $array The array to analyze
|
||||
* @return boolean true: The array is associative false: It's not
|
||||
* @param array $array The array to analyze
|
||||
* @return bool true: The array is associative false: It's not
|
||||
*/
|
||||
public static function isAssociative(array $array): bool
|
||||
{
|
||||
@@ -511,9 +511,9 @@ class A
|
||||
/**
|
||||
* Returns the average value of an array
|
||||
*
|
||||
* @param array $array The source array
|
||||
* @param int $decimals The number of decimals to return
|
||||
* @return float The average value
|
||||
* @param array $array The source array
|
||||
* @param int $decimals The number of decimals to return
|
||||
* @return float The average value
|
||||
*/
|
||||
public static function average(array $array, int $decimals = 0): float
|
||||
{
|
||||
@@ -568,8 +568,8 @@ class A
|
||||
* ]);
|
||||
* </code>
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $update
|
||||
* @param array $array
|
||||
* @param array $update
|
||||
* @return array
|
||||
*/
|
||||
public static function update(array $array, array $update): array
|
||||
|
@@ -35,8 +35,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Magic getter function
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $arguments
|
||||
* @param string $key
|
||||
* @param mixed $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $key, $arguments)
|
||||
@@ -67,7 +67,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Low-level getter for elements
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
@@ -82,8 +82,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Low-level setter for elements
|
||||
*
|
||||
* @param string $key string or array
|
||||
* @param mixed $value
|
||||
* @param string $key string or array
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set(string $key, $value)
|
||||
{
|
||||
@@ -114,8 +114,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Appends an element
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $item
|
||||
* @param mixed $key
|
||||
* @param mixed $item
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function append(...$args)
|
||||
@@ -133,9 +133,9 @@ class Collection extends Iterator implements Countable
|
||||
* Creates chunks of the same size.
|
||||
* 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
|
||||
* a sub collection in each chunk
|
||||
* @param int $size Number of elements per chunk
|
||||
* @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)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Getter and setter for the data
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array|Collection
|
||||
*/
|
||||
public function data(array $data = null)
|
||||
@@ -422,8 +422,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $default
|
||||
* @param mixed $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
@@ -439,7 +439,7 @@ class Collection extends Iterator implements Countable
|
||||
*
|
||||
* @param array|object $item
|
||||
* @param string $attribute
|
||||
* @param boolean $split
|
||||
* @param bool $split
|
||||
* @param mixed $related
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -542,10 +542,38 @@ class Collection extends Iterator implements Countable
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Collection with the intersection of the given elements
|
||||
*
|
||||
* @param \Kirby\Toolkit\Collection $other
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function intersection($other)
|
||||
{
|
||||
return $other->find($this->keys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is an intersection between the given collection and this collection
|
||||
*
|
||||
* @param \Kirby\Toolkit\Collection $other
|
||||
* @return bool
|
||||
*/
|
||||
public function intersects($other): bool
|
||||
{
|
||||
foreach ($this->keys() as $key) {
|
||||
if ($other->has($key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the number of elements is zero
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
@@ -555,7 +583,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Checks if the number of elements is even
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isEven(): bool
|
||||
{
|
||||
@@ -565,7 +593,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Checks if the number of elements is more than zero
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotEmpty(): bool
|
||||
{
|
||||
@@ -575,7 +603,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Checks if the number of elements is odd
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isOdd(): bool
|
||||
{
|
||||
@@ -596,7 +624,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
|
||||
* @param int $limit The number of elements to return
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function limit(int $limit)
|
||||
@@ -607,7 +635,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Map a function to each element
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param callable $callback
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function map(callable $callback)
|
||||
@@ -619,7 +647,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Returns the nth element from the collection
|
||||
*
|
||||
* @param integer $n
|
||||
* @param int $n
|
||||
* @return mixed
|
||||
*/
|
||||
public function nth(int $n)
|
||||
@@ -645,7 +673,7 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Returns a new object starting from the given offset
|
||||
*
|
||||
* @param int $offset The index to start from
|
||||
* @param int $offset The index to start from
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function offset(int $offset)
|
||||
@@ -710,8 +738,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Prepends an element to the data array
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $item
|
||||
* @param mixed $key
|
||||
* @param mixed $item
|
||||
* @return self
|
||||
*/
|
||||
public function prepend(...$args)
|
||||
@@ -790,8 +818,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Adds a new element to the collection
|
||||
*
|
||||
* @param mixed $key string or array
|
||||
* @param mixed $value
|
||||
* @param mixed $key string or array
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function set($key, $value = null)
|
||||
@@ -830,8 +858,8 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Returns a slice of the object
|
||||
*
|
||||
* @param int $offset The optional index to start the slice from
|
||||
* @param int $limit The optional number of elements to return
|
||||
* @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
|
||||
*/
|
||||
public function slice(int $offset = 0, int $limit = null)
|
||||
@@ -868,10 +896,10 @@ class Collection extends Iterator implements Countable
|
||||
/**
|
||||
* Sorts the elements by any number of fields
|
||||
*
|
||||
* @param $field string|callable Field name or value callback to sort by
|
||||
* @param $direction string asc or desc
|
||||
* @param $method int The sort flag, SORT_REGULAR, SORT_NUMERIC etc.
|
||||
* @return Collection
|
||||
* @param string|callable $field Field name or value callback to sort by
|
||||
* @param string $direction asc or desc
|
||||
* @param int $method The sort flag, SORT_REGULAR, SORT_NUMERIC etc.
|
||||
* @return Collection
|
||||
*/
|
||||
public function sortBy()
|
||||
{
|
||||
@@ -1027,10 +1055,34 @@ class Collection extends Iterator implements Countable
|
||||
return array_values($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The when method only executes the given Closure when the first parameter
|
||||
* is true. If the first parameter is false, the Closure will not be executed.
|
||||
* You may pass another Closure as the third parameter to the when method.
|
||||
* This Closure will execute if the first parameter evaluates as false
|
||||
*
|
||||
* @param mixed $condition
|
||||
* @param Closure $callback
|
||||
* @param Closure $fallback
|
||||
* @return mixed
|
||||
*/
|
||||
public function when($condition, Closure $callback, Closure $fallback = null)
|
||||
{
|
||||
if ($condition) {
|
||||
return $callback->call($this, $condition);
|
||||
}
|
||||
|
||||
if ($fallback !== null) {
|
||||
return $fallback->call($this, $condition);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for $this->not()
|
||||
*
|
||||
* @param string ...$keys any number of keys, passed as individual arguments
|
||||
* @param string ...$keys any number of keys, passed as individual arguments
|
||||
* @return \Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function without(...$keys)
|
||||
|
@@ -149,7 +149,7 @@ class Dir
|
||||
* Checks if the folder has any contents
|
||||
*
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEmpty(string $dir): bool
|
||||
{
|
||||
@@ -160,7 +160,7 @@ class Dir
|
||||
* Checks if the directory is readable
|
||||
*
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isReadable(string $dir): bool
|
||||
{
|
||||
@@ -171,7 +171,7 @@ class Dir
|
||||
* Checks if the directory is writable
|
||||
*
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWritable(string $dir): bool
|
||||
{
|
||||
@@ -183,7 +183,7 @@ class Dir
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $link
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function link(string $source, string $link): bool
|
||||
{
|
||||
@@ -207,9 +207,9 @@ class Dir
|
||||
/**
|
||||
* Creates a new directory
|
||||
*
|
||||
* @param string $dir The path for the new directory
|
||||
* @param boolean $recursive Create all parent directories, which don't exist
|
||||
* @return boolean True: the dir has been created, false: creating failed
|
||||
* @param string $dir The path for the new directory
|
||||
* @param bool $recursive Create all parent directories, which don't exist
|
||||
* @return bool True: the dir has been created, false: creating failed
|
||||
*/
|
||||
public static function make(string $dir, bool $recursive = true): bool
|
||||
{
|
||||
@@ -240,10 +240,10 @@ class Dir
|
||||
* Recursively check when the dir and all
|
||||
* subfolders have been modified for the last time.
|
||||
*
|
||||
* @param string $dir The path of the directory
|
||||
* @param string $format
|
||||
* @param string $handler
|
||||
* @return int
|
||||
* @param string $dir The path of the directory
|
||||
* @param string $format
|
||||
* @param string $handler
|
||||
* @return int
|
||||
*/
|
||||
public static function modified(string $dir, string $format = null, string $handler = 'date')
|
||||
{
|
||||
@@ -266,9 +266,9 @@ class Dir
|
||||
/**
|
||||
* Moves a directory to a new location
|
||||
*
|
||||
* @param string $old The current path of the directory
|
||||
* @param string $new The desired path where the dir should be moved to
|
||||
* @return boolean true: the directory has been moved, false: moving failed
|
||||
* @param string $old The current path of the directory
|
||||
* @param string $new The desired path where the dir should be moved to
|
||||
* @return bool true: the directory has been moved, false: moving failed
|
||||
*/
|
||||
public static function move(string $old, string $new): bool
|
||||
{
|
||||
@@ -302,10 +302,10 @@ class Dir
|
||||
* Reads all files from a directory and returns them as an array.
|
||||
* It skips unwanted invisible stuff.
|
||||
*
|
||||
* @param string $dir The path of directory
|
||||
* @param array $ignore Optional array with filenames, which should be ignored
|
||||
* @param bool $absolute If true, the full path for each item will be returned
|
||||
* @return array An array of filenames
|
||||
* @param string $dir The path of directory
|
||||
* @param array $ignore Optional array with filenames, which should be ignored
|
||||
* @param bool $absolute If true, the full path for each item will be returned
|
||||
* @return array An array of filenames
|
||||
*/
|
||||
public static function read(string $dir, array $ignore = null, bool $absolute = false): array
|
||||
{
|
||||
@@ -334,7 +334,7 @@ class Dir
|
||||
* Removes a folder including all containing files and folders
|
||||
*
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove(string $dir): bool
|
||||
{
|
||||
@@ -370,8 +370,8 @@ class Dir
|
||||
/**
|
||||
* Gets the size of the directory and all subfolders and files
|
||||
*
|
||||
* @param string $dir The path of the directory
|
||||
* @return mixed
|
||||
* @param string $dir The path of the directory
|
||||
* @return mixed
|
||||
*/
|
||||
public static function size(string $dir)
|
||||
{
|
||||
|
@@ -38,7 +38,7 @@ class Escape
|
||||
* <div attr='...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'>content</div>
|
||||
* <div attr="...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...">content</div>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function attr($string)
|
||||
@@ -59,7 +59,7 @@ class Escape
|
||||
* <style>selector { property : "...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE..."; } </style>
|
||||
* <span style="property : ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...">text</span>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function css($string)
|
||||
@@ -79,7 +79,7 @@ class Escape
|
||||
* <body>...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...</body>
|
||||
* <div>...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...</div>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function html($string)
|
||||
@@ -97,7 +97,7 @@ class Escape
|
||||
* <script>x='...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'</script>
|
||||
* <div onmouseover="x='...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'"</div>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function js($string)
|
||||
@@ -113,7 +113,7 @@ class Escape
|
||||
*
|
||||
* <a href="http://www.somesite.com?test=...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...">link</a>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function url($string)
|
||||
@@ -135,7 +135,7 @@ class Escape
|
||||
* < is replaced with <
|
||||
* > is replaced with >
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function xml($string)
|
||||
|
@@ -108,9 +108,9 @@ class F
|
||||
/**
|
||||
* Appends new content to an existing file
|
||||
*
|
||||
* @param string $file The path for the file
|
||||
* @param mixed $content Either a string or an array. Arrays will be converted to JSON.
|
||||
* @return boolean
|
||||
* @param string $file The path for the file
|
||||
* @param mixed $content Either a string or an array. Arrays will be converted to JSON.
|
||||
* @return bool
|
||||
*/
|
||||
public static function append(string $file, $content): bool
|
||||
{
|
||||
@@ -131,10 +131,10 @@ class F
|
||||
/**
|
||||
* Copy a file to a new location.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
* @param boolean $force
|
||||
* @return boolean
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public static function copy(string $source, string $target, bool $force = false): bool
|
||||
{
|
||||
@@ -162,7 +162,7 @@ class F
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $file The path
|
||||
* @param string $file The path
|
||||
* @return string
|
||||
*/
|
||||
public static function dirname(string $file): string
|
||||
@@ -175,7 +175,7 @@ class F
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $in
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists(string $file, string $in = null): bool
|
||||
{
|
||||
@@ -190,8 +190,8 @@ class F
|
||||
/**
|
||||
* Gets the extension of a file
|
||||
*
|
||||
* @param string $file The filename or path
|
||||
* @param string $extension Set an optional extension to overwrite the current one
|
||||
* @param string $file The filename or path
|
||||
* @param string $extension Set an optional extension to overwrite the current one
|
||||
* @return string
|
||||
*/
|
||||
public static function extension(string $file = null, string $extension = null): string
|
||||
@@ -258,7 +258,7 @@ class F
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $name The path
|
||||
* @param string $name The path
|
||||
* @return string
|
||||
*/
|
||||
public static function filename(string $name): string
|
||||
@@ -269,8 +269,8 @@ class F
|
||||
/**
|
||||
* Invalidate opcode cache for file.
|
||||
*
|
||||
* @param string $file The path of the file
|
||||
* @return boolean
|
||||
* @param string $file The path of the file
|
||||
* @return bool
|
||||
*/
|
||||
public static function invalidateOpcodeCache(string $file): bool
|
||||
{
|
||||
@@ -286,7 +286,7 @@ class F
|
||||
*
|
||||
* @param string $file Full path to the file
|
||||
* @param string $value An extension or mime type
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function is(string $file, string $value): bool
|
||||
{
|
||||
@@ -307,7 +307,7 @@ class F
|
||||
* Checks if the file is readable
|
||||
*
|
||||
* @param string $file
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isReadable(string $file): bool
|
||||
{
|
||||
@@ -318,7 +318,7 @@ class F
|
||||
* Checks if the file is writable
|
||||
*
|
||||
* @param string $file
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWritable(string $file): bool
|
||||
{
|
||||
@@ -335,7 +335,7 @@ class F
|
||||
* @param string $source
|
||||
* @param string $link
|
||||
* @param string $method
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function link(string $source, string $link, string $method = 'link'): bool
|
||||
{
|
||||
@@ -414,9 +414,9 @@ class F
|
||||
/**
|
||||
* Get the file's last modification time.
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $format
|
||||
* @param string $handler date or strftime
|
||||
* @param string $file
|
||||
* @param string $format
|
||||
* @param string $handler date or strftime
|
||||
* @return mixed
|
||||
*/
|
||||
public static function modified(string $file, string $format = null, string $handler = 'date')
|
||||
@@ -440,10 +440,10 @@ class F
|
||||
/**
|
||||
* Moves a file to a new location
|
||||
*
|
||||
* @param string $oldRoot The current path for the file
|
||||
* @param string $newRoot The path to the new location
|
||||
* @param boolean $force Force move if the target file exists
|
||||
* @return boolean
|
||||
* @param string $oldRoot The current path for the file
|
||||
* @param string $newRoot The path to the new location
|
||||
* @param bool $force Force move if the target file exists
|
||||
* @return bool
|
||||
*/
|
||||
public static function move(string $oldRoot, string $newRoot, bool $force = false): bool
|
||||
{
|
||||
@@ -472,7 +472,7 @@ class F
|
||||
/**
|
||||
* Extracts the name from a file path or filename without extension
|
||||
*
|
||||
* @param string $name The path or filename
|
||||
* @param string $name The path or filename
|
||||
* @return string
|
||||
*/
|
||||
public static function name(string $name): string
|
||||
@@ -483,7 +483,7 @@ class F
|
||||
/**
|
||||
* Converts an integer size into a human readable format
|
||||
*
|
||||
* @param mixed $size The file size or a file path
|
||||
* @param mixed $size The file size or a file path
|
||||
* @return string|int
|
||||
*/
|
||||
public static function niceSize($size): string
|
||||
@@ -508,7 +508,7 @@ class F
|
||||
/**
|
||||
* Reads the content of a file
|
||||
*
|
||||
* @param string $file The path for the file
|
||||
* @param string $file The path for the file
|
||||
* @return string|false
|
||||
*/
|
||||
public static function read(string $file)
|
||||
@@ -520,9 +520,9 @@ class F
|
||||
* Changes the name of the file without
|
||||
* touching the extension
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $newName
|
||||
* @param bool $overwrite Force overwrite existing files
|
||||
* @param string $file
|
||||
* @param string $newName
|
||||
* @param bool $overwrite Force overwrite existing files
|
||||
* @return string|false
|
||||
*/
|
||||
public static function rename(string $file, string $newName, bool $overwrite = false)
|
||||
@@ -610,8 +610,8 @@ class F
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $file The path for the file
|
||||
* @return boolean
|
||||
* @param string $file The path for the file
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove(string $file): bool
|
||||
{
|
||||
@@ -642,7 +642,7 @@ class F
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string The file name
|
||||
* @param string $string The file name
|
||||
* @return string
|
||||
*/
|
||||
public static function safeName(string $string): string
|
||||
@@ -675,7 +675,7 @@ class F
|
||||
/**
|
||||
* Returns the size of a file.
|
||||
*
|
||||
* @param mixed $file The path
|
||||
* @param mixed $file The path
|
||||
* @return int
|
||||
*/
|
||||
public static function size(string $file): int
|
||||
@@ -728,7 +728,7 @@ class F
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $to
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function unzip(string $file, string $to): bool
|
||||
{
|
||||
@@ -765,10 +765,10 @@ class F
|
||||
/**
|
||||
* Creates a new file
|
||||
*
|
||||
* @param string $file The path for the new file
|
||||
* @param mixed $content Either a string, an object or an array. Arrays and objects will be serialized.
|
||||
* @param boolean $append true: append the content to an exisiting file if available. false: overwrite.
|
||||
* @return boolean
|
||||
* @param string $file The path for the new file
|
||||
* @param mixed $content Either a string, an object or an array. Arrays and objects will be serialized.
|
||||
* @param bool $append true: append the content to an exisiting file if available. false: overwrite.
|
||||
* @return bool
|
||||
*/
|
||||
public static function write(string $file, $content, bool $append = false): bool
|
||||
{
|
||||
|
@@ -56,8 +56,8 @@ class File
|
||||
/**
|
||||
* Copy a file to a new location.
|
||||
*
|
||||
* @param string $target
|
||||
* @param boolean $force
|
||||
* @param string $target
|
||||
* @param bool $force
|
||||
* @return self
|
||||
*/
|
||||
public function copy(string $target, bool $force = false)
|
||||
@@ -147,7 +147,7 @@ class File
|
||||
/**
|
||||
* Checks if the file is readable
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadable(): bool
|
||||
{
|
||||
@@ -157,7 +157,7 @@ class File
|
||||
/**
|
||||
* Checks if the file is writable
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isWritable(): bool
|
||||
{
|
||||
@@ -177,8 +177,8 @@ class File
|
||||
/**
|
||||
* Get the file's last modification time.
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $handler date or strftime
|
||||
* @param string $format
|
||||
* @param string $handler date or strftime
|
||||
* @return mixed
|
||||
*/
|
||||
public function modified(string $format = null, string $handler = 'date')
|
||||
@@ -189,8 +189,8 @@ class File
|
||||
/**
|
||||
* Move the file to a new location
|
||||
*
|
||||
* @param string $newRoot
|
||||
* @param bool $overwrite Force overwriting any existing files
|
||||
* @param string $newRoot
|
||||
* @param bool $overwrite Force overwriting any existing files
|
||||
* @return self
|
||||
*/
|
||||
public function move(string $newRoot, bool $overwrite = false)
|
||||
@@ -248,8 +248,8 @@ class File
|
||||
* Changes the name of the file without
|
||||
* touching the extension
|
||||
*
|
||||
* @param string $newName
|
||||
* @param bool $overwrite Force overwrite existing files
|
||||
* @param string $newName
|
||||
* @param bool $overwrite Force overwrite existing files
|
||||
* @return self
|
||||
*/
|
||||
public function rename(string $newName, bool $overwrite = false)
|
||||
@@ -276,7 +276,7 @@ class File
|
||||
/**
|
||||
* Returns the raw size of the file
|
||||
*
|
||||
* @return int
|
||||
* @return int
|
||||
*/
|
||||
public function size(): int
|
||||
{
|
||||
@@ -321,7 +321,7 @@ class File
|
||||
/**
|
||||
* Writes content to the file
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $content
|
||||
* @return bool
|
||||
*/
|
||||
public function write($content): bool
|
||||
|
@@ -144,8 +144,8 @@ class Html
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string
|
||||
* @return string The html string
|
||||
* @param string $string
|
||||
* @return string The html string
|
||||
*/
|
||||
public static function decode(string $string = null): string
|
||||
{
|
||||
@@ -189,9 +189,9 @@ class Html
|
||||
/**
|
||||
* Converts a string to a html-safe string
|
||||
*
|
||||
* @param string $string
|
||||
* @param bool $keepTags
|
||||
* @return string The html string
|
||||
* @param string $string
|
||||
* @param bool $keepTags
|
||||
* @return string The html string
|
||||
*/
|
||||
public static function encode(string $string = null, bool $keepTags = false): string
|
||||
{
|
||||
@@ -465,7 +465,7 @@ class Html
|
||||
}
|
||||
|
||||
// build the options query
|
||||
if (!empty($options)) {
|
||||
if (empty($options) === false) {
|
||||
$query = '?' . http_build_query($options);
|
||||
} else {
|
||||
$query = '';
|
||||
@@ -523,7 +523,7 @@ class Html
|
||||
}
|
||||
|
||||
// build the options query
|
||||
if (!empty($options)) {
|
||||
if (empty($options) === false) {
|
||||
$query = '?' . http_build_query($options);
|
||||
} else {
|
||||
$query = '';
|
||||
|
@@ -67,7 +67,7 @@ class I18n
|
||||
* depending on the given number
|
||||
*
|
||||
* @param int $count
|
||||
* @param boolean $none If true, 'none' will be returned if the count is 0
|
||||
* @param bool $none If true, 'none' will be returned if the count is 0
|
||||
* @return string
|
||||
*/
|
||||
public static function form(int $count, bool $none = false): string
|
||||
@@ -194,7 +194,7 @@ class I18n
|
||||
* Translate amounts
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $count
|
||||
* @param int $count
|
||||
* @param string $locale
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Kirby\Toolkit;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* Extended version of PHP's iterator
|
||||
* class that builds the foundation of our
|
||||
@@ -13,7 +16,7 @@ namespace Kirby\Toolkit;
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Iterator implements \Iterator
|
||||
class Iterator implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* The data array
|
||||
@@ -32,6 +35,16 @@ class Iterator implements \Iterator
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the items.
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current key
|
||||
*
|
||||
@@ -95,7 +108,7 @@ class Iterator implements \Iterator
|
||||
/**
|
||||
* Checks if the current element is valid
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function valid(): bool
|
||||
{
|
||||
@@ -115,8 +128,8 @@ class Iterator implements \Iterator
|
||||
/**
|
||||
* Tries to find the index number for the given element
|
||||
*
|
||||
* @param mixed $needle the element to search for
|
||||
* @return string|false the name of the key or false
|
||||
* @param mixed $needle the element to search for
|
||||
* @return string|false the name of the key or false
|
||||
*/
|
||||
public function indexOf($needle)
|
||||
{
|
||||
@@ -126,8 +139,8 @@ class Iterator implements \Iterator
|
||||
/**
|
||||
* Tries to find the key for the given element
|
||||
*
|
||||
* @param mixed $needle the element to search for
|
||||
* @return string|false the name of the key or false
|
||||
* @param mixed $needle the element to search for
|
||||
* @return string|false the name of the key or false
|
||||
*/
|
||||
public function keyOf($needle)
|
||||
{
|
||||
@@ -137,8 +150,8 @@ class Iterator implements \Iterator
|
||||
/**
|
||||
* Checks by key if an element is included
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return boolean
|
||||
* @param mixed $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key): bool
|
||||
{
|
||||
@@ -148,8 +161,8 @@ class Iterator implements \Iterator
|
||||
/**
|
||||
* Checks if the current key is set
|
||||
*
|
||||
* @param mixed $key the key to check
|
||||
* @return boolean
|
||||
* @param mixed $key the key to check
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key): bool
|
||||
{
|
||||
|
@@ -6,7 +6,7 @@ use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* The `Mime` class provides method
|
||||
* for mime type detection or guessing
|
||||
* for MIME type detection or guessing
|
||||
* from different criteria like
|
||||
* extensions etc.
|
||||
*
|
||||
@@ -19,7 +19,7 @@ use SimpleXMLElement;
|
||||
class Mime
|
||||
{
|
||||
/**
|
||||
* Extension to mime type map
|
||||
* Extension to MIME type map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
@@ -112,7 +112,7 @@ class Mime
|
||||
];
|
||||
|
||||
/**
|
||||
* Fixes an invalid mime type guess for the given file
|
||||
* Fixes an invalid MIME type guess for the given file
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $mime
|
||||
@@ -153,7 +153,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Guesses a mime type by extension
|
||||
* Guesses a MIME type by extension
|
||||
*
|
||||
* @param string $extension
|
||||
* @return string|null
|
||||
@@ -165,7 +165,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mime type of a file
|
||||
* Returns the MIME type of a file
|
||||
*
|
||||
* @param string $file
|
||||
* @return string|false
|
||||
@@ -183,7 +183,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mime type of a file
|
||||
* Returns the MIME type of a file
|
||||
*
|
||||
* @param string $file
|
||||
* @return string|false
|
||||
@@ -198,7 +198,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to detect a valid SVG and returns the mime type accordingly
|
||||
* Tries to detect a valid SVG and returns the MIME type accordingly
|
||||
*
|
||||
* @param string $file
|
||||
* @return string|false
|
||||
@@ -219,18 +219,19 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Tests if a given MIME type is matched by an `Accept` header
|
||||
* pattern; returns true if the MIME type is contained at all
|
||||
*
|
||||
* @param string $mime
|
||||
* @param string $pattern
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAccepted(string $mime, string $pattern): bool
|
||||
{
|
||||
$accepted = Str::accepted($pattern);
|
||||
|
||||
foreach ($accepted as $m) {
|
||||
if (fnmatch($m['value'], $mime, FNM_PATHNAME) === true) {
|
||||
if (static::matches($mime, $m['value']) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +240,20 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension for a given mime type
|
||||
* Tests if a MIME wildcard pattern from an `Accept` header
|
||||
* matches a given type
|
||||
*
|
||||
* @param string $test
|
||||
* @param string $wildcard
|
||||
* @return bool
|
||||
*/
|
||||
public static function matches(string $test, string $wildcard): bool
|
||||
{
|
||||
return fnmatch($wildcard, $test, FNM_PATHNAME) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension for a given MIME type
|
||||
*
|
||||
* @param string|null $mime
|
||||
* @return string|false
|
||||
@@ -260,7 +274,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available extensions for a given mime type
|
||||
* Returns all available extensions for a given MIME type
|
||||
*
|
||||
* @param string|null $mime
|
||||
* @return array
|
||||
@@ -285,7 +299,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mime type of a file
|
||||
* Returns the MIME type of a file
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $extension
|
||||
@@ -314,7 +328,7 @@ class Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all detectable mime types
|
||||
* Returns all detectable MIME types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Kirby\Toolkit;
|
||||
|
||||
use Exception;
|
||||
use Kirby\Exception\ErrorPageException;
|
||||
use Kirby\Exception\Exception;
|
||||
|
||||
/**
|
||||
* Basic pagination handling
|
||||
@@ -15,38 +16,48 @@ use Exception;
|
||||
*/
|
||||
class Pagination
|
||||
{
|
||||
use Properties {
|
||||
setProperties as protected baseSetProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current page
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Total number of items
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $total;
|
||||
protected $total = 0;
|
||||
|
||||
/**
|
||||
* The number of items per page
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $limit;
|
||||
protected $limit = 20;
|
||||
|
||||
/**
|
||||
* Whether validation of the pagination page
|
||||
* is enabled; will throw Exceptions if true
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $validate = true;
|
||||
|
||||
/**
|
||||
* Creates a new pagination object
|
||||
* with the given parameters
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $props
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
public function __construct(array $props = [])
|
||||
{
|
||||
$this->page($params['page'] ?? 1);
|
||||
$this->limit($params['limit'] ?? 20);
|
||||
$this->total($params['total'] ?? 0);
|
||||
$this->setProperties($props);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,67 +124,48 @@ class Pagination
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter and setter for the current page
|
||||
* Getter for the current page
|
||||
*
|
||||
* @param int|null $page
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
|
||||
* @return int
|
||||
*/
|
||||
public function page(int $page = null)
|
||||
public function page(int $page = null): int
|
||||
{
|
||||
if ($page === null) {
|
||||
if ($this->page > $this->pages()) {
|
||||
$this->page = $this->lastPage();
|
||||
}
|
||||
|
||||
if ($this->page < 1) {
|
||||
$this->page = $this->firstPage();
|
||||
}
|
||||
|
||||
return $this->page;
|
||||
if ($page !== null) {
|
||||
throw new Exception('$pagination->page() setter is no longer supported, use $pagination->clone()'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->page = $page;
|
||||
return $this;
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter and setter for the total number of items
|
||||
* Getter for the total number of items
|
||||
*
|
||||
* @param int|null $total
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
|
||||
* @return int
|
||||
*/
|
||||
public function total(int $total = null)
|
||||
public function total(int $total = null): int
|
||||
{
|
||||
if ($total === null) {
|
||||
return $this->total;
|
||||
if ($total !== null) {
|
||||
throw new Exception('$pagination->total() setter is no longer supported, use $pagination->clone()'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if ($total < 0) {
|
||||
throw new Exception('Invalid total number of items: ' . $total);
|
||||
}
|
||||
|
||||
$this->total = $total;
|
||||
return $this;
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter and setter for the number of items per page
|
||||
* Getter for the number of items per page
|
||||
*
|
||||
* @param int|null $limit
|
||||
* @return int|\Kirby\Toolkit\Pagination
|
||||
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
|
||||
* @return int
|
||||
*/
|
||||
public function limit(int $limit = null)
|
||||
public function limit(int $limit = null): int
|
||||
{
|
||||
if ($limit === null) {
|
||||
return $this->limit;
|
||||
if ($limit !== null) {
|
||||
throw new Exception('$pagination->limit() setter is no longer supported, use $pagination->clone()'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
throw new Exception('Invalid pagination limit: ' . $limit);
|
||||
}
|
||||
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +248,7 @@ class Pagination
|
||||
* Checks if the given page exists
|
||||
*
|
||||
* @param int $page
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPage(int $page): bool
|
||||
{
|
||||
@@ -274,7 +266,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if there are any pages at all
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPages(): bool
|
||||
{
|
||||
@@ -284,7 +276,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if there's a previous page
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrevPage(): bool
|
||||
{
|
||||
@@ -304,7 +296,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if there's a next page
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasNextPage(): bool
|
||||
{
|
||||
@@ -324,7 +316,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if the current page is the first page
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isFirstPage(): bool
|
||||
{
|
||||
@@ -334,7 +326,7 @@ class Pagination
|
||||
/**
|
||||
* Checks if the current page is the last page
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isLastPage(): bool
|
||||
{
|
||||
@@ -397,6 +389,97 @@ class Pagination
|
||||
return array_pop($range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the properties limit, total and page
|
||||
* and validates that the properties match
|
||||
*
|
||||
* @param array $props Array with keys limit, total and/or page
|
||||
* @return self
|
||||
*/
|
||||
protected function setProperties(array $props)
|
||||
{
|
||||
$this->baseSetProperties($props);
|
||||
|
||||
// ensure that page is set to something, otherwise
|
||||
// generate "default page" based on other params
|
||||
if ($this->page === null) {
|
||||
$this->page = $this->firstPage();
|
||||
}
|
||||
|
||||
// allow a page value of 1 even if there are no pages;
|
||||
// otherwise the exception will get thrown for this pretty common case
|
||||
$min = $this->firstPage();
|
||||
$max = $this->pages();
|
||||
if ($this->page === 1 && $max === 0) {
|
||||
$this->page = 0;
|
||||
}
|
||||
|
||||
// validate page based on all params if validation is enabled,
|
||||
// otherwise limit the page number to the bounds
|
||||
if ($this->page < $min || $this->page > $max) {
|
||||
if (static::$validate === true) {
|
||||
throw new ErrorPageException('Pagination page ' . $this->page . ' does not exist, expected ' . $min . '-' . $max);
|
||||
} else {
|
||||
$this->page = max(min($this->page, $max), $min);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of items per page
|
||||
*
|
||||
* @param int $limit
|
||||
* @return self
|
||||
*/
|
||||
protected function setLimit(int $limit = 20)
|
||||
{
|
||||
if ($limit < 1) {
|
||||
throw new Exception('Invalid pagination limit: ' . $limit);
|
||||
}
|
||||
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total number of items
|
||||
*
|
||||
* @param int $total
|
||||
* @return self
|
||||
*/
|
||||
protected function setTotal(int $total = 0)
|
||||
{
|
||||
if ($total < 0) {
|
||||
throw new Exception('Invalid total number of items: ' . $total);
|
||||
}
|
||||
|
||||
$this->total = $total;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current page
|
||||
*
|
||||
* @param int|string|null $page Int or int in string form;
|
||||
* automatically determined if null
|
||||
* @return self
|
||||
*/
|
||||
protected function setPage($page = null)
|
||||
{
|
||||
// if $page is null, it is set to a default in the setProperties() method
|
||||
if ($page !== null) {
|
||||
if (is_numeric($page) !== true || $page < 0) {
|
||||
throw new Exception('Invalid page number: ' . $page);
|
||||
}
|
||||
|
||||
$this->page = (int)$page;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all properties
|
||||
*
|
||||
|
@@ -114,7 +114,7 @@ class Query
|
||||
/**
|
||||
* Breaks the query string down into its components
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query
|
||||
* @return array
|
||||
*/
|
||||
protected function parts(string $query): array
|
||||
@@ -137,7 +137,7 @@ class Query
|
||||
* Analyzes each part of the query string and
|
||||
* extracts methods and method arguments.
|
||||
*
|
||||
* @param string $part
|
||||
* @param string $part
|
||||
* @return array
|
||||
*/
|
||||
protected function part(string $part): array
|
||||
@@ -158,7 +158,7 @@ class Query
|
||||
* Converts a parameter of query to
|
||||
* proper type.
|
||||
*
|
||||
* @param mixed $arg
|
||||
* @param mixed $arg
|
||||
* @return mixed
|
||||
*/
|
||||
protected function parameter($arg)
|
||||
|
@@ -169,9 +169,9 @@ class Str
|
||||
/**
|
||||
* Returns the rest of the string after the given character
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return string
|
||||
*/
|
||||
public static function after(string $string, string $needle, bool $caseInsensitive = false): string
|
||||
@@ -188,7 +188,7 @@ class Str
|
||||
/**
|
||||
* Convert a string to 7-bit ASCII.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function ascii(string $string): string
|
||||
@@ -211,9 +211,9 @@ class Str
|
||||
/**
|
||||
* Returns the beginning of a string before the given character
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return string
|
||||
*/
|
||||
public static function before(string $string, string $needle, bool $caseInsensitive = false): string
|
||||
@@ -243,9 +243,9 @@ class Str
|
||||
/**
|
||||
* Checks if a str contains another string
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return bool
|
||||
*/
|
||||
public static function contains(string $string = null, string $needle, bool $caseInsensitive = false): bool
|
||||
@@ -279,7 +279,7 @@ class Str
|
||||
/**
|
||||
* Encode a string (used for email addresses)
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string): string
|
||||
@@ -298,7 +298,7 @@ class Str
|
||||
/**
|
||||
* Tries to detect the string encoding
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function encoding(string $string): string
|
||||
@@ -309,9 +309,9 @@ class Str
|
||||
/**
|
||||
* Checks if a string ends with the passed needle
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return bool
|
||||
*/
|
||||
public static function endsWith(string $string, string $needle, bool $caseInsensitive = false): bool
|
||||
@@ -335,11 +335,11 @@ class Str
|
||||
* It removes all html tags first and then cuts the string
|
||||
* according to the specified number of chars.
|
||||
*
|
||||
* @param string $string The string to be shortened
|
||||
* @param int $chars The final number of characters the string should have
|
||||
* @param boolean $strip True: remove the HTML tags from the string first
|
||||
* @param string $rep The element, which should be added if the string is too long. Ellipsis is the default.
|
||||
* @return string The shortened string
|
||||
* @param string $string The string to be shortened
|
||||
* @param int $chars The final number of characters the string should have
|
||||
* @param bool $strip True: remove the HTML tags from the string first
|
||||
* @param string $rep The element, which should be added if the string is too long. Ellipsis is the default.
|
||||
* @return string The shortened string
|
||||
*/
|
||||
public static function excerpt($string, $chars = 140, $strip = true, $rep = '…')
|
||||
{
|
||||
@@ -381,9 +381,9 @@ class Str
|
||||
/**
|
||||
* Returns the rest of the string starting from the given character
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return string
|
||||
*/
|
||||
public static function from(string $string, string $needle, bool $caseInsensitive = false): string
|
||||
@@ -401,7 +401,7 @@ class Str
|
||||
* Checks if the given string is a URL
|
||||
*
|
||||
* @param string|null $string
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function isURL(string $string = null): bool
|
||||
{
|
||||
@@ -411,7 +411,7 @@ class Str
|
||||
/**
|
||||
* Convert a string to kebab case.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function kebab(string $value = null): string
|
||||
@@ -422,7 +422,7 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of strlen()
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return int
|
||||
*/
|
||||
public static function length(string $string = null): int
|
||||
@@ -433,7 +433,7 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of strtolower()
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function lower(string $string = null): string
|
||||
@@ -457,8 +457,8 @@ class Str
|
||||
/**
|
||||
* Get a character pool with various possible combinations
|
||||
*
|
||||
* @param string|array $type
|
||||
* @param boolean $array
|
||||
* @param string|array $type
|
||||
* @param bool $array
|
||||
* @return string|array
|
||||
*/
|
||||
public static function pool($type, bool $array = true)
|
||||
@@ -498,9 +498,9 @@ class Str
|
||||
* Returns the position of a needle in a string
|
||||
* if it can be found
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return int|bool
|
||||
*/
|
||||
public static function position(string $string = null, string $needle, bool $caseInsensitive = false)
|
||||
@@ -565,15 +565,15 @@ class Str
|
||||
* Replaces all or some occurrences of the search string with the replacement string
|
||||
* Extension of the str_replace() function in PHP with an additional $limit parameter
|
||||
*
|
||||
* @param string|array $string String being replaced on (haystack);
|
||||
* can be an array of multiple subject strings
|
||||
* @param string|array $search Value being searched for (needle)
|
||||
* @param string|array $replace Value to replace matches with
|
||||
* @param int|array $limit Maximum possible replacements for each search value;
|
||||
* multiple limits for each search value are supported;
|
||||
* defaults to no limit
|
||||
* @return string|array String with replaced values;
|
||||
* if $string is an array, array of strings
|
||||
* @param string|array $string String being replaced on (haystack);
|
||||
* can be an array of multiple subject strings
|
||||
* @param string|array $search Value being searched for (needle)
|
||||
* @param string|array $replace Value to replace matches with
|
||||
* @param int|array $limit Maximum possible replacements for each search value;
|
||||
* multiple limits for each search value are supported;
|
||||
* defaults to no limit
|
||||
* @return string|array String with replaced values;
|
||||
* if $string is an array, array of strings
|
||||
*/
|
||||
public static function replace($string, $search, $replace, $limit = -1)
|
||||
{
|
||||
@@ -622,13 +622,13 @@ class Str
|
||||
* Generates a replacement array out of dynamic input data
|
||||
* Used for Str::replace()
|
||||
*
|
||||
* @param string|array $search Value being searched for (needle)
|
||||
* @param string|array $replace Value to replace matches with
|
||||
* @param int|array $limit Maximum possible replacements for each search value;
|
||||
* multiple limits for each search value are supported;
|
||||
* defaults to no limit
|
||||
* @return array List of replacement arrays, each with a
|
||||
* 'search', 'replace' and 'limit' attribute
|
||||
* @param string|array $search Value being searched for (needle)
|
||||
* @param string|array $replace Value to replace matches with
|
||||
* @param int|array $limit Maximum possible replacements for each search value;
|
||||
* multiple limits for each search value are supported;
|
||||
* defaults to no limit
|
||||
* @return array List of replacement arrays, each with a
|
||||
* 'search', 'replace' and 'limit' attribute
|
||||
*/
|
||||
public static function replacements($search, $replace, $limit): array
|
||||
{
|
||||
@@ -673,9 +673,9 @@ class Str
|
||||
* Takes a replacement array and processes the replacements
|
||||
* Used for Str::replace()
|
||||
*
|
||||
* @param string $string String being replaced on (haystack)
|
||||
* @param array $replacements Replacement array from Str::replacements()
|
||||
* @return string String with replaced values
|
||||
* @param string $string String being replaced on (haystack)
|
||||
* @param array $replacements Replacement array from Str::replacements()
|
||||
* @return string String with replaced values
|
||||
*/
|
||||
public static function replaceReplacements(string $string, array $replacements): string
|
||||
{
|
||||
@@ -736,12 +736,12 @@ class Str
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string The string to be shortened
|
||||
* @param int $length The final number of characters the
|
||||
* string should have
|
||||
* @param string $appendix The element, which should be added if the
|
||||
* string is too long. Ellipsis is the default.
|
||||
* @return string The shortened string
|
||||
* @param string $string The string to be shortened
|
||||
* @param int $length The final number of characters the
|
||||
* string should have
|
||||
* @param string $appendix The element, which should be added if the
|
||||
* string is too long. Ellipsis is the default.
|
||||
* @return string The shortened string
|
||||
*/
|
||||
public static function short(string $string = null, int $length = 0, string $appendix = '…'): ?string
|
||||
{
|
||||
@@ -759,13 +759,14 @@ class Str
|
||||
/**
|
||||
* Convert a string to a safe version to be used in a URL
|
||||
*
|
||||
* @param string $string The unsafe string
|
||||
* @param string $separator To be used instead of space and
|
||||
* other non-word characters.
|
||||
* @param string $allowed List of all allowed characters (regex)
|
||||
* @return string The safe string
|
||||
* @param string $string The unsafe string
|
||||
* @param string $separator To be used instead of space and
|
||||
* other non-word characters.
|
||||
* @param string $allowed List of all allowed characters (regex)
|
||||
* @param int $maxlength The maximum length of the slug
|
||||
* @return string The safe string
|
||||
*/
|
||||
public static function slug(string $string = null, string $separator = null, string $allowed = null): string
|
||||
public static function slug(string $string = null, string $separator = null, string $allowed = null, int $maxlength = 128): string
|
||||
{
|
||||
$separator = $separator ?? static::$defaults['slug']['separator'];
|
||||
$allowed = $allowed ?? static::$defaults['slug']['allowed'];
|
||||
@@ -789,14 +790,15 @@ class Str
|
||||
$string = preg_replace('!^[^a-z0-9]+!', '', $string);
|
||||
$string = preg_replace('![^a-z0-9]+$!', '', $string);
|
||||
|
||||
return $string;
|
||||
// cut the string after the given maxlength
|
||||
return static::short($string, $maxlength, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to snake case.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $delimiter
|
||||
* @param string $value
|
||||
* @param string $delimiter
|
||||
* @return string
|
||||
*/
|
||||
public static function snake(string $value = null, string $delimiter = '_'): string
|
||||
@@ -814,10 +816,10 @@ class Str
|
||||
* and it has a built-in way to skip values
|
||||
* which are too short.
|
||||
*
|
||||
* @param string $string The string to split
|
||||
* @param string $separator The string to split by
|
||||
* @param int $length The min length of values.
|
||||
* @return array An array of found values
|
||||
* @param string $string The string to split
|
||||
* @param string $separator The string to split by
|
||||
* @param int $length The min length of values.
|
||||
* @return array An array of found values
|
||||
*/
|
||||
public static function split($string, string $separator = ',', int $length = 1): array
|
||||
{
|
||||
@@ -841,9 +843,9 @@ class Str
|
||||
/**
|
||||
* Checks if a string starts with the passed needle
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return bool
|
||||
*/
|
||||
public static function startsWith(string $string = null, string $needle, bool $caseInsensitive = false): bool
|
||||
@@ -858,9 +860,9 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of substr()
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $start
|
||||
* @param int $length
|
||||
* @param string $string
|
||||
* @param int $start
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
public static function substr(string $string = null, int $start = 0, int $length = null): string
|
||||
@@ -878,13 +880,13 @@ class Str
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string The string with placeholders
|
||||
* @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
|
||||
* @param string $string The string with placeholders
|
||||
* @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
|
||||
{
|
||||
@@ -969,7 +971,7 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of ucfirst()
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function ucfirst(string $string = null): string
|
||||
@@ -980,7 +982,7 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of ucwords()
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function ucwords(string $string = null): string
|
||||
@@ -998,8 +1000,8 @@ class Str
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string
|
||||
* @return string The html string
|
||||
* @param string $string
|
||||
* @return string The html string
|
||||
*/
|
||||
public static function unhtml(string $string = null): string
|
||||
{
|
||||
@@ -1009,9 +1011,9 @@ class Str
|
||||
/**
|
||||
* Returns the beginning of a string until the given character
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @param string $string
|
||||
* @param string $needle
|
||||
* @param bool $caseInsensitive
|
||||
* @return string
|
||||
*/
|
||||
public static function until(string $string, string $needle, bool $caseInsensitive = false): string
|
||||
@@ -1028,7 +1030,7 @@ class Str
|
||||
/**
|
||||
* A UTF-8 safe version of strotoupper()
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function upper(string $string = null): string
|
||||
|
@@ -102,11 +102,11 @@ class V
|
||||
* a set of rules, using all registered
|
||||
* validators
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $rules
|
||||
* @param array $messages
|
||||
* @param boolean $fail
|
||||
* @return boolean|array
|
||||
* @param mixed $value
|
||||
* @param array $rules
|
||||
* @param array $messages
|
||||
* @param bool $fail
|
||||
* @return bool|array
|
||||
*/
|
||||
public static function value($value, array $rules, array $messages = [], bool $fail = true)
|
||||
{
|
||||
@@ -142,9 +142,9 @@ class V
|
||||
* a set of rules, using all registered
|
||||
* validators
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $rules
|
||||
* @return boolean
|
||||
* @param array $input
|
||||
* @param array $rules
|
||||
* @return bool
|
||||
*/
|
||||
public static function input(array $input, array $rules): bool
|
||||
{
|
||||
@@ -179,9 +179,9 @@ class V
|
||||
/**
|
||||
* Calls an installed validator and passes all arguments
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $arguments
|
||||
* @return boolean
|
||||
* @param string $method
|
||||
* @param array $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public static function __callStatic(string $method, array $arguments): bool
|
||||
{
|
||||
@@ -481,7 +481,8 @@ V::$validators = [
|
||||
*/
|
||||
'url' => function ($value): bool {
|
||||
// In search for the perfect regular expression: https://mathiasbynens.be/demo/url-regex
|
||||
$regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iu';
|
||||
// Added localhost support and removed 127.*.*.* ip restriction
|
||||
$regex = '_^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:localhost)|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$_iu';
|
||||
return preg_match($regex, $value) !== 0;
|
||||
}
|
||||
];
|
||||
|
@@ -34,7 +34,7 @@ class View
|
||||
* Creates a new view object
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(string $file, array $data = [])
|
||||
{
|
||||
@@ -56,7 +56,7 @@ class View
|
||||
/**
|
||||
* Checks if the template file exists
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(): bool
|
||||
{
|
||||
|
@@ -56,11 +56,11 @@ class Xml
|
||||
/**
|
||||
* Creates an XML string from an array
|
||||
*
|
||||
* @param string $props The source array
|
||||
* @param string $name The name of the root element
|
||||
* @param boolean $head Include the xml declaration head or not
|
||||
* @param int $level The indendation level
|
||||
* @return string The XML string
|
||||
* @param string $props The source array
|
||||
* @param string $name The name of the root element
|
||||
* @param bool $head Include the xml declaration head or not
|
||||
* @param int $level The indendation level
|
||||
* @return string The XML string
|
||||
*/
|
||||
public static function create($props, string $name = 'root', bool $head = true, $level = 0): string
|
||||
{
|
||||
@@ -116,7 +116,7 @@ class Xml
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $string = null): string
|
||||
@@ -136,8 +136,8 @@ class Xml
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @param string $string
|
||||
* @param boolean $html True: convert to html first
|
||||
* @param string $string
|
||||
* @param bool $html True: convert to html first
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string = null, bool $html = true): string
|
||||
@@ -166,7 +166,7 @@ class Xml
|
||||
/**
|
||||
* Parses a XML string and returns an array
|
||||
*
|
||||
* @param string $xml
|
||||
* @param string $xml
|
||||
* @return array|false
|
||||
*/
|
||||
public static function parse(string $xml = null)
|
||||
|
Reference in New Issue
Block a user