Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,417 @@
<?php
namespace FluentMail\Includes\Support;
use Closure;
use ArrayAccess;
use FluentMail\Includes\Support\Collection;
use FluentMail\Includes\Support\MacroableTrait;
class Arr {
use MacroableTrait;
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*/
public static function add($array, $key, $value)
{
if (is_null(static::get($array, $key)))
{
static::set($array, $key, $value);
}
return $array;
}
/**
* Build a new array using a callback.
*
* @param array $array
* @param \Closure $callback
* @return array
*/
public static function build($array, Closure $callback)
{
$results = array();
foreach ($array as $key => $value)
{
list($innerKey, $innerValue) = call_user_func($callback, $key, $value);
$results[$innerKey] = $innerValue;
}
return $results;
}
/**
* Divide an array into two arrays. One with keys and the other with values.
*
* @param array $array
* @return array
*/
public static function divide($array)
{
return array(array_keys($array), array_values($array));
}
/**
* Flatten a multi-dimensional associative array with dots.
*
* @param array $array
* @param string $prepend
* @return array
*/
public static function dot($array, $prepend = '')
{
$results = array();
foreach ($array as $key => $value)
{
if (is_array($value))
{
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
}
else
{
$results[$prepend.$key] = $value;
}
}
return $results;
}
/**
* Get all of the given array except for a specified array of items.
*
* @param array $array
* @param array|string $keys
* @return array
*/
public static function except($array, $keys)
{
return array_diff_key($array, array_flip((array) $keys));
}
/**
* Fetch a flattened array of a nested array element.
*
* @param array $array
* @param string $key
* @return array
*/
public static function fetch($array, $key)
{
foreach (explode('.', $key) as $segment)
{
$results = array();
foreach ($array as $value)
{
if (array_key_exists($segment, $value = (array) $value))
{
$results[] = $value[$segment];
}
}
$array = array_values($results);
}
return array_values($results);
}
/**
* Return the first element in an array passing a given truth test.
*
* @param array $array
* @param \Closure $callback
* @param mixed $default
* @return mixed
*/
public static function first($array, $callback, $default = null)
{
foreach ($array as $key => $value)
{
if (call_user_func($callback, $key, $value)) return $value;
}
return static::value($default);
}
/**
* Return the last element in an array passing a given truth test.
*
* @param array $array
* @param \Closure $callback
* @param mixed $default
* @return mixed
*/
public static function last($array, $callback, $default = null)
{
return static::first(array_reverse($array), $callback, $default);
}
/**
* Flatten a multi-dimensional array into a single level.
*
* @param array $array
* @return array
*/
public static function flatten($array)
{
$return = array();
array_walk_recursive($array, function($x) use (&$return) { $return[] = $x; });
return $return;
}
/**
* Remove one or many array items from a given array using "dot" notation.
*
* @param array $array
* @param array|string $keys
* @return void
*/
public static function forget(&$array, $keys)
{
$original =& $array;
foreach ((array) $keys as $key)
{
$parts = explode('.', $key);
while (count($parts) > 1)
{
$part = array_shift($parts);
if (isset($array[$part]) && is_array($array[$part]))
{
$array =& $array[$part];
}
}
unset($array[array_shift($parts)]);
// clean up after each pass
$array =& $original;
}
}
/**
* Get an item from an array using "dot" notation.
*
* @param array $array
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($array, $key, $default = null)
{
return static::getItem($array, $key, $default);
}
/**
* Retrieves nested items from array(able) data
* it's the laravel's date_get global function.
*
* @param mixed $target
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function getItem($target, $key, $default = null)
{
if (is_null($key)) return $target;
foreach (explode('.', $key) as $segment) {
if (is_array($target)) {
if (!array_key_exists($segment, $target)) {
return static::value($default);
}
$target = $target[$segment];
} elseif ($target instanceof ArrayAccess) {
if (!isset($target[$segment])) {
return static::value($default);
}
$target = $target[$segment];
} elseif (is_object($target)) {
if (!isset($target->{$segment})) {
return static::value($default);
}
$target = $target->{$segment};
} else {
return static::value($default);
}
}
return $target;
}
/**
* Check if an item exists in an array using "dot" notation.
*
* @param array $array
* @param string $key
* @return bool
*/
public static function has($array, $key)
{
if (empty($array) || is_null($key)) return false;
if (array_key_exists($key, $array)) return true;
foreach (explode('.', $key) as $segment)
{
if ( ! is_array($array) || ! array_key_exists($segment, $array))
{
return false;
}
$array = $array[$segment];
}
return true;
}
/**
* Get a subset of the items from the given array.
*
* @param array $array
* @param array|string $keys
* @return array
*/
public static function only($array, $keys)
{
return array_intersect_key($array, array_flip((array) $keys));
}
/**
* Pluck an array of values from an array.
*
* @param array $array
* @param string $value
* @param string $key
* @return array
*/
public static function pluck($array, $value, $key = null)
{
$results = array();
foreach ($array as $item)
{
$itemValue = is_object($item) ? $item->{$value} : $item[$value];
// If the key is "null", we will just append the value to the array and keep
// looping. Otherwise we will key the array using the value of the key we
// received from the developer. Then we'll return the final array form.
if (is_null($key))
{
$results[] = $itemValue;
}
else
{
$itemKey = is_object($item) ? $item->{$key} : $item[$key];
$results[$itemKey] = $itemValue;
}
}
return $results;
}
/**
* Get a value from the array, and remove it.
*
* @param array $array
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function pull(&$array, $key, $default = null)
{
$value = static::get($array, $key, $default);
static::forget($array, $key);
return $value;
}
/**
* Set an array item to a given value using "dot" notation.
*
* If no key is given to the method, the entire array will be replaced.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*/
public static function set(&$array, $key, $value)
{
if (is_null($key)) return $array = $value;
$keys = explode('.', $key);
while (count($keys) > 1)
{
$key = array_shift($keys);
// If the key doesn't exist at this depth, we will just create an empty array
// to hold the next value, allowing us to create the arrays to hold final
// values at the correct depth. Then we'll keep digging into the array.
if ( ! isset($array[$key]) || ! is_array($array[$key]))
{
$array[$key] = array();
}
$array =& $array[$key];
}
$array[array_shift($keys)] = $value;
return $array;
}
/**
* Sort the array using the given Closure.
*
* @param array $array
* @param \Closure $callback
* @return array
*/
public static function sort($array, Closure $callback)
{
return Collection::make($array)->sortBy($callback)->all();
}
/**
* Filter the array using the given Closure.
*
* @param array $array
* @param \Closure $callback
* @return array
*/
public static function where($array, Closure $callback)
{
$filtered = array();
foreach ($array as $key => $value)
{
if (call_user_func($callback, $key, $value)) $filtered[$key] = $value;
}
return $filtered;
}
public static function value($value)
{
return $value instanceof Closure ? $value() : $value;
}
}

View File

@@ -0,0 +1,851 @@
<?php
namespace FluentMail\Includes\Support;
use Closure;
use Countable;
use ArrayAccess;
use ArrayIterator;
use CachingIterator;
use JsonSerializable;
use IteratorAggregate;
use FluentMail\Includes\Support\Arr;
use FluentMail\Includes\Support\Contracts\JsonableInterface;
use FluentMail\Includes\Support\Contracts\ArrayableInterface;
class Collection implements ArrayAccess, ArrayableInterface, Countable, IteratorAggregate, JsonableInterface, JsonSerializable {
/**
* The items contained in the collection.
*
* @var array
*/
protected $items = array();
/**
* Create a new collection.
*
* @param array $items
* @return void
*/
public function __construct(array $items = array())
{
$this->items = $items;
}
/**
* Create a new collection instance if the value isn't one already.
*
* @param mixed $items
* @return static
*/
public static function make($items)
{
if (is_null($items)) return new static;
if ($items instanceof Collection) return $items;
return new static(is_array($items) ? $items : array($items));
}
/**
* Get all of the items in the collection.
*
* @return array
*/
public function all()
{
return $this->items;
}
/**
* Collapse the collection items into a single array.
*
* @return static
*/
public function collapse()
{
$results = array();
foreach ($this->items as $values)
{
if ($values instanceof Collection) $values = $values->all();
$results = array_merge($results, $values);
}
return new static($results);
}
/**
* Determine if an item exists in the collection.
*
* @param mixed $value
* @return bool
*/
public function contains($value)
{
if ($value instanceof Closure)
{
return ! is_null($this->first($value));
}
return in_array($value, $this->items);
}
/**
* Diff the collection with the given items.
*
* @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items
* @return static
*/
public function diff($items)
{
return new static(array_diff($this->items, $this->getArrayableItems($items)));
}
/**
* Execute a callback over each item.
*
* @param \Closure $callback
* @return $this
*/
public function each(Closure $callback)
{
array_map($callback, $this->items);
return $this;
}
/**
* Fetch a nested element of the collection.
*
* @param string $key
* @return static
*/
public function fetch($key)
{
return new static(Arr::fetch($this->items, $key));
}
/**
* Run a filter over each of the items.
*
* @param \Closure $callback
* @return static
*/
public function filter(Closure $callback)
{
return new static(array_filter($this->items, $callback));
}
/**
* Get the first item from the collection.
*
* @param \Closure $callback
* @param mixed $default
* @return mixed|null
*/
public function first(?Closure $callback = null, $default = null)
{
if (is_null($callback))
{
return count($this->items) > 0 ? reset($this->items) : null;
}
return Arr::first($this->items, $callback, $default);
}
/**
* Get a flattened array of the items in the collection.
*
* @return static
*/
public function flatten()
{
return new static(Arr::flatten($this->items));
}
/**
* Flip the items in the collection.
*
* @return static
*/
public function flip()
{
return new static(array_flip($this->items));
}
/**
* Remove an item from the collection by key.
*
* @param mixed $key
* @return void
*/
public function forget($key)
{
unset($this->items[$key]);
}
/**
* Get an item from the collection by key.
*
* @param mixed $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
if ($this->offsetExists($key))
{
return $this->items[$key];
}
return value($default);
}
/**
* Group an associative array by a field or Closure value.
*
* @param callable|string $groupBy
* @return static
*/
public function groupBy($groupBy)
{
$results = array();
foreach ($this->items as $key => $value)
{
$results[$this->getGroupByKey($groupBy, $key, $value)][] = $value;
}
return new static($results);
}
/**
* Get the "group by" key value.
*
* @param callable|string $groupBy
* @param string $key
* @param mixed $value
* @return string
*/
protected function getGroupByKey($groupBy, $key, $value)
{
if ( ! is_string($groupBy) && is_callable($groupBy))
{
return $groupBy($value, $key);
}
return Arr::getItem($value, $groupBy);
}
/**
* Key an associative array by a field.
*
* @param string $keyBy
* @return static
*/
public function keyBy($keyBy)
{
$results = [];
foreach ($this->items as $item)
{
$key = Arr::getItem($item, $keyBy);
$results[$key] = $item;
}
return new static($results);
}
/**
* Determine if an item exists in the collection by key.
*
* @param mixed $key
* @return bool
*/
public function has($key)
{
return $this->offsetExists($key);
}
/**
* Concatenate values of a given key as a string.
*
* @param string $value
* @param string $glue
* @return string
*/
public function implode($value, $glue = null)
{
return implode($glue, $this->lists($value));
}
/**
* Intersect the collection with the given items.
*
* @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items
* @return static
*/
public function intersect($items)
{
return new static(array_intersect($this->items, $this->getArrayableItems($items)));
}
/**
* Determine if the collection is empty or not.
*
* @return bool
*/
public function isEmpty()
{
return empty($this->items);
}
/**
* Get the keys of the collection items.
*
* @return array
*/
public function keys()
{
return array_keys($this->items);
}
/**
* Get the last item from the collection.
*
* @return mixed|null
*/
public function last()
{
return count($this->items) > 0 ? end($this->items) : null;
}
/**
* Get an array with the values of a given key.
*
* @param string $value
* @param string $key
* @return array
*/
public function lists($value, $key = null)
{
return Arr::pluck($this->items, $value, $key);
}
/**
* Run a map over each of the items.
*
* @param \Closure $callback
* @return static
*/
public function map(Closure $callback)
{
return new static(array_map($callback, $this->items, array_keys($this->items)));
}
/**
* Merge the collection with the given items.
*
* @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items
* @return static
*/
public function merge($items)
{
return new static(array_merge($this->items, $this->getArrayableItems($items)));
}
/**
* Get and remove the last item from the collection.
*
* @return mixed|null
*/
public function pop()
{
return array_pop($this->items);
}
/**
* Push an item onto the beginning of the collection.
*
* @param mixed $value
* @return void
*/
public function prepend($value)
{
array_unshift($this->items, $value);
}
/**
* Push an item onto the end of the collection.
*
* @param mixed $value
* @return void
*/
public function push($value)
{
$this->items[] = $value;
}
/**
* Pulls an item from the collection.
*
* @param mixed $key
* @param mixed $default
* @return mixed
*/
public function pull($key, $default = null)
{
return Arr::pull($this->items, $key, $default);
}
/**
* Put an item in the collection by key.
*
* @param mixed $key
* @param mixed $value
* @return void
*/
public function put($key, $value)
{
$this->items[$key] = $value;
}
/**
* Get one or more items randomly from the collection.
*
* @param int $amount
* @return mixed
*/
public function random($amount = 1)
{
if ($this->isEmpty()) return null;
$keys = array_rand($this->items, $amount);
return is_array($keys) ? array_intersect_key($this->items, array_flip($keys)) : $this->items[$keys];
}
/**
* Reduce the collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
*/
public function reduce(callable $callback, $initial = null)
{
return array_reduce($this->items, $callback, $initial);
}
/**
* Create a collection of all elements that do not pass a given truth test.
*
* @param \Closure|mixed $callback
* @return static
*/
public function reject($callback)
{
if ($callback instanceof Closure)
{
return $this->filter(function($item) use ($callback)
{
return ! $callback($item);
});
}
return $this->filter(function($item) use ($callback)
{
return $item != $callback;
});
}
/**
* Reverse items order.
*
* @return static
*/
public function reverse()
{
return new static(array_reverse($this->items));
}
/**
* Search the collection for a given value and return the corresponding key if successful.
*
* @param mixed $value
* @param bool $strict
* @return mixed
*/
public function search($value, $strict = false)
{
return array_search($value, $this->items, $strict);
}
/**
* Get and remove the first item from the collection.
*
* @return mixed|null
*/
public function shift()
{
return array_shift($this->items);
}
/**
* Shuffle the items in the collection.
*
* @return $this
*/
public function shuffle()
{
shuffle($this->items);
return $this;
}
/**
* Slice the underlying collection array.
*
* @param int $offset
* @param int $length
* @param bool $preserveKeys
* @return static
*/
public function slice($offset, $length = null, $preserveKeys = false)
{
return new static(array_slice($this->items, $offset, $length, $preserveKeys));
}
/**
* Chunk the underlying collection array.
*
* @param int $size
* @param bool $preserveKeys
* @return static
*/
public function chunk($size, $preserveKeys = false)
{
$chunks = new static;
foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk)
{
$chunks->push(new static($chunk));
}
return $chunks;
}
/**
* Sort through each item with a callback.
*
* @param \Closure $callback
* @return $this
*/
public function sort(Closure $callback)
{
uasort($this->items, $callback);
return $this;
}
/**
* Sort the collection using the given Closure.
*
* @param \Closure|string $callback
* @param int $options
* @param bool $descending
* @return $this
*/
public function sortBy($callback, $options = SORT_REGULAR, $descending = false)
{
$results = array();
if (is_string($callback)) $callback =
$this->valueRetriever($callback);
// First we will loop through the items and get the comparator from a callback
// function which we were given. Then, we will sort the returned values and
// and grab the corresponding values for the sorted keys from this array.
foreach ($this->items as $key => $value)
{
$results[$key] = $callback($value);
}
$descending ? arsort($results, $options)
: asort($results, $options);
// Once we have sorted all of the keys in the array, we will loop through them
// and grab the corresponding model so we can set the underlying items list
// to the sorted version. Then we'll just return the collection instance.
foreach (array_keys($results) as $key)
{
$results[$key] = $this->items[$key];
}
$this->items = $results;
return $this;
}
/**
* Sort the collection in descending order using the given Closure.
*
* @param \Closure|string $callback
* @param int $options
* @return $this
*/
public function sortByDesc($callback, $options = SORT_REGULAR)
{
return $this->sortBy($callback, $options, true);
}
/**
* Splice portion of the underlying collection array.
*
* @param int $offset
* @param int $length
* @param mixed $replacement
* @return static
*/
public function splice($offset, $length = 0, $replacement = array())
{
return new static(array_splice($this->items, $offset, $length, $replacement));
}
/**
* Get the sum of the given values.
*
* @param \Closure $callback
* @return mixed
*/
public function sum($callback = null)
{
if (is_null($callback))
{
return array_sum($this->items);
}
if (is_string($callback))
{
$callback = $this->valueRetriever($callback);
}
return $this->reduce(function($result, $item) use ($callback)
{
return $result += $callback($item);
}, 0);
}
/**
* Take the first or last {$limit} items.
*
* @param int $limit
* @return static
*/
public function take($limit = null)
{
if ($limit < 0) return $this->slice($limit, abs($limit));
return $this->slice(0, $limit);
}
/**
* Transform each item in the collection using a callback.
*
* @param \Closure $callback
* @return $this
*/
public function transform(Closure $callback)
{
$this->items = array_map($callback, $this->items);
return $this;
}
/**
* Return only unique items from the collection array.
*
* @return static
*/
public function unique()
{
return new static(array_unique($this->items));
}
/**
* Reset the keys on the underlying array.
*
* @return static
*/
public function values()
{
$this->items = array_values($this->items);
return $this;
}
/**
* Get a value retrieving callback.
*
* @param string $value
* @return \Closure
*/
protected function valueRetriever($value)
{
return function($item) use ($value)
{
return Arr::getItem($item, $value);
};
}
/**
* Get the collection of items as a plain array.
*
* @return array
*/
public function toArray()
{
return array_map(function($value) {
return $value instanceof ArrayableInterface ? $value->toArray() : $value;
}, $this->items);
}
/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* Get the collection of items as JSON.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
}
/**
* Get an iterator for the items.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->items);
}
/**
* Get a CachingIterator instance.
*
* @param int $flags
* @return \CachingIterator
*/
public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING)
{
return new CachingIterator($this->getIterator(), $flags);
}
/**
* Count the number of items in the collection.
*
* @return int
*/
public function count()
{
return count($this->items);
}
/**
* Determine if an item exists at an offset.
*
* @param mixed $key
* @return bool
*/
public function offsetExists($key)
{
return array_key_exists($key, $this->items);
}
/**
* Get an item at a given offset.
*
* @param mixed $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->items[$key];
}
/**
* Set the item at a given offset.
*
* @param mixed $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
if (is_null($key))
{
$this->items[] = $value;
}
else
{
$this->items[$key] = $value;
}
}
/**
* Unset the item at a given offset.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
unset($this->items[$key]);
}
/**
* Convert the collection to its string representation.
*
* @return string
*/
public function __toString()
{
return $this->toJson();
}
/**
* Results array of items from Collection or ArrayableInterface.
*
* @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items
* @return array
*/
protected function getArrayableItems($items)
{
if ($items instanceof Collection)
{
$items = $items->all();
}
elseif ($items instanceof ArrayableInterface)
{
$items = $items->toArray();
}
return $items;
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace FluentMail\Includes\Support\Contracts;
interface ArrayableInterface {
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray();
}

View File

@@ -0,0 +1,22 @@
<?php
namespace FluentMail\Includes\Support\Contracts;
interface ContextualBindingBuilderContract
{
/**
* Define the abstract target that depends on the context.
*
* @param string $abstract
* @return $this
*/
public function needs($abstract);
/**
* Define the implementation for the contextual binding.
*
* @param Closure|string $implementation
* @return void
*/
public function give($implementation);
}

View File

@@ -0,0 +1,34 @@
<?php
namespace FluentMail\Includes\Support\Contracts;
interface FileInterface
{
/**
* Returns whether the file was uploaded successfully.
*
* @return bool
*/
public function isValid();
/**
* Gets the path without filename
*
* @return string
*/
public function getPath();
/**
* Take an educated guess of the file's extension.
*
* @return mixed|null
*/
public function guessExtension();
/**
* Returns the original file extension.
*
* @return string
*/
public function getClientOriginalExtension();
}

View File

@@ -0,0 +1,15 @@
<?php
namespace FluentMail\Includes\Support\Contracts;
interface JsonableInterface {
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0);
}

View File

@@ -0,0 +1,10 @@
<?php
namespace FluentMail\Includes\Support;
use Exception;
class ForbiddenException extends Exception
{
// ...
}

View File

@@ -0,0 +1,70 @@
<?php
namespace FluentMail\Includes\Support;
trait MacroableTrait {
/**
* The registered string macros.
*
* @var array
*/
protected static $macros = array();
/**
* Register a custom macro.
*
* @param string $name
* @param callable $macro
* @return void
*/
public static function macro($name, callable $macro)
{
static::$macros[$name] = $macro;
}
/**
* Checks if macro is registered
*
* @param string $name
* @return boolean
*/
public static function hasMacro($name)
{
return isset(static::$macros[$name]);
}
/**
* Dynamically handle calls to the class.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public static function __callStatic($method, $parameters)
{
if (static::hasMacro($method))
{
return call_user_func_array(static::$macros[$method], $parameters);
}
throw new \BadMethodCallException("Method {$method} does not exist."); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
/**
* Dynamically handle calls to the class.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
return static::__callStatic($method, $parameters);
}
}

View File

@@ -0,0 +1,590 @@
<?php
namespace FluentMail\Includes\Support;
use FluentMail\Includes\Support\MacroableTrait;
class Str {
use MacroableTrait;
/**
* The cache of snake-cased words.
*
* @var array
*/
protected static $snakeCache = [];
/**
* The cache of camel-cased words.
*
* @var array
*/
protected static $camelCache = [];
/**
* The cache of studly-cased words.
*
* @var array
*/
protected static $studlyCache = [];
/**
* Transliterate a UTF-8 value to ASCII.
*
* @param string $value
* @return string
*/
public static function ascii($value)
{
foreach (static::charsArray() as $key => $val) {
$value = str_replace($val, $key, $value);
}
return preg_replace('/[^\x20-\x7E]/u', '', $value);
}
/**
* Convert a value to camel case.
*
* @param string $value
* @return string
*/
public static function camel($value)
{
if (isset(static::$camelCache[$value])) {
return static::$camelCache[$value];
}
return static::$camelCache[$value] = lcfirst(static::studly($value));
}
/**
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
public static function contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
return true;
}
}
return false;
}
/**
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
public static function endsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true;
}
}
return false;
}
/**
* Cap a string with a single instance of a given value.
*
* @param string $value
* @param string $cap
* @return string
*/
public static function finish($value, $cap)
{
$quoted = preg_quote($cap, '/');
return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
}
/**
* Determine if a given string matches a given pattern.
*
* @param string $pattern
* @param string $value
* @return bool
*/
public static function is($pattern, $value)
{
if ($pattern == $value) {
return true;
}
$pattern = preg_quote($pattern, '#');
// Asterisks are translated into zero-or-more regular expression wildcards
// to make it convenient to check if the strings starts with the given
// pattern such as "library/*", making any string check convenient.
$pattern = str_replace('\*', '.*', $pattern);
return (bool) preg_match('#^'.$pattern.'\z#u', $value);
}
/**
* Return the length of the given string.
*
* @param string $value
* @return int
*/
public static function length($value)
{
return mb_strlen($value);
}
/**
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param string $end
* @return string
*/
public static function limit($value, $limit = 100, $end = '...')
{
if (mb_strwidth($value, 'UTF-8') <= $limit) {
return $value;
}
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
}
/**
* Convert the given string to lower-case.
*
* @param string $value
* @return string
*/
public static function lower($value)
{
return mb_strtolower($value, 'UTF-8');
}
/**
* Limit the number of words in a string.
*
* @param string $value
* @param int $words
* @param string $end
* @return string
*/
public static function words($value, $words = 100, $end = '...')
{
preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);
if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
return $value;
}
return rtrim($matches[0]).$end;
}
/**
* Parse a Class@method style callback into class and method.
*
* @param string $callback
* @param string $default
* @return array
*/
public static function parseCallback($callback, $default)
{
return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default];
}
/**
* Get the plural form of an English word.
*
* @param string $value
* @param int $count
* @return string
*/
public static function plural($value, $count = 2)
{
return Pluralizer::plural($value, $count);
}
/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @return string
*/
public static function random($length = 16)
{
$string = '';
while (($len = strlen($string)) < $length) {
$size = $length - $len;
$bytes = random_bytes($size);
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
}
return $string;
}
/**
* Generate a "random" alpha-numeric string.
*
* Should not be considered sufficient for cryptography, etc.
*
* @deprecated since version 5.3. Use the "random" method directly.
*
* @param int $length
* @return string
*/
public static function quickRandom($length = 16)
{
if (PHP_MAJOR_VERSION > 5) {
return static::random($length);
}
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
/**
* Replace a given value in the string sequentially with an array.
*
* @param string $search
* @param array $replace
* @param string $subject
* @return string
*/
public static function replaceArray($search, array $replace, $subject)
{
foreach ($replace as $value) {
$subject = static::replaceFirst($search, $value, $subject);
}
return $subject;
}
/**
* Replace the first occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*/
public static function replaceFirst($search, $replace, $subject)
{
$position = strpos($subject, $search);
if ($position !== false) {
return substr_replace($subject, $replace, $position, strlen($search));
}
return $subject;
}
/**
* Replace the last occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*/
public static function replaceLast($search, $replace, $subject)
{
$position = strrpos($subject, $search);
if ($position !== false) {
return substr_replace($subject, $replace, $position, strlen($search));
}
return $subject;
}
/**
* Convert the given string to upper-case.
*
* @param string $value
* @return string
*/
public static function upper($value)
{
return mb_strtoupper($value, 'UTF-8');
}
/**
* Convert the given string to title case.
*
* @param string $value
* @return string
*/
public static function title($value)
{
return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
}
/**
* Get the singular form of an English word.
*
* @param string $value
* @return string
*/
public static function singular($value)
{
return Pluralizer::singular($value);
}
/**
* Generate a URL friendly "slug" from a given string.
*
* @param string $title
* @param string $separator
* @return string
*/
public static function slug($title, $separator = '-')
{
$title = static::ascii($title);
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));
// Replace all separator characters and whitespace by a single separator
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
return trim($title, $separator);
}
/**
* Convert a string to snake case.
*
* @param string $value
* @param string $delimiter
* @return string
*/
public static function snake($value, $delimiter = '_')
{
$key = $value;
if (isset(static::$snakeCache[$key][$delimiter])) {
return static::$snakeCache[$key][$delimiter];
}
if (! ctype_lower($value)) {
$value = preg_replace('/\s+/u', '', $value);
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
}
return static::$snakeCache[$key][$delimiter] = $value;
}
/**
* Determine if a given string starts with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
return true;
}
}
return false;
}
/**
* Convert a value to studly caps case.
*
* @param string $value
* @return string
*/
public static function studly($value)
{
$key = $value;
if (isset(static::$studlyCache[$key])) {
return static::$studlyCache[$key];
}
$value = ucwords(str_replace(['-', '_'], ' ', $value));
return static::$studlyCache[$key] = str_replace(' ', '', $value);
}
/**
* Returns the portion of string specified by the start and length parameters.
*
* @param string $string
* @param int $start
* @param int|null $length
* @return string
*/
public static function substr($string, $start, $length = null)
{
return mb_substr($string, $start, $length, 'UTF-8');
}
/**
* Make a string's first character uppercase.
*
* @param string $string
* @return string
*/
public static function ucfirst($string)
{
return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
}
/**
* Returns the replacements for the ascii method.
*
* Note: Adapted from Stringy\Stringy.
*
* @see https://github.com/danielstjules/Stringy/blob/2.3.1/LICENSE.txt
*
* @return array
*/
protected static function charsArray()
{
static $charsArray;
if (isset($charsArray)) {
return $charsArray;
}
return $charsArray = [
'0' => ['°', '₀', '۰'],
'1' => ['¹', '₁', '۱'],
'2' => ['²', '₂', '۲'],
'3' => ['³', '₃', '۳'],
'4' => ['⁴', '₄', '۴', '٤'],
'5' => ['⁵', '₅', '۵', '٥'],
'6' => ['⁶', '₆', '۶', '٦'],
'7' => ['⁷', '₇', '۷'],
'8' => ['⁸', '₈', '۸'],
'9' => ['⁹', '₉', '۹'],
'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'],
'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'],
'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'],
'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'],
'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'],
'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'],
'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'],
'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'],
'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'],
'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'],
'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'],
'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'],
'm' => ['м', 'μ', 'م', 'မ', 'მ'],
'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'],
'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'],
'p' => ['п', 'π', 'ပ', 'პ', 'پ'],
'q' => [''],
'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'],
's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'],
't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'],
'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'],
'v' => ['в', 'ვ', 'ϐ'],
'w' => ['ŵ', 'ω', 'ώ', '', 'ွ'],
'x' => ['χ', 'ξ'],
'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'],
'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'],
'aa' => ['ع', 'आ', 'آ'],
'ae' => ['ä', 'æ', 'ǽ'],
'ai' => ['ऐ'],
'at' => ['@'],
'ch' => ['ч', 'ჩ', 'ჭ', 'چ'],
'dj' => ['ђ', 'đ'],
'dz' => ['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', 'Ǜ'],
'V' => ['В'],
'W' => ['Ω', 'Ώ', 'Ŵ'],
'X' => ['Χ', 'Ξ'],
'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'],
'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'],
'AE' => ['Ä', 'Æ', 'Ǽ'],
'CH' => ['Ч'],
'DJ' => ['Ђ'],
'DZ' => ['Џ'],
'GX' => ['Ĝ'],
'HX' => ['Ĥ'],
'IJ' => ['IJ'],
'JX' => ['Ĵ'],
'KH' => ['Х'],
'LJ' => ['Љ'],
'NJ' => ['Њ'],
'OE' => ['Ö', 'Œ'],
'PS' => ['Ψ'],
'SH' => ['Ш'],
'SHCH' => ['Щ'],
'SS' => ['ẞ'],
'TH' => ['Þ'],
'TS' => ['Ц'],
'UE' => ['Ü'],
'YA' => ['Я'],
'YU' => ['Ю'],
'ZH' => ['Ж'],
' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"],
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace FluentMail\Includes\Support;
use Exception;
class ValidationException extends Exception
{
public function __construct($message = "", $code = 0 , Exception $previous = NULL, $errors = [])
{
$this->errors = $errors;
parent::__construct($message, $code, $previous);
}
public function errors()
{
return $this->errors;
}
}