Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -1,86 +0,0 @@
<?php
namespace Illuminate\Events;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Container\Container;
class CallQueuedHandler
{
/**
* The container instance.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* Create a new job instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Handle the queued job.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @param array $data
* @return void
*/
public function call(Job $job, array $data)
{
$handler = $this->setJobInstanceIfNecessary(
$job, $this->container->make($data['class'])
);
call_user_func_array(
[$handler, $data['method']], unserialize($data['data'])
);
if (! $job->isDeletedOrReleased()) {
$job->delete();
}
}
/**
* Set the job instance of the given class if necessary.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @param mixed $instance
* @return mixed
*/
protected function setJobInstanceIfNecessary(Job $job, $instance)
{
if (in_array(InteractsWithQueue::class, class_uses_recursive(get_class($instance)))) {
$instance->setJob($job);
}
return $instance;
}
/**
* Call the failed method on the job instance.
*
* The event instance and the exception will be passed.
*
* @param array $data
* @param \Exception $e
* @return void
*/
public function failed(array $data, $e)
{
$handler = $this->container->make($data['class']);
$parameters = array_merge(unserialize($data['data']), [$e]);
if (method_exists($handler, 'failed')) {
call_user_func_array([$handler, 'failed'], $parameters);
}
}
}

View File

@@ -2,14 +2,15 @@
namespace Illuminate\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class CallQueuedListener implements ShouldQueue
{
use InteractsWithQueue;
use InteractsWithQueue, Queueable;
/**
* The listener class name.
@@ -39,6 +40,27 @@ class CallQueuedListener implements ShouldQueue
*/
public $tries;
/**
* The maximum number of exceptions allowed, regardless of attempts.
*
* @var int
*/
public $maxExceptions;
/**
* The number of seconds to wait before retrying a job that encountered an uncaught exception.
*
* @var int
*/
public $backoff;
/**
* The timestamp indicating when the job should timeout.
*
* @var int
*/
public $retryUntil;
/**
* The number of seconds the job can run before timing out.
*
@@ -46,6 +68,13 @@ class CallQueuedListener implements ShouldQueue
*/
public $timeout;
/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;
/**
* Create a new job instance.
*
@@ -75,21 +104,19 @@ class CallQueuedListener implements ShouldQueue
$this->job, $container->make($this->class)
);
call_user_func_array(
[$handler, $this->method], $this->data
);
$handler->{$this->method}(...array_values($this->data));
}
/**
* Set the job instance of the given class if necessary.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @param mixed $instance
* @return mixed
* @param object $instance
* @return object
*/
protected function setJobInstanceIfNecessary(Job $job, $instance)
{
if (in_array(InteractsWithQueue::class, class_uses_recursive(get_class($instance)))) {
if (in_array(InteractsWithQueue::class, class_uses_recursive($instance))) {
$instance->setJob($job);
}
@@ -101,7 +128,7 @@ class CallQueuedListener implements ShouldQueue
*
* The event instance and the exception will be passed.
*
* @param \Exception $e
* @param \Throwable $e
* @return void
*/
public function failed($e)
@@ -110,10 +137,10 @@ class CallQueuedListener implements ShouldQueue
$handler = Container::getInstance()->make($this->class);
$parameters = array_merge($this->data, [$e]);
$parameters = array_merge(array_values($this->data), [$e]);
if (method_exists($handler, 'failed')) {
call_user_func_array([$handler, 'failed'], $parameters);
$handler->failed(...$parameters);
}
}
@@ -138,4 +165,16 @@ class CallQueuedListener implements ShouldQueue
{
return $this->class;
}
/**
* Prepare the instance for cloning.
*
* @return void
*/
public function __clone()
{
$this->data = array_map(function ($data) {
return is_object($data) ? clone $data : $data;
}, $this->data);
}
}

View File

@@ -2,18 +2,25 @@
namespace Illuminate\Events;
use Closure;
use Exception;
use ReflectionClass;
use Illuminate\Support\Str;
use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\ReflectsClosures;
use ReflectionClass;
class Dispatcher implements DispatcherContract
{
use Macroable, ReflectsClosures;
/**
* The IoC container instance.
*
@@ -35,6 +42,13 @@ class Dispatcher implements DispatcherContract
*/
protected $wildcards = [];
/**
* The cached wildcard listeners.
*
* @var array
*/
protected $wildcardsCache = [];
/**
* The queue resolver instance.
*
@@ -56,17 +70,31 @@ class Dispatcher implements DispatcherContract
/**
* Register an event listener with the dispatcher.
*
* @param string|array $events
* @param mixed $listener
* @param \Closure|string|array $events
* @param \Closure|string|array|null $listener
* @return void
*/
public function listen($events, $listener)
public function listen($events, $listener = null)
{
if ($events instanceof Closure) {
return collect($this->firstClosureParameterTypes($events))
->each(function ($event) use ($events) {
$this->listen($event, $events);
});
} elseif ($events instanceof QueuedClosure) {
return collect($this->firstClosureParameterTypes($events->closure))
->each(function ($event) use ($events) {
$this->listen($event, $events->resolve());
});
} elseif ($listener instanceof QueuedClosure) {
$listener = $listener->resolve();
}
foreach ((array) $events as $event) {
if (Str::contains($event, '*')) {
if (str_contains($event, '*')) {
$this->setupWildcardListen($event, $listener);
} else {
$this->listeners[$event][] = $this->makeListener($listener);
$this->listeners[$event][] = $listener;
}
}
}
@@ -75,12 +103,14 @@ class Dispatcher implements DispatcherContract
* Setup a wildcard listener callback.
*
* @param string $event
* @param mixed $listener
* @param \Closure|string $listener
* @return void
*/
protected function setupWildcardListen($event, $listener)
{
$this->wildcards[$event][] = $this->makeListener($listener, true);
$this->wildcards[$event][] = $listener;
$this->wildcardsCache = [];
}
/**
@@ -91,14 +121,33 @@ class Dispatcher implements DispatcherContract
*/
public function hasListeners($eventName)
{
return isset($this->listeners[$eventName]) || isset($this->wildcards[$eventName]);
return isset($this->listeners[$eventName]) ||
isset($this->wildcards[$eventName]) ||
$this->hasWildcardListeners($eventName);
}
/**
* Determine if the given event has any wildcard listeners.
*
* @param string $eventName
* @return bool
*/
public function hasWildcardListeners($eventName)
{
foreach ($this->wildcards as $key => $listeners) {
if (Str::is($key, $eventName)) {
return true;
}
}
return false;
}
/**
* Register an event and payload to be fired later.
*
* @param string $event
* @param array $payload
* @param object|array $payload
* @return void
*/
public function push($event, $payload = [])
@@ -129,7 +178,21 @@ class Dispatcher implements DispatcherContract
{
$subscriber = $this->resolveSubscriber($subscriber);
$subscriber->subscribe($this);
$events = $subscriber->subscribe($this);
if (is_array($events)) {
foreach ($events as $event => $listeners) {
foreach (Arr::wrap($listeners) as $listener) {
if (is_string($listener) && method_exists($subscriber, $listener)) {
$this->listen($event, [get_class($subscriber), $listener]);
continue;
}
$this->listen($event, $listener);
}
}
}
}
/**
@@ -159,19 +222,6 @@ class Dispatcher implements DispatcherContract
return $this->dispatch($event, $payload, true);
}
/**
* Fire an event and call the listeners.
*
* @param string|object $event
* @param mixed $payload
* @param bool $halt
* @return array|null
*/
public function fire($event, $payload = [], $halt = false)
{
return $this->dispatch($event, $payload, $halt);
}
/**
* Fire an event and call the listeners.
*
@@ -185,7 +235,7 @@ class Dispatcher implements DispatcherContract
// When the given "event" is actually an object we will assume it is an event
// object and use the class as the event name and this event itself as the
// payload to the handler, which makes object based events quite simple.
list($event, $payload) = $this->parseEventAndPayload(
[$event, $payload] = $this->parseEventAndPayload(
$event, $payload
);
@@ -228,10 +278,10 @@ class Dispatcher implements DispatcherContract
protected function parseEventAndPayload($event, $payload)
{
if (is_object($event)) {
list($payload, $event) = [[$event], get_class($event)];
[$payload, $event] = [[$event], get_class($event)];
}
return [$event, array_wrap($payload)];
return [$event, Arr::wrap($payload)];
}
/**
@@ -248,7 +298,7 @@ class Dispatcher implements DispatcherContract
}
/**
* Check if event should be broadcasted by condition.
* Check if the event should be broadcasted by the condition.
*
* @param mixed $event
* @return bool
@@ -278,10 +328,9 @@ class Dispatcher implements DispatcherContract
*/
public function getListeners($eventName)
{
$listeners = isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : [];
$listeners = array_merge(
$listeners, $this->getWildcardListeners($eventName)
$this->prepareListeners($eventName),
$this->wildcardsCache[$eventName] ?? $this->getWildcardListeners($eventName)
);
return class_exists($eventName, false)
@@ -301,11 +350,13 @@ class Dispatcher implements DispatcherContract
foreach ($this->wildcards as $key => $listeners) {
if (Str::is($key, $eventName)) {
$wildcards = array_merge($wildcards, $listeners);
foreach ($listeners as $listener) {
$wildcards[] = $this->makeListener($listener, true);
}
}
}
return $wildcards;
return $this->wildcardsCache[$eventName] = $wildcards;
}
/**
@@ -319,7 +370,7 @@ class Dispatcher implements DispatcherContract
{
foreach (class_implements($eventName) as $interface) {
if (isset($this->listeners[$interface])) {
foreach ($this->listeners[$interface] as $names) {
foreach ($this->prepareListeners($interface) as $names) {
$listeners = array_merge($listeners, (array) $names);
}
}
@@ -328,10 +379,27 @@ class Dispatcher implements DispatcherContract
return $listeners;
}
/**
* Prepare the listeners for a given event.
*
* @param string $eventName
* @return \Closure[]
*/
protected function prepareListeners(string $eventName)
{
$listeners = [];
foreach ($this->listeners[$eventName] ?? [] as $listener) {
$listeners[] = $this->makeListener($listener);
}
return $listeners;
}
/**
* Register an event listener with the dispatcher.
*
* @param string|\Closure $listener
* @param \Closure|string|array $listener
* @param bool $wildcard
* @return \Closure
*/
@@ -341,12 +409,16 @@ class Dispatcher implements DispatcherContract
return $this->createClassListener($listener, $wildcard);
}
if (is_array($listener) && isset($listener[0]) && is_string($listener[0])) {
return $this->createClassListener($listener, $wildcard);
}
return function ($event, $payload) use ($listener, $wildcard) {
if ($wildcard) {
return $listener($event, $payload);
} else {
return $listener(...array_values($payload));
}
return $listener(...array_values($payload));
};
}
@@ -362,29 +434,39 @@ class Dispatcher implements DispatcherContract
return function ($event, $payload) use ($listener, $wildcard) {
if ($wildcard) {
return call_user_func($this->createClassCallable($listener), $event, $payload);
} else {
return call_user_func_array(
$this->createClassCallable($listener), $payload
);
}
$callable = $this->createClassCallable($listener);
return $callable(...array_values($payload));
};
}
/**
* Create the class based event callable.
*
* @param string $listener
* @param array|string $listener
* @return callable
*/
protected function createClassCallable($listener)
{
list($class, $method) = $this->parseClassCallable($listener);
[$class, $method] = is_array($listener)
? $listener
: $this->parseClassCallable($listener);
if (! method_exists($class, $method)) {
$method = '__invoke';
}
if ($this->handlerShouldBeQueued($class)) {
return $this->createQueuedHandlerCallable($class, $method);
} else {
return [$this->container->make($class), $method];
}
$listener = $this->container->make($class);
return $this->handlerShouldBeDispatchedAfterDatabaseTransactions($listener)
? $this->createCallbackForListenerRunningAfterCommits($listener, $method)
: [$listener, $method];
}
/**
@@ -429,29 +511,59 @@ class Dispatcher implements DispatcherContract
return is_object($a) ? clone $a : $a;
}, func_get_args());
if (method_exists($class, 'queue')) {
$this->callQueueMethodOnHandler($class, $method, $arguments);
} else {
if ($this->handlerWantsToBeQueued($class, $arguments)) {
$this->queueHandler($class, $method, $arguments);
}
};
}
/**
* Call the queue method on the handler class.
* Determine if the given event handler should be dispatched after all database transactions have committed.
*
* @param object|mixed $listener
* @return bool
*/
protected function handlerShouldBeDispatchedAfterDatabaseTransactions($listener)
{
return ($listener->afterCommit ?? null) && $this->container->bound('db.transactions');
}
/**
* Create a callable for dispatching a listener after database transactions.
*
* @param mixed $listener
* @param string $method
* @return \Closure
*/
protected function createCallbackForListenerRunningAfterCommits($listener, $method)
{
return function () use ($method, $listener) {
$payload = func_get_args();
$this->container->make('db.transactions')->addCallback(
function () use ($listener, $method, $payload) {
$listener->$method(...$payload);
}
);
};
}
/**
* Determine if the event handler wants to be queued.
*
* @param string $class
* @param string $method
* @param array $arguments
* @return void
* @return bool
*/
protected function callQueueMethodOnHandler($class, $method, $arguments)
protected function handlerWantsToBeQueued($class, $arguments)
{
$handler = (new ReflectionClass($class))->newInstanceWithoutConstructor();
$instance = $this->container->make($class);
$handler->queue($this->resolveQueue(), 'Illuminate\Events\CallQueuedHandler@call', [
'class' => $class, 'method' => $method, 'data' => serialize($arguments),
]);
if (method_exists($instance, 'shouldQueue')) {
return $instance->shouldQueue($arguments[0]);
}
return true;
}
/**
@@ -464,13 +576,15 @@ class Dispatcher implements DispatcherContract
*/
protected function queueHandler($class, $method, $arguments)
{
list($listener, $job) = $this->createListenerAndJob($class, $method, $arguments);
[$listener, $job] = $this->createListenerAndJob($class, $method, $arguments);
$connection = $this->resolveQueue()->connection(
isset($listener->connection) ? $listener->connection : null
);
$connection = $this->resolveQueue()->connection(method_exists($listener, 'viaConnection')
? (isset($arguments[0]) ? $listener->viaConnection($arguments[0]) : $listener->viaConnection())
: $listener->connection ?? null);
$queue = isset($listener->queue) ? $listener->queue : null;
$queue = method_exists($listener, 'viaQueue')
? (isset($arguments[0]) ? $listener->viaQueue($arguments[0]) : $listener->viaQueue())
: $listener->queue ?? null;
isset($listener->delay)
? $connection->laterOn($queue, $listener->delay, $job)
@@ -489,23 +603,35 @@ class Dispatcher implements DispatcherContract
{
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();
return [$listener, $this->propogateListenerOptions(
return [$listener, $this->propagateListenerOptions(
$listener, new CallQueuedListener($class, $method, $arguments)
)];
}
/**
* Propogate listener options to the job.
* Propagate listener options to the job.
*
* @param mixed $listener
* @param mixed $job
* @param \Illuminate\Events\CallQueuedListener $job
* @return mixed
*/
protected function propogateListenerOptions($listener, $job)
protected function propagateListenerOptions($listener, $job)
{
return tap($job, function ($job) use ($listener) {
$job->tries = isset($listener->tries) ? $listener->tries : null;
$job->timeout = isset($listener->timeout) ? $listener->timeout : null;
$data = array_values($job->data);
$job->afterCommit = property_exists($listener, 'afterCommit') ? $listener->afterCommit : null;
$job->backoff = method_exists($listener, 'backoff') ? $listener->backoff(...$data) : ($listener->backoff ?? null);
$job->maxExceptions = $listener->maxExceptions ?? null;
$job->retryUntil = method_exists($listener, 'retryUntil') ? $listener->retryUntil(...$data) : null;
$job->shouldBeEncrypted = $listener instanceof ShouldBeEncrypted;
$job->timeout = $listener->timeout ?? null;
$job->tries = $listener->tries ?? null;
$job->through(array_merge(
method_exists($listener, 'middleware') ? $listener->middleware(...$data) : [],
$listener->middleware ?? []
));
});
}
@@ -517,11 +643,17 @@ class Dispatcher implements DispatcherContract
*/
public function forget($event)
{
if (Str::contains($event, '*')) {
if (str_contains($event, '*')) {
unset($this->wildcards[$event]);
} else {
unset($this->listeners[$event]);
}
foreach ($this->wildcardsCache as $key => $listeners) {
if (Str::is($event, $key)) {
unset($this->wildcardsCache[$key]);
}
}
}
/**
@@ -532,7 +664,7 @@ class Dispatcher implements DispatcherContract
public function forgetPushed()
{
foreach ($this->listeners as $key => $value) {
if (Str::endsWith($key, '_pushed')) {
if (str_ends_with($key, '_pushed')) {
$this->forget($key);
}
}
@@ -560,4 +692,14 @@ class Dispatcher implements DispatcherContract
return $this;
}
/**
* Gets the raw, unprepared listeners.
*
* @return array
*/
public function getRawListeners()
{
return $this->listeners;
}
}

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Events;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
use Illuminate\Support\ServiceProvider;
class EventServiceProvider extends ServiceProvider
{

View File

@@ -0,0 +1,34 @@
<?php
namespace Illuminate\Events;
class InvokeQueuedClosure
{
/**
* Handle the event.
*
* @param \Laravel\SerializableClosure\SerializableClosure $closure
* @param array $arguments
* @return void
*/
public function handle($closure, array $arguments)
{
call_user_func($closure->getClosure(), ...$arguments);
}
/**
* Handle a job failure.
*
* @param \Laravel\SerializableClosure\SerializableClosure $closure
* @param array $arguments
* @param array $catchCallbacks
* @param \Throwable $exception
* @return void
*/
public function failed($closure, array $arguments, array $catchCallbacks, $exception)
{
$arguments[] = $exception;
collect($catchCallbacks)->each->__invoke(...$arguments);
}
}

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,144 @@
<?php
namespace Illuminate\Events;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Support\Traits\ForwardsCalls;
class NullDispatcher implements DispatcherContract
{
use ForwardsCalls;
/**
* The underlying event dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $dispatcher;
/**
* Create a new event dispatcher instance that does not fire.
*
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @return void
*/
public function __construct(DispatcherContract $dispatcher)
{
$this->dispatcher = $dispatcher;
}
/**
* Don't fire an event.
*
* @param string|object $event
* @param mixed $payload
* @param bool $halt
* @return void
*/
public function dispatch($event, $payload = [], $halt = false)
{
//
}
/**
* Don't register an event and payload to be fired later.
*
* @param string $event
* @param array $payload
* @return void
*/
public function push($event, $payload = [])
{
//
}
/**
* Don't dispatch an event.
*
* @param string|object $event
* @param mixed $payload
* @return array|null
*/
public function until($event, $payload = [])
{
//
}
/**
* Register an event listener with the dispatcher.
*
* @param \Closure|string|array $events
* @param \Closure|string|array|null $listener
* @return void
*/
public function listen($events, $listener = null)
{
$this->dispatcher->listen($events, $listener);
}
/**
* Determine if a given event has listeners.
*
* @param string $eventName
* @return bool
*/
public function hasListeners($eventName)
{
return $this->dispatcher->hasListeners($eventName);
}
/**
* Register an event subscriber with the dispatcher.
*
* @param object|string $subscriber
* @return void
*/
public function subscribe($subscriber)
{
$this->dispatcher->subscribe($subscriber);
}
/**
* Flush a set of pushed events.
*
* @param string $event
* @return void
*/
public function flush($event)
{
$this->dispatcher->flush($event);
}
/**
* Remove a set of listeners from the dispatcher.
*
* @param string $event
* @return void
*/
public function forget($event)
{
$this->dispatcher->forget($event);
}
/**
* Forget all of the queued listeners.
*
* @return void
*/
public function forgetPushed()
{
$this->dispatcher->forgetPushed();
}
/**
* Dynamically pass method calls to the underlying dispatcher.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->forwardDecoratedCallTo($this->dispatcher, $method, $parameters);
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Illuminate\Events;
use Closure;
use Laravel\SerializableClosure\SerializableClosure;
class QueuedClosure
{
/**
* The underlying Closure.
*
* @var \Closure
*/
public $closure;
/**
* The name of the connection the job should be sent to.
*
* @var string|null
*/
public $connection;
/**
* The name of the queue the job should be sent to.
*
* @var string|null
*/
public $queue;
/**
* The number of seconds before the job should be made available.
*
* @var \DateTimeInterface|\DateInterval|int|null
*/
public $delay;
/**
* All of the "catch" callbacks for the queued closure.
*
* @var array
*/
public $catchCallbacks = [];
/**
* Create a new queued closure event listener resolver.
*
* @param \Closure $closure
* @return void
*/
public function __construct(Closure $closure)
{
$this->closure = $closure;
}
/**
* Set the desired connection for the job.
*
* @param string|null $connection
* @return $this
*/
public function onConnection($connection)
{
$this->connection = $connection;
return $this;
}
/**
* Set the desired queue for the job.
*
* @param string|null $queue
* @return $this
*/
public function onQueue($queue)
{
$this->queue = $queue;
return $this;
}
/**
* Set the desired delay in seconds for the job.
*
* @param \DateTimeInterface|\DateInterval|int|null $delay
* @return $this
*/
public function delay($delay)
{
$this->delay = $delay;
return $this;
}
/**
* Specify a callback that should be invoked if the queued listener job fails.
*
* @param \Closure $closure
* @return $this
*/
public function catch(Closure $closure)
{
$this->catchCallbacks[] = $closure;
return $this;
}
/**
* Resolve the actual event listener callback.
*
* @return \Closure
*/
public function resolve()
{
return function (...$arguments) {
dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [
'closure' => new SerializableClosure($this->closure),
'arguments' => $arguments,
'catch' => collect($this->catchCallbacks)->map(function ($callback) {
return new SerializableClosure($callback);
})->all(),
]))->onConnection($this->connection)->onQueue($this->queue)->delay($this->delay);
};
}
}

View File

@@ -14,19 +14,25 @@
}
],
"require": {
"php": ">=5.6.4",
"illuminate/container": "5.4.*",
"illuminate/contracts": "5.4.*",
"illuminate/support": "5.4.*"
"php": "^8.0.2",
"illuminate/bus": "^9.0",
"illuminate/collections": "^9.0",
"illuminate/container": "^9.0",
"illuminate/contracts": "^9.0",
"illuminate/macroable": "^9.0",
"illuminate/support": "^9.0"
},
"autoload": {
"psr-4": {
"Illuminate\\Events\\": ""
}
},
"files": [
"functions.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
"dev-master": "9.x-dev"
}
},
"config": {

View File

@@ -0,0 +1,18 @@
<?php
namespace Illuminate\Events;
use Closure;
if (! function_exists('Illuminate\Events\queueable')) {
/**
* Create a new queued Closure event listener.
*
* @param \Closure $closure
* @return \Illuminate\Events\QueuedClosure
*/
function queueable(Closure $closure)
{
return new QueuedClosure($closure);
}
}