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 May 15, 2023
2 parents 893d8fc + 38693f4 commit a7be8bf
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 36 deletions.
1 change: 0 additions & 1 deletion phpstan.src.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ parameters:
- "#Class [a-zA-Z0-9\\\\_]+ not found.#"
- "#has invalid type#"
- "#should always throw an exception or terminate script execution#"
- "#Function GuzzleHttp\\\\Psr7#"
- "#Instantiated class [a-zA-Z0-9\\\\_]+ not found.#"
- "#Unsafe usage of new static#"
excludePaths:
Expand Down
25 changes: 16 additions & 9 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,19 +969,26 @@ protected function ensureOrderForCursorPagination($shouldReverse = false)
$this->enforceOrderBy();
}

if ($shouldReverse) {
$this->query->orders = collect($this->query->orders)->map(function ($order) {
$order['direction'] = $order['direction'] === 'asc' ? 'desc' : 'asc';

$reverseDirection = function ($order) {
if (! isset($order['direction'])) {
return $order;
})->toArray();
}
}

$order['direction'] = $order['direction'] === 'asc' ? 'desc' : 'asc';

if ($this->query->unionOrders) {
return collect($this->query->unionOrders);
return $order;
};

if ($shouldReverse) {
$this->query->orders = collect($this->query->orders)->map($reverseDirection)->toArray();
$this->query->unionOrders = collect($this->query->unionOrders)->map($reverseDirection)->toArray();
}

return collect($this->query->orders);
$orders = ! empty($this->query->unionOrders) ? $this->query->unionOrders : $this->query->orders;

return collect($orders)
->filter(fn ($order) => Arr::has($order, 'direction'))
->values();
}

/**
Expand Down
31 changes: 22 additions & 9 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2793,17 +2793,30 @@ public function cursorPaginate($perPage = 15, $columns = ['*'], $cursorName = 'c
*/
protected function ensureOrderForCursorPagination($shouldReverse = false)
{
$this->enforceOrderBy();

return collect($this->orders ?? $this->unionOrders ?? [])->filter(function ($order) {
return Arr::has($order, 'direction');
})->when($shouldReverse, function (Collection $orders) {
return $orders->map(function ($order) {
$order['direction'] = $order['direction'] === 'asc' ? 'desc' : 'asc';
if (empty($this->orders) && empty($this->unionOrders)) {
$this->enforceOrderBy();
}

$reverseDirection = function ($order) {
if (! isset($order['direction'])) {
return $order;
});
})->values();
}

$order['direction'] = $order['direction'] === 'asc' ? 'desc' : 'asc';

return $order;
};

if ($shouldReverse) {
$this->orders = collect($this->orders)->map($reverseDirection)->toArray();
$this->unionOrders = collect($this->unionOrders)->map($reverseDirection)->toArray();
}

$orders = ! empty($this->unionOrders) ? $this->unionOrders : $this->orders;

return collect($orders)
->filter(fn ($order) => Arr::has($order, 'direction'))
->values();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Precognition.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function afterValidationHook($request)
{
return function ($validator) use ($request) {
if ($validator->messages()->isEmpty() && $request->headers->has('Precognition-Validate-Only')) {
abort(204);
abort(204, headers: ['Precognition-Success' => 'true']);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function dispatch(Route $route, $callable)
{
$this->resolveParameters($route, $callable);

abort(204);
abort(204, headers: ['Precognition-Success' => 'true']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function dispatch(Route $route, $controller, $method)

$this->resolveParameters($route, $controller, $method);

abort(204);
abort(204, headers: ['Precognition-Success' => 'true']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Foundation\Mix;
use Illuminate\Foundation\Vite;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\HtmlString;
use Mockery;

Expand Down Expand Up @@ -110,6 +111,8 @@ protected function withoutVite()
$this->originalVite = app(Vite::class);
}

Facade::clearResolvedInstance(Vite::class);

$this->swap(Vite::class, new class
{
public function __invoke()
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ function precognitive($callable = null)
});

if (request()->isPrecognitive()) {
abort(204);
abort(204, headers: ['Precognition-Success' => 'true']);
}

return $payload;
Expand Down
5 changes: 2 additions & 3 deletions 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\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Response as Psr7Response;
use GuzzleHttp\TransferStats;
Expand Down Expand Up @@ -93,9 +94,7 @@ public static function response($body = null, $status = 200, $headers = [])

$response = new Psr7Response($status, $headers, $body);

return class_exists(\GuzzleHttp\Promise\Create::class)
? \GuzzleHttp\Promise\Create::promiseFor($response)
: \GuzzleHttp\Promise\promise_for($response);
return Create::promiseFor($response);
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Illuminate/Http/Client/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ class Pool
public function __construct(Factory $factory = null)
{
$this->factory = $factory ?: new Factory();

if (method_exists(Utils::class, 'chooseHandler')) {
$this->handler = Utils::chooseHandler();
} else {
$this->handler = \GuzzleHttp\choose_handler();
}
$this->handler = Utils::chooseHandler();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Http/Client/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Http\Client;

use GuzzleHttp\Psr7\Message;

class RequestException extends HttpClientException
{
/**
Expand Down Expand Up @@ -34,9 +36,7 @@ protected function prepareMessage(Response $response)
{
$message = "HTTP request returned status code {$response->status()}";

$summary = class_exists(\GuzzleHttp\Psr7\Message::class)
? \GuzzleHttp\Psr7\Message::bodySummary($response->toPsrResponse())
: \GuzzleHttp\Psr7\get_message_body_summary($response->toPsrResponse());
$summary = Message::bodySummary($response->toPsrResponse());

return is_null($summary) ? $message : $message .= ":\n{$summary}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5008,7 +5008,7 @@ public function testCursorPaginateWithUnionWheresReverseOrder()

$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
$this->assertEquals(
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ?)) union (select "id", "created_at", \'news\' as type from "news" where ("start_time" < ?)) order by "created_at" asc limit 17',
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ?)) union (select "id", "created_at", \'news\' as type from "news" where ("start_time" < ?)) order by "created_at" desc limit 17',
$builder->toSql());
$this->assertEquals([$ts], $builder->bindings['where']);
$this->assertEquals([$ts], $builder->bindings['union']);
Expand Down
Loading

0 comments on commit a7be8bf

Please sign in to comment.