This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -9,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
class CallQueuedListener implements ShouldQueue
{
use InteractsWithQueue;
use InteractsWithQueue, Queueable;
/**
* The listener class name.
@@ -40,18 +41,25 @@ class CallQueuedListener implements ShouldQueue
public $tries;
/**
* The number of seconds to wait before retrying the job.
* The maximum number of exceptions allowed, regardless of attempts.
*
* @var int
*/
public $retryAfter;
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 $timeoutAt;
public $retryUntil;
/**
* The number of seconds the job can run before timing out.
@@ -60,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.
*

100
vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php vendored Normal file → Executable file
View File

@@ -2,21 +2,24 @@
namespace Illuminate\Events;
use Closure;
use Exception;
use Illuminate\Container\Container;
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;
use Macroable, ReflectsClosures;
/**
* The IoC container instance.
@@ -67,12 +70,26 @@ class Dispatcher implements DispatcherContract
/**
* Register an event listener with the dispatcher.
*
* @param string|array $events
* @param \Closure|string $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, '*')) {
$this->setupWildcardListen($event, $listener);
@@ -165,7 +182,13 @@ class Dispatcher implements DispatcherContract
if (is_array($events)) {
foreach ($events as $event => $listeners) {
foreach ($listeners as $listener) {
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);
}
}
@@ -275,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
@@ -359,7 +382,7 @@ class Dispatcher implements DispatcherContract
/**
* Register an event listener with the dispatcher.
*
* @param \Closure|string $listener
* @param \Closure|string|array $listener
* @param bool $wildcard
* @return \Closure
*/
@@ -414,11 +437,19 @@ class Dispatcher implements DispatcherContract
? $listener
: $this->parseClassCallable($listener);
if (! method_exists($class, $method)) {
$method = '__invoke';
}
if ($this->handlerShouldBeQueued($class)) {
return $this->createQueuedHandlerCallable($class, $method);
}
return [$this->container->make($class), $method];
$listener = $this->container->make($class);
return $this->handlerShouldBeDispatchedAfterDatabaseTransactions($listener)
? $this->createCallbackForListenerRunningAfterCommits($listener, $method)
: [$listener, $method];
}
/**
@@ -469,6 +500,37 @@ class Dispatcher implements DispatcherContract
};
}
/**
* 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.
*
@@ -499,9 +561,9 @@ class Dispatcher implements DispatcherContract
{
[$listener, $job] = $this->createListenerAndJob($class, $method, $arguments);
$connection = $this->resolveQueue()->connection(
$listener->connection ?? null
);
$connection = $this->resolveQueue()->connection(method_exists($listener, 'viaConnection')
? $listener->viaConnection()
: $listener->connection ?? null);
$queue = method_exists($listener, 'viaQueue')
? $listener->viaQueue()
@@ -539,12 +601,18 @@ class Dispatcher implements DispatcherContract
protected function propagateListenerOptions($listener, $job)
{
return tap($job, function ($job) use ($listener) {
$job->tries = $listener->tries ?? null;
$job->retryAfter = method_exists($listener, 'retryAfter')
? $listener->retryAfter() : ($listener->retryAfter ?? null);
$job->afterCommit = property_exists($listener, 'afterCommit') ? $listener->afterCommit : null;
$job->backoff = method_exists($listener, 'backoff') ? $listener->backoff() : ($listener->backoff ?? null);
$job->maxExceptions = $listener->maxExceptions ?? null;
$job->retryUntil = method_exists($listener, 'retryUntil') ? $listener->retryUntil() : null;
$job->shouldBeEncrypted = $listener instanceof ShouldBeEncrypted;
$job->timeout = $listener->timeout ?? null;
$job->timeoutAt = method_exists($listener, 'retryUntil')
? $listener->retryUntil() : null;
$job->tries = $listener->tries ?? null;
$job->through(array_merge(
method_exists($listener, 'middleware') ? $listener->middleware() : [],
$listener->middleware ?? []
));
});
}

View File

View File

@@ -12,7 +12,7 @@ class NullDispatcher implements DispatcherContract
/**
* The underlying event dispatcher instance.
*
* @var \Illuminate\Contracts\Bus\Dispatcher
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $dispatcher;
@@ -37,6 +37,7 @@ class NullDispatcher implements DispatcherContract
*/
public function dispatch($event, $payload = [], $halt = false)
{
//
}
/**
@@ -48,6 +49,7 @@ class NullDispatcher implements DispatcherContract
*/
public function push($event, $payload = [])
{
//
}
/**
@@ -59,16 +61,17 @@ class NullDispatcher implements DispatcherContract
*/
public function until($event, $payload = [])
{
//
}
/**
* Register an event listener with the dispatcher.
*
* @param string|array $events
* @param \Closure|string $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)
{
$this->dispatcher->listen($events, $listener);
}

18
vendor/laravel/framework/src/Illuminate/Events/composer.json vendored Normal file → Executable file
View File

@@ -14,19 +14,25 @@
}
],
"require": {
"php": "^7.2.5|^8.0",
"illuminate/container": "^7.0",
"illuminate/contracts": "^7.0",
"illuminate/support": "^7.0"
"php": "^7.3|^8.0",
"illuminate/bus": "^8.0",
"illuminate/collections": "^8.0",
"illuminate/container": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/macroable": "^8.0",
"illuminate/support": "^8.0"
},
"autoload": {
"psr-4": {
"Illuminate\\Events\\": ""
}
},
"files": [
"functions.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "7.x-dev"
"dev-master": "8.x-dev"
}
},
"config": {