Skip to content

Commit

Permalink
Merge branch '10.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Jun 27, 2023
2 parents c39a156 + aa18c13 commit c5a7c14
Show file tree
Hide file tree
Showing 34 changed files with 420 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function flush()
/**
* Remove all expired tag set entries.
*
* @return bool
* @return void
*/
public function flushStaleTags()
{
Expand Down
22 changes: 9 additions & 13 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,21 +955,17 @@ protected function getArrayableItems($items)
{
if (is_array($items)) {
return $items;
} elseif ($items instanceof Enumerable) {
return $items->all();
} elseif ($items instanceof Arrayable) {
return $items->toArray();
} elseif ($items instanceof Traversable) {
return iterator_to_array($items);
} elseif ($items instanceof Jsonable) {
return json_decode($items->toJson(), true);
} elseif ($items instanceof JsonSerializable) {
return (array) $items->jsonSerialize();
} elseif ($items instanceof UnitEnum) {
return [$items];
}

return (array) $items;
return match (true) {
$items instanceof Enumerable => $items->all(),
$items instanceof Arrayable => $items->toArray(),
$items instanceof Traversable => iterator_to_array($items),
$items instanceof Jsonable => json_decode($items->toJson(), true),
$items instanceof JsonSerializable => (array) $items->jsonSerialize(),
$items instanceof UnitEnum => [$items],
default => (array) $items,
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Signals.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function initializeSignal($signal)
/**
* Unregister the current signal handlers.
*
* @return array<int, array<int, callable(int $signal): void>>
* @return void
*/
public function unregister()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function subscribe($subscriber);
*
* @param string|object $event
* @param mixed $payload
* @return array|null
* @return mixed
*/
public function until($event, $payload = []);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Console/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DumpCommand extends Command
*
* @param \Illuminate\Database\ConnectionResolverInterface $connections
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @return int
* @return void
*/
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function handle()
* @param string $name
* @param string $table
* @param bool $create
* @return string
* @return void
*/
protected function writeMigration($name, $table, $create)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ public function loadMissing($relations)
*
* @param array|string $relations
* @param string $column
* @param string $function
* @param string|null $function
* @return $this
*/
public function loadAggregate($relations, $column, $function = null)
Expand Down Expand Up @@ -834,7 +834,7 @@ public function loadExists($relations)
* @param string $relation
* @param array $relations
* @param string $column
* @param string $function
* @param string|null $function
* @return $this
*/
public function loadMorphAggregate($relation, $relations, $column, $function = null)
Expand Down
27 changes: 10 additions & 17 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,23 +754,16 @@ protected function compileHaving(array $having)
// If the having clause is "raw", we can just return the clause straight away
// without doing any more processing on it. Otherwise, we will compile the
// clause into SQL based on the components that make it up from builder.
if ($having['type'] === 'Raw') {
return $having['sql'];
} elseif ($having['type'] === 'between') {
return $this->compileHavingBetween($having);
} elseif ($having['type'] === 'Null') {
return $this->compileHavingNull($having);
} elseif ($having['type'] === 'NotNull') {
return $this->compileHavingNotNull($having);
} elseif ($having['type'] === 'bit') {
return $this->compileHavingBit($having);
} elseif ($having['type'] === 'Expression') {
return $this->compileHavingExpression($having);
} elseif ($having['type'] === 'Nested') {
return $this->compileNestedHavings($having);
}

return $this->compileBasicHaving($having);
return match ($having['type']) {
'Raw' => $having['sql'],
'between' => $this->compileHavingBetween($having),
'Null' => $this->compileHavingNull($having),
'NotNull' => $this->compileHavingNotNull($having),
'bit' => $this->compileHavingBit($having),
'Expression' => $this->compileHavingExpression($having),
'Nested' => $this->compileNestedHavings($having),
default => $this->compileBasicHaving($having),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function resolveSubscriber($subscriber)
*
* @param string|object $event
* @param mixed $payload
* @return array|null
* @return mixed
*/
public function until($event, $payload = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Events/NullDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function push($event, $payload = [])
*
* @param string|object $event
* @param mixed $payload
* @return array|null
* @return mixed
*/
public function until($event, $payload = [])
{
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public function terminate($input, $status)
{
$this->app->terminate();

$this->commandStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');

foreach ($this->commandLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
$end ??= Carbon::now();

Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ public function report(Throwable $e)
return;
}

$this->reportThrowable($e);
}

/**
* Reports error based on report method on exception or to logger.
*
* @param \Throwable $e
* @return void
*
* @throws \Throwable
*/
protected function reportThrowable(Throwable $e): void
{
if (Reflector::isCallable($reportCallable = [$e, 'report']) &&
$this->container->call($reportCallable) !== false) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public function terminate($request, $response)

$this->app->terminate();

$this->requestStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');

foreach ($this->requestLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
$end ??= Carbon::now();

Expand Down
49 changes: 48 additions & 1 deletion src/Illuminate/Http/Client/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Http\Client;

use Closure;
use GuzzleHttp\Middleware;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Response as Psr7Response;
Expand All @@ -28,6 +29,13 @@ class Factory
*/
protected $dispatcher;

/**
* The middleware to apply to every request.
*
* @var array
*/
protected $globalMiddleware = [];

/**
* The stub callables that will handle requests.
*
Expand Down Expand Up @@ -76,6 +84,45 @@ public function __construct(Dispatcher $dispatcher = null)
$this->stubCallbacks = collect();
}

/**
* Add middleware to apply to every request.
*
* @param callable $middleware
* @return $this
*/
public function globalMiddleware($middleware)
{
$this->globalMiddleware[] = $middleware;

return $this;
}

/**
* Add request middleware to apply to every request.
*
* @param callable $middleware
* @return $this
*/
public function globalRequestMiddleware($middleware)
{
$this->globalMiddleware[] = Middleware::mapRequest($middleware);

return $this;
}

/**
* Add response middleware to apply to every request.
*
* @param callable $middleware
* @return $this
*/
public function globalResponseMiddleware($middleware)
{
$this->globalMiddleware[] = Middleware::mapResponse($middleware);

return $this;
}

/**
* Create a new response instance for use during stubbing.
*
Expand Down Expand Up @@ -353,7 +400,7 @@ public function recorded($callback = null)
*/
protected function newPendingRequest()
{
return new PendingRequest($this);
return new PendingRequest($this, $this->globalMiddleware);
}

/**
Expand Down
32 changes: 30 additions & 2 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\UriTemplate\UriTemplate;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Client\Events\ConnectionFailed;
Expand Down Expand Up @@ -216,12 +217,13 @@ class PendingRequest
* Create a new HTTP Client instance.
*
* @param \Illuminate\Http\Client\Factory|null $factory
* @param array $middleware
* @return void
*/
public function __construct(Factory $factory = null)
public function __construct(Factory $factory = null, $middleware = [])
{
$this->factory = $factory;
$this->middleware = new Collection;
$this->middleware = new Collection($middleware);

$this->asJson();

Expand Down Expand Up @@ -642,6 +644,32 @@ public function withMiddleware(callable $middleware)
return $this;
}

/**
* Add new request middleware the client handler stack.
*
* @param callable $middleware
* @return $this
*/
public function withRequestMiddleware(callable $middleware)
{
$this->middleware->push(Middleware::mapRequest($middleware));

return $this;
}

/**
* Add new response middleware the client handler stack.
*
* @param callable $middleware
* @return $this
*/
public function withResponseMiddleware(callable $middleware)
{
$this->middleware->push(Middleware::mapResponse($middleware));

return $this;
}

/**
* Add a new "before sending" callback to the request.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Client/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getRequests()
*
* @param string $method
* @param array $parameters
* @return \Illuminate\Http\Client\PendingRequest
* @return \Illuminate\Http\Client\PendingRequest|\GuzzleHttp\Promise\Promise
*/
public function __call($method, $parameters)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Log/ParsesLogConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected function level(array $config)
*
* @param array $config
* @return int
*
* @throws \InvalidArgumentException
*/
protected function actionLevel(array $config)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Process/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public function assertRanTimes(Closure|string $callback, int $times = 1)
$times, $count,
"An expected process ran {$count} times instead of {$times} times."
);

return $this;
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/Illuminate/Process/PendingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,15 @@ protected function resolveSynchronousFake(string $command, Closure $fake)

if (is_string($result) || is_array($result)) {
return (new FakeProcessResult(output: $result))->withCommand($command);
} elseif ($result instanceof ProcessResult) {
return $result;
} elseif ($result instanceof FakeProcessResult) {
return $result->withCommand($command);
} elseif ($result instanceof FakeProcessDescription) {
return $result->toProcessResult($command);
} elseif ($result instanceof FakeProcessSequence) {
return $this->resolveSynchronousFake($command, fn () => $result());
}

throw new LogicException('Unsupported synchronous process fake result provided.');
return match (true) {
$result instanceof ProcessResult => $result,
$result instanceof FakeProcessResult => $result->withCommand($command),
$result instanceof FakeProcessDescription => $result->toProcessResult($command),
$result instanceof FakeProcessSequence => $this->resolveSynchronousFake($command, fn () => $result()),
default => throw new LogicException('Unsupported synchronous process fake result provided.'),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
* @param string $job
* @param mixed $data
* @param string|null $queue
* @return void
* @return mixed
*/
public function later($delay, $job, $data = '', $queue = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @method static void push(string $event, object|array $payload = [])
* @method static void flush(string $event)
* @method static void subscribe(object|string $subscriber)
* @method static array|null until(string|object $event, mixed $payload = [])
* @method static mixed until(string|object $event, mixed $payload = [])
* @method static array|null dispatch(string|object $event, mixed $payload = [], bool $halt = false)
* @method static array getListeners(string $eventName)
* @method static \Closure makeListener(\Closure|string|array $listener, bool $wildcard = false)
Expand Down
Loading

0 comments on commit c5a7c14

Please sign in to comment.