Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/11.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 4, 2024
2 parents 7429e4a + 4dee6b3 commit 17c4d0a
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 31 deletions.
5 changes: 3 additions & 2 deletions AbstractRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Countable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use IteratorAggregate;
use LogicException;
Expand Down Expand Up @@ -78,7 +79,7 @@ function ($method) use ($request) {
*/
protected function matchAgainstRoutes(array $routes, $request, $includingMethod = true)
{
[$fallbacks, $routes] = collect($routes)->partition(function ($route) {
[$fallbacks, $routes] = (new Collection($routes))->partition(function ($route) {
return $route->isFallback;
});

Expand Down Expand Up @@ -113,7 +114,7 @@ protected function getRouteForMethods($request, array $methods)
* @param \Illuminate\Http\Request $request
* @param array $others
* @param string $method
* @return void
* @return never
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
Expand Down
8 changes: 4 additions & 4 deletions CompiledRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function getByName($name)
*/
public function getByAction($action)
{
$attributes = collect($this->attributes)->first(function (array $attributes) use ($action) {
$attributes = (new Collection($this->attributes))->first(function (array $attributes) use ($action) {
if (isset($attributes['action']['controller'])) {
return trim($attributes['action']['controller'], '\\') === $action;
}
Expand All @@ -230,7 +230,7 @@ public function getByAction($action)
*/
public function getRoutes()
{
return collect($this->attributes)
return (new Collection($this->attributes))
->map(function (array $attributes) {
return $this->newRoute($attributes);
})
Expand All @@ -246,7 +246,7 @@ public function getRoutes()
*/
public function getRoutesByMethod()
{
return collect($this->getRoutes())
return (new Collection($this->getRoutes()))
->groupBy(function (Route $route) {
return $route->methods();
})
Expand All @@ -265,7 +265,7 @@ public function getRoutesByMethod()
*/
public function getRoutesByName()
{
return collect($this->getRoutes())
return (new Collection($this->getRoutes()))
->keyBy(function (Route $route) {
return $route->getName();
})
Expand Down
3 changes: 2 additions & 1 deletion ControllerDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Container\Container;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;
use Illuminate\Support\Collection;

class ControllerDispatcher implements ControllerDispatcherContract
{
Expand Down Expand Up @@ -74,7 +75,7 @@ public function getMiddleware($controller, $method)
return [];
}

return collect($controller->getMiddleware())->reject(function ($data) use ($method) {
return (new Collection($controller->getMiddleware()))->reject(function ($data) use ($method) {
return static::methodExcludedByOptions($method, $data['options']);
})->pluck('middleware')->all();
}
Expand Down
3 changes: 2 additions & 1 deletion Middleware/ThrottleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Exceptions\ThrottleRequestsException;
use Illuminate\Routing\Exceptions\MissingRateLimiterException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\InteractsWithTime;
use RuntimeException;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -127,7 +128,7 @@ protected function handleRequestUsingNamedLimiter($request, Closure $next, $limi
return $this->handleRequest(
$request,
$next,
collect(Arr::wrap($limiterResponse))->map(function ($limit) use ($limiterName) {
(new Collection(Arr::wrap($limiterResponse)))->map(function ($limit) use ($limiterName) {
return (object) [
'key' => self::$shouldHashKeys ? md5($limiterName.$limit->key) : $limiterName.':'.$limit->key,
'maxAttempts' => $limit->maxAttempts,
Expand Down
3 changes: 2 additions & 1 deletion RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

class RedirectController extends Controller
Expand All @@ -17,7 +18,7 @@ class RedirectController extends Controller
*/
public function __invoke(Request $request, UrlGenerator $url)
{
$parameters = collect($request->route()->parameters());
$parameters = new Collection($request->route()->parameters());

$status = $parameters->get('status');

Expand Down
6 changes: 4 additions & 2 deletions Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Illuminate\Routing\Matching\SchemeValidator;
use Illuminate\Routing\Matching\UriValidator;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use Laravel\SerializableClosure\SerializableClosure;
Expand All @@ -27,7 +29,7 @@

class Route
{
use CreatesRegularExpressionRouteConstraints, FiltersControllerMiddleware, Macroable, ResolvesRouteDependencies;
use Conditionable, CreatesRegularExpressionRouteConstraints, FiltersControllerMiddleware, Macroable, ResolvesRouteDependencies;

/**
* The URI pattern the route responds to.
Expand Down Expand Up @@ -1136,7 +1138,7 @@ public function controllerMiddleware()
*/
protected function staticallyProvidedControllerMiddleware(string $class, string $method)
{
return collect($class::middleware())->map(function ($middleware) {
return (new Collection($class::middleware()))->map(function ($middleware) {
return $middleware instanceof Middleware
? $middleware
: new Middleware($middleware);
Expand Down
6 changes: 3 additions & 3 deletions Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,11 @@ public function gatherRouteMiddleware(Route $route)
*/
public function resolveMiddleware(array $middleware, array $excluded = [])
{
$excluded = collect($excluded)->map(function ($name) {
$excluded = (new Collection($excluded))->map(function ($name) {
return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
})->flatten()->values()->all();

$middleware = collect($middleware)->map(function ($name) {
$middleware = (new Collection($middleware))->map(function ($name) {
return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
})->flatten()->reject(function ($name) use ($excluded) {
if (empty($excluded)) {
Expand All @@ -854,7 +854,7 @@ public function resolveMiddleware(array $middleware, array $excluded = [])

$reflection = new ReflectionClass($name);

return collect($excluded)->contains(
return (new Collection($excluded))->contains(
fn ($exclude) => class_exists($exclude) && $reflection->isSubclassOf($exclude)
);
})->values();
Expand Down
17 changes: 7 additions & 10 deletions RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;
use Illuminate\Support\ServiceProvider;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response as PsrResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Symfony\Component\HttpFoundation\Response;

class RoutingServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -134,10 +133,8 @@ protected function registerRedirector()
protected function registerPsrRequest()
{
$this->app->bind(ServerRequestInterface::class, function ($app) {
if (class_exists(Psr17Factory::class) && class_exists(PsrHttpFactory::class)) {
$psr17Factory = new Psr17Factory;

return with((new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory))
if (class_exists(PsrHttpFactory::class)) {
return with((new PsrHttpFactory)
->createRequest($illuminateRequest = $app->make('request')), function (ServerRequestInterface $request) use ($illuminateRequest) {
if ($illuminateRequest->getContentTypeFormat() !== 'json' && $illuminateRequest->request->count() === 0) {
return $request;
Expand All @@ -149,7 +146,7 @@ protected function registerPsrRequest()
});
}

throw new BindingResolutionException('Unable to resolve PSR request. Please install the symfony/psr-http-message-bridge and nyholm/psr7 packages.');
throw new BindingResolutionException('Unable to resolve PSR request. Please install the "symfony/psr-http-message-bridge" package.');
});
}

Expand All @@ -161,11 +158,11 @@ protected function registerPsrRequest()
protected function registerPsrResponse()
{
$this->app->bind(ResponseInterface::class, function () {
if (class_exists(PsrResponse::class)) {
return new PsrResponse;
if (class_exists(PsrHttpFactory::class)) {
return (new PsrHttpFactory)->createResponse(new Response);
}

throw new BindingResolutionException('Unable to resolve PSR response. Please install the nyholm/psr7 package.');
throw new BindingResolutionException('Unable to resolve PSR response. Please install the "symfony/psr-http-message-bridge" package.');
});
}

Expand Down
5 changes: 3 additions & 2 deletions UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\InteractsWithTime;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
Expand Down Expand Up @@ -453,7 +454,7 @@ public function hasCorrectSignature(Request $request, $absolute = true, array $i

$url = $absolute ? $request->url() : '/'.$request->path();

$queryString = collect(explode('&', (string) $request->server->get('QUERY_STRING')))
$queryString = (new Collection(explode('&', (string) $request->server->get('QUERY_STRING'))))
->reject(fn ($parameter) => in_array(Str::before($parameter, '='), $ignoreQuery))
->join('&');

Expand Down Expand Up @@ -528,7 +529,7 @@ public function route($name, $parameters = [], $absolute = true)
*/
public function toRoute($route, $parameters, $absolute)
{
$parameters = collect(Arr::wrap($parameters))->map(function ($value, $key) use ($route) {
$parameters = (new Collection(Arr::wrap($parameters)))->map(function ($value, $key) use ($route) {
return $value instanceof UrlRoutable && $route->bindingFieldFor($key)
? $value->{$route->bindingFieldFor($key)}
: $value;
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"illuminate/pipeline": "^12.0",
"illuminate/session": "^12.0",
"illuminate/support": "^12.0",
"symfony/http-foundation": "^7.0",
"symfony/http-kernel": "^7.0",
"symfony/routing": "^7.0"
"symfony/http-foundation": "^7.0.3",
"symfony/http-kernel": "^7.0.3",
"symfony/routing": "^7.0.3"
},
"autoload": {
"psr-4": {
Expand All @@ -41,11 +41,14 @@
},
"suggest": {
"illuminate/console": "Required to use the make commands (^12.0).",
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
"php-http/discovery": "Required to use PSR-7 bridging features (^1.15).",
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^7.0)."
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": false
}
},
"minimum-stability": "dev"
}

0 comments on commit 17c4d0a

Please sign in to comment.