mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
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:
54
plugins/vendor/illuminate/support/Defer/DeferredCallback.php
vendored
Normal file
54
plugins/vendor/illuminate/support/Defer/DeferredCallback.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Defer;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeferredCallback
|
||||
{
|
||||
/**
|
||||
* Create a new deferred callback instance.
|
||||
*
|
||||
* @param callable $callback
|
||||
*/
|
||||
public function __construct(public $callback, public ?string $name = null, public bool $always = false)
|
||||
{
|
||||
$this->name = $name ?? (string) Str::uuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the name of the deferred callback so it can be cancelled later.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function name(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the deferred callback should run even on unsuccessful requests and jobs.
|
||||
*
|
||||
* @param bool $always
|
||||
* @return $this
|
||||
*/
|
||||
public function always(bool $always = true): static
|
||||
{
|
||||
$this->always = $always;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the deferred callback.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __invoke(): void
|
||||
{
|
||||
call_user_func($this->callback);
|
||||
}
|
||||
}
|
||||
157
plugins/vendor/illuminate/support/Defer/DeferredCallbackCollection.php
vendored
Normal file
157
plugins/vendor/illuminate/support/Defer/DeferredCallbackCollection.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Defer;
|
||||
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use Countable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class DeferredCallbackCollection implements ArrayAccess, Countable
|
||||
{
|
||||
/**
|
||||
* All of the deferred callbacks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $callbacks = [];
|
||||
|
||||
/**
|
||||
* Get the first callback in the collection.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
return array_values($this->callbacks)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the deferred callbacks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invoke(): void
|
||||
{
|
||||
$this->invokeWhen(fn () => true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the deferred callbacks if the given truth test evaluates to true.
|
||||
*
|
||||
* @param \Closure|null $when
|
||||
* @return void
|
||||
*/
|
||||
public function invokeWhen(?Closure $when = null): void
|
||||
{
|
||||
$when ??= fn () => true;
|
||||
|
||||
$this->forgetDuplicates();
|
||||
|
||||
foreach ($this->callbacks as $index => $callback) {
|
||||
if ($when($callback)) {
|
||||
rescue($callback);
|
||||
}
|
||||
|
||||
unset($this->callbacks[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any deferred callbacks with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function forget(string $name): void
|
||||
{
|
||||
$this->callbacks = (new Collection($this->callbacks))
|
||||
->reject(fn ($callback) => $callback->name === $name)
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any duplicate callbacks.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function forgetDuplicates(): static
|
||||
{
|
||||
$this->callbacks = (new Collection($this->callbacks))
|
||||
->reverse()
|
||||
->unique(fn ($c) => $c->name)
|
||||
->reverse()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the collection has a callback with the given key.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists(mixed $offset): bool
|
||||
{
|
||||
$this->forgetDuplicates();
|
||||
|
||||
return isset($this->callbacks[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the callback with the given key.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet(mixed $offset): mixed
|
||||
{
|
||||
$this->forgetDuplicates();
|
||||
|
||||
return $this->callbacks[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the callback with the given key.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet(mixed $offset, mixed $value): void
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->callbacks[] = $value;
|
||||
} else {
|
||||
$this->callbacks[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the callback with the given key from the collection.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset(mixed $offset): void
|
||||
{
|
||||
$this->forgetDuplicates();
|
||||
|
||||
unset($this->callbacks[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine how many callbacks are in the collection.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$this->forgetDuplicates();
|
||||
|
||||
return count($this->callbacks);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user