Reintroduce Webklex IMAP for ticket processing as PHP-IMAP is no longer being developed. This is optional for now and considered beta can be found in cron/ticket_email_parser.php

This commit is contained in:
johnnyq
2025-09-10 14:27:46 -04:00
parent 981fb9585d
commit ce7d84aa2f
2035 changed files with 174115 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace Illuminate\Support\Traits;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Fluent;
trait CapsuleManagerTrait
{
/**
* The current globally used instance.
*
* @var object
*/
protected static $instance;
/**
* The container instance.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* Setup the IoC container instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
protected function setupContainer(Container $container)
{
$this->container = $container;
if (! $this->container->bound('config')) {
$this->container->instance('config', new Fluent);
}
}
/**
* Make this capsule instance available globally.
*
* @return void
*/
public function setAsGlobal()
{
static::$instance = $this;
}
/**
* Get the IoC container instance.
*
* @return \Illuminate\Contracts\Container\Container
*/
public function getContainer()
{
return $this->container;
}
/**
* Set the IoC container instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
{
$this->container = $container;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Illuminate\Support\Traits;
trait Dumpable
{
/**
* Dump the given arguments and terminate execution.
*
* @param mixed ...$args
* @return never
*/
public function dd(...$args)
{
dd($this, ...$args);
}
/**
* Dump the given arguments.
*
* @param mixed ...$args
* @return $this
*/
public function dump(...$args)
{
dump($this, ...$args);
return $this;
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Illuminate\Support\Traits;
use BadMethodCallException;
use Error;
trait ForwardsCalls
{
/**
* Forward a method call to the given object.
*
* @param mixed $object
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
protected function forwardCallTo($object, $method, $parameters)
{
try {
return $object->{$method}(...$parameters);
} catch (Error|BadMethodCallException $e) {
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] != get_class($object) ||
$matches['method'] != $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
}
/**
* Forward a method call to the given object, returning $this if the forwarded call returned itself.
*
* @param mixed $object
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
protected function forwardDecoratedCallTo($object, $method, $parameters)
{
$result = $this->forwardCallTo($object, $method, $parameters);
return $result === $object ? $this : $result;
}
/**
* Throw a bad method call exception for the given method.
*
* @param string $method
* @return never
*
* @throws \BadMethodCallException
*/
protected static function throwBadMethodCallException($method)
{
throw new BadMethodCallException(sprintf(
'Call to undefined method %s::%s()', static::class, $method
));
}
}

View File

@@ -0,0 +1,426 @@
<?php
namespace Illuminate\Support\Traits;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use stdClass;
use function Illuminate\Support\enum_value;
trait InteractsWithData
{
/**
* Retrieve all data from the instance.
*
* @param mixed $keys
* @return array
*/
abstract public function all($keys = null);
/**
* Retrieve data from the instance.
*
* @param string|null $key
* @param mixed $default
* @return mixed
*/
abstract protected function data($key = null, $default = null);
/**
* Determine if the data contains a given key.
*
* @param string|array $key
* @return bool
*/
public function exists($key)
{
return $this->has($key);
}
/**
* Determine if the data contains a given key.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
$keys = is_array($key) ? $key : func_get_args();
$data = $this->all();
foreach ($keys as $value) {
if (! Arr::has($data, $value)) {
return false;
}
}
return true;
}
/**
* Determine if the instance contains any of the given keys.
*
* @param string|array $keys
* @return bool
*/
public function hasAny($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$data = $this->all();
return Arr::hasAny($data, $keys);
}
/**
* Apply the callback if the instance contains the given key.
*
* @param string $key
* @param callable $callback
* @param callable|null $default
* @return $this|mixed
*/
public function whenHas($key, callable $callback, ?callable $default = null)
{
if ($this->has($key)) {
return $callback(data_get($this->all(), $key)) ?: $this;
}
if ($default) {
return $default();
}
return $this;
}
/**
* Determine if the instance contains a non-empty value for the given key.
*
* @param string|array $key
* @return bool
*/
public function filled($key)
{
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value) {
if ($this->isEmptyString($value)) {
return false;
}
}
return true;
}
/**
* Determine if the instance contains an empty value for the given key.
*
* @param string|array $key
* @return bool
*/
public function isNotFilled($key)
{
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value) {
if (! $this->isEmptyString($value)) {
return false;
}
}
return true;
}
/**
* Determine if the instance contains a non-empty value for any of the given keys.
*
* @param string|array $keys
* @return bool
*/
public function anyFilled($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
foreach ($keys as $key) {
if ($this->filled($key)) {
return true;
}
}
return false;
}
/**
* Apply the callback if the instance contains a non-empty value for the given key.
*
* @param string $key
* @param callable $callback
* @param callable|null $default
* @return $this|mixed
*/
public function whenFilled($key, callable $callback, ?callable $default = null)
{
if ($this->filled($key)) {
return $callback(data_get($this->all(), $key)) ?: $this;
}
if ($default) {
return $default();
}
return $this;
}
/**
* Determine if the instance is missing a given key.
*
* @param string|array $key
* @return bool
*/
public function missing($key)
{
$keys = is_array($key) ? $key : func_get_args();
return ! $this->has($keys);
}
/**
* Apply the callback if the instance is missing the given key.
*
* @param string $key
* @param callable $callback
* @param callable|null $default
* @return $this|mixed
*/
public function whenMissing($key, callable $callback, ?callable $default = null)
{
if ($this->missing($key)) {
return $callback(data_get($this->all(), $key)) ?: $this;
}
if ($default) {
return $default();
}
return $this;
}
/**
* Determine if the given key is an empty string for "filled".
*
* @param string $key
* @return bool
*/
protected function isEmptyString($key)
{
$value = $this->data($key);
return ! is_bool($value) && ! is_array($value) && trim((string) $value) === '';
}
/**
* Retrieve data from the instance as a Stringable instance.
*
* @param string $key
* @param mixed $default
* @return \Illuminate\Support\Stringable
*/
public function str($key, $default = null)
{
return $this->string($key, $default);
}
/**
* Retrieve data from the instance as a Stringable instance.
*
* @param string $key
* @param mixed $default
* @return \Illuminate\Support\Stringable
*/
public function string($key, $default = null)
{
return Str::of($this->data($key, $default));
}
/**
* Retrieve data as a boolean value.
*
* Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
*
* @param string|null $key
* @param bool $default
* @return bool
*/
public function boolean($key = null, $default = false)
{
return filter_var($this->data($key, $default), FILTER_VALIDATE_BOOLEAN);
}
/**
* Retrieve data as an integer value.
*
* @param string $key
* @param int $default
* @return int
*/
public function integer($key, $default = 0)
{
return intval($this->data($key, $default));
}
/**
* Retrieve data as a float value.
*
* @param string $key
* @param float $default
* @return float
*/
public function float($key, $default = 0.0)
{
return floatval($this->data($key, $default));
}
/**
* Retrieve data from the instance as a Carbon instance.
*
* @param string $key
* @param string|null $format
* @param \UnitEnum|string|null $tz
* @return \Illuminate\Support\Carbon|null
*
* @throws \Carbon\Exceptions\InvalidFormatException
*/
public function date($key, $format = null, $tz = null)
{
$tz = enum_value($tz);
if ($this->isNotFilled($key)) {
return null;
}
if (is_null($format)) {
return Date::parse($this->data($key), $tz);
}
return Date::createFromFormat($format, $this->data($key), $tz);
}
/**
* Retrieve data from the instance as an enum.
*
* @template TEnum of \BackedEnum
*
* @param string $key
* @param class-string<TEnum> $enumClass
* @param TEnum|null $default
* @return TEnum|null
*/
public function enum($key, $enumClass, $default = null)
{
if ($this->isNotFilled($key) || ! $this->isBackedEnum($enumClass)) {
return value($default);
}
return $enumClass::tryFrom($this->data($key)) ?: value($default);
}
/**
* Retrieve data from the instance as an array of enums.
*
* @template TEnum of \BackedEnum
*
* @param string $key
* @param class-string<TEnum> $enumClass
* @return TEnum[]
*/
public function enums($key, $enumClass)
{
if ($this->isNotFilled($key) || ! $this->isBackedEnum($enumClass)) {
return [];
}
return $this->collect($key)
->map(fn ($value) => $enumClass::tryFrom($value))
->filter()
->all();
}
/**
* Determine if the given enum class is backed.
*
* @param class-string $enumClass
* @return bool
*/
protected function isBackedEnum($enumClass)
{
return enum_exists($enumClass) && method_exists($enumClass, 'tryFrom');
}
/**
* Retrieve data from the instance as an array.
*
* @param array|string|null $key
* @return array
*/
public function array($key = null)
{
return (array) (is_array($key) ? $this->only($key) : $this->data($key));
}
/**
* Retrieve data from the instance as a collection.
*
* @param array|string|null $key
* @return \Illuminate\Support\Collection
*/
public function collect($key = null)
{
return new Collection(is_array($key) ? $this->only($key) : $this->data($key));
}
/**
* Get a subset containing the provided keys with values from the instance data.
*
* @param mixed $keys
* @return array
*/
public function only($keys)
{
$results = [];
$data = $this->all();
$placeholder = new stdClass;
foreach (is_array($keys) ? $keys : func_get_args() as $key) {
$value = data_get($data, $key, $placeholder);
if ($value !== $placeholder) {
Arr::set($results, $key, $value);
}
}
return $results;
}
/**
* Get all of the data except for a specified array of items.
*
* @param mixed $keys
* @return array
*/
public function except($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = $this->all();
Arr::forget($results, $keys);
return $results;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Illuminate\Support\Traits;
use Illuminate\Container\Container;
trait Localizable
{
/**
* Run the callback with the given locale.
*
* @param string $locale
* @param \Closure $callback
* @return mixed
*/
public function withLocale($locale, $callback)
{
if (! $locale) {
return $callback();
}
$app = Container::getInstance();
$original = $app->getLocale();
try {
$app->setLocale($locale);
return $callback();
} finally {
$app->setLocale($original);
}
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Illuminate\Support\Traits;
use Closure;
use Illuminate\Support\Collection;
use Illuminate\Support\Reflector;
use ReflectionFunction;
use RuntimeException;
trait ReflectsClosures
{
/**
* Get the class name of the first parameter of the given Closure.
*
* @param \Closure $closure
* @return string
*
* @throws \ReflectionException
* @throws \RuntimeException
*/
protected function firstClosureParameterType(Closure $closure)
{
$types = array_values($this->closureParameterTypes($closure));
if (! $types) {
throw new RuntimeException('The given Closure has no parameters.');
}
if ($types[0] === null) {
throw new RuntimeException('The first parameter of the given Closure is missing a type hint.');
}
return $types[0];
}
/**
* Get the class names of the first parameter of the given Closure, including union types.
*
* @param \Closure $closure
* @return array
*
* @throws \ReflectionException
* @throws \RuntimeException
*/
protected function firstClosureParameterTypes(Closure $closure)
{
$reflection = new ReflectionFunction($closure);
$types = (new Collection($reflection->getParameters()))
->mapWithKeys(function ($parameter) {
if ($parameter->isVariadic()) {
return [$parameter->getName() => null];
}
return [$parameter->getName() => Reflector::getParameterClassNames($parameter)];
})
->filter()
->values()
->all();
if (empty($types)) {
throw new RuntimeException('The given Closure has no parameters.');
}
if (isset($types[0]) && empty($types[0])) {
throw new RuntimeException('The first parameter of the given Closure is missing a type hint.');
}
return $types[0];
}
/**
* Get the class names / types of the parameters of the given Closure.
*
* @param \Closure $closure
* @return array
*
* @throws \ReflectionException
*/
protected function closureParameterTypes(Closure $closure)
{
$reflection = new ReflectionFunction($closure);
return (new Collection($reflection->getParameters()))
->mapWithKeys(function ($parameter) {
if ($parameter->isVariadic()) {
return [$parameter->getName() => null];
}
return [$parameter->getName() => Reflector::getParameterClassName($parameter)];
})
->all();
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Illuminate\Support\Traits;
trait Tappable
{
/**
* Call the given Closure with this instance then return the instance.
*
* @param (callable($this): mixed)|null $callback
* @return ($callback is null ? \Illuminate\Support\HigherOrderTapProxy : $this)
*/
public function tap($callback = null)
{
return tap($this, $callback);
}
}