Skip to content

Commit 1cdf4d9

Browse files
committed
Merge remote-tracking branch 'upstream/8.x' into 8.x
2 parents bf3092a + 041f016 commit 1cdf4d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1142
-95
lines changed

src/Illuminate/Auth/SessionGuard.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
1818
use Illuminate\Contracts\Events\Dispatcher;
1919
use Illuminate\Contracts\Session\Session;
20+
use Illuminate\Support\Arr;
2021
use Illuminate\Support\Facades\Hash;
2122
use Illuminate\Support\Str;
2223
use Illuminate\Support\Traits\Macroable;
@@ -374,6 +375,34 @@ public function attempt(array $credentials = [], $remember = false)
374375
return false;
375376
}
376377

378+
/**
379+
* Attempt to authenticate a user with credentials and additional callbacks.
380+
*
381+
* @param array $credentials
382+
* @param array|callable $callbacks
383+
* @param false $remember
384+
* @return bool
385+
*/
386+
public function attemptWhen(array $credentials = [], $callbacks = null, $remember = false)
387+
{
388+
$this->fireAttemptEvent($credentials, $remember);
389+
390+
$this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials);
391+
392+
// This method does the exact same thing as attempt, but also executes callbacks after
393+
// the user is retrieved and validated. If one of the callbacks returns falsy we do
394+
// not login the user. Instead, we will fail the specific authentication attempt.
395+
if ($this->hasValidCredentials($user, $credentials) && $this->shouldLogin($callbacks, $user)) {
396+
$this->login($user, $remember);
397+
398+
return true;
399+
}
400+
401+
$this->fireFailedEvent($user, $credentials);
402+
403+
return false;
404+
}
405+
377406
/**
378407
* Determine if the user matches the credentials.
379408
*
@@ -392,6 +421,24 @@ protected function hasValidCredentials($user, $credentials)
392421
return $validated;
393422
}
394423

424+
/**
425+
* Determine if the user should login by executing the given callbacks.
426+
*
427+
* @param array|callable|null $callbacks
428+
* @param \Illuminate\Contracts\Auth\Authenticatable $user
429+
* @return bool
430+
*/
431+
protected function shouldLogin($callbacks, AuthenticatableContract $user)
432+
{
433+
foreach (Arr::wrap($callbacks) as $callback) {
434+
if (! $callback($user, $this)) {
435+
return false;
436+
}
437+
}
438+
439+
return true;
440+
}
441+
395442
/**
396443
* Log the given user ID into the application.
397444
*

src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class RedisBroadcaster extends Broadcaster
2020
/**
2121
* The Redis connection to use for broadcasting.
2222
*
23-
* @var string
23+
* @var ?string
2424
*/
25-
protected $connection;
25+
protected $connection = null;
2626

2727
/**
2828
* The Redis key prefix.
2929
*
3030
* @var string
3131
*/
32-
protected $prefix;
32+
protected $prefix = '';
3333

3434
/**
3535
* Create a new broadcaster instance.

src/Illuminate/Cache/Console/ClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function cache()
116116
*/
117117
protected function tags()
118118
{
119-
return array_filter(explode(',', $this->option('tags')));
119+
return array_filter(explode(',', $this->option('tags') ?? ''));
120120
}
121121

122122
/**

src/Illuminate/Collections/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,10 @@ public function implode($value, $glue = null)
515515
$first = $this->first();
516516

517517
if (is_array($first) || (is_object($first) && ! $first instanceof Stringable)) {
518-
return implode($glue, $this->pluck($value)->all());
518+
return implode($glue ?? '', $this->pluck($value)->all());
519519
}
520520

521-
return implode($value, $this->items);
521+
return implode($value ?? '', $this->items);
522522
}
523523

524524
/**

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function handle(Schedule $schedule)
3737
$event->expression,
3838
$event->description,
3939
(new CronExpression($event->expression))
40-
->getNextRunDate(Carbon::now())
41-
->setTimezone($this->option('timezone', config('app.timezone'))),
40+
->getNextRunDate(Carbon::now()->setTimezone($event->timezone))
41+
->setTimezone($this->option('timezone', config('app.timezone')))
42+
->format('Y-m-d H:i:s P'),
4243
];
4344
}
4445

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Validation;
4+
5+
interface DataAwareRule
6+
{
7+
/**
8+
* Set the data under validation.
9+
*
10+
* @param array $data
11+
* @return $this
12+
*/
13+
public function setData($data);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Validation;
4+
5+
interface UncompromisedVerifier
6+
{
7+
/**
8+
* Verify that the given data has not been compromised in data leaks.
9+
*
10+
* @param array $data
11+
* @return bool
12+
*/
13+
public function verify($data);
14+
}

src/Illuminate/Cookie/CookieJar.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ public function queue(...$parameters)
153153
$this->queued[$cookie->getName()][$cookie->getPath()] = $cookie;
154154
}
155155

156+
/**
157+
* Queue a cookie to expire with the next response.
158+
*
159+
* @param string $name
160+
* @param string|null $path
161+
* @param string|null $domain
162+
* @return void
163+
*/
164+
public function expire($name, $path = null, $domain = null)
165+
{
166+
$this->queue($this->forget($name, $path, $domain));
167+
}
168+
156169
/**
157170
* Remove a cookie from the queue.
158171
*

src/Illuminate/Database/Eloquent/Relations/MorphTo.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,14 @@ protected function matchToMorphParents($type, Collection $results)
231231
*/
232232
public function associate($model)
233233
{
234+
if ($model instanceof Model) {
235+
$foreignKey = $this->ownerKey && $model->{$this->ownerKey}
236+
? $this->ownerKey
237+
: $model->getKeyName();
238+
}
239+
234240
$this->parent->setAttribute(
235-
$this->foreignKey, $model instanceof Model ? $model->{$this->ownerKey ?: $model->getKeyName()} : null
241+
$this->foreignKey, $model instanceof Model ? $model->{$foreignKey} : null
236242
);
237243

238244
$this->parent->setAttribute(

src/Illuminate/Database/Eloquent/SoftDeletes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true)
77
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyTrashed()
88
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withoutTrashed()
9-
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder restore()
109
*/
1110
trait SoftDeletes
1211
{

src/Illuminate/Database/Schema/ColumnDefinition.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @method $this change() Change the column
1212
* @method $this charset(string $charset) Specify a character set for the column (MySQL)
1313
* @method $this collation(string $collation) Specify a collation for the column (MySQL/PostgreSQL/SQL Server)
14-
* @method $this comment(string $comment) Add a comment to the column (MySQL)
14+
* @method $this comment(string $comment) Add a comment to the column (MySQL/PostgreSQL)
1515
* @method $this default(mixed $value) Specify a "default" value for the column
1616
* @method $this first() Place the column "first" in the table (MySQL)
1717
* @method $this generatedAs(string|Expression $expression = null) Create a SQL compliant identity column (PostgreSQL)
@@ -20,13 +20,14 @@
2020
* @method $this persisted() Mark the computed generated column as persistent (SQL Server)
2121
* @method $this primary() Add a primary index
2222
* @method $this spatialIndex() Add a spatial index
23-
* @method $this storedAs(string $expression) Create a stored generated column (MySQL/SQLite)
23+
* @method $this startingValue(int $startingValue) Set the starting value of an auto-incrementing field (MySQL/PostgreSQL)
24+
* @method $this storedAs(string $expression) Create a stored generated column (MySQL/PostgreSQL/SQLite)
2425
* @method $this type(string $type) Specify a type for the column
2526
* @method $this unique(string $indexName = null) Add a unique index
2627
* @method $this unsigned() Set the INTEGER column as UNSIGNED (MySQL)
2728
* @method $this useCurrent() Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
2829
* @method $this useCurrentOnUpdate() Set the TIMESTAMP column to use CURRENT_TIMESTAMP when updating (MySQL)
29-
* @method $this virtualAs(string $expression) Create a virtual generated column (MySQL/SQLite)
30+
* @method $this virtualAs(string $expression) Create a virtual generated column (MySQL/PostgreSQL/SQLite)
3031
*/
3132
class ColumnDefinition extends Fluent
3233
{

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
3333
*
3434
* @var string
3535
*/
36-
const VERSION = '8.38.0';
36+
const VERSION = '8.39.0';
3737

3838
/**
3939
* The base path for the Laravel installation.

src/Illuminate/Foundation/Console/ServeCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function handle()
5454
? filemtime($environmentFile)
5555
: now()->addDays(30)->getTimestamp();
5656

57-
$process = $this->startProcess();
57+
$process = $this->startProcess($hasEnvironment);
5858

5959
while ($process->isRunning()) {
6060
if ($hasEnvironment) {
@@ -70,7 +70,7 @@ public function handle()
7070

7171
$process->stop(5);
7272

73-
$process = $this->startProcess();
73+
$process = $this->startProcess($hasEnvironment);
7474
}
7575

7676
usleep(500 * 1000);
@@ -90,12 +90,13 @@ public function handle()
9090
/**
9191
* Start a new server process.
9292
*
93+
* @param bool $hasEnvironment
9394
* @return \Symfony\Component\Process\Process
9495
*/
95-
protected function startProcess()
96+
protected function startProcess($hasEnvironment)
9697
{
97-
$process = new Process($this->serverCommand(), null, collect($_ENV)->mapWithKeys(function ($value, $key) {
98-
if ($this->option('no-reload')) {
98+
$process = new Process($this->serverCommand(), null, collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
99+
if ($this->option('no-reload') || ! $hasEnvironment) {
99100
return [$key => $value];
100101
}
101102

src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ public function setUpRedis()
3636

3737
if (! extension_loaded('redis')) {
3838
$this->markTestSkipped('The redis extension is not installed. Please install the extension to enable '.__CLASS__);
39-
40-
return;
4139
}
4240

4341
if (static::$connectionFailedOnceWithDefaultsSkip) {
4442
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
45-
46-
return;
4743
}
4844

4945
foreach ($this->redisDriverProvider() as $driver) {

src/Illuminate/Http/Client/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @method \Illuminate\Http\Client\PendingRequest dump()
3636
* @method \Illuminate\Http\Client\PendingRequest dd()
3737
* @method \Illuminate\Http\Client\PendingRequest async()
38-
* @method \Illuminate\Http\Client\Pool pool(callable $callback)
38+
* @method array pool(callable $callback)
3939
* @method \Illuminate\Http\Client\Response delete(string $url, array $data = [])
4040
* @method \Illuminate\Http\Client\Response get(string $url, array $query = [])
4141
* @method \Illuminate\Http\Client\Response head(string $url, array $query = [])

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public function buildRecorderHandler()
819819
{
820820
return function ($handler) {
821821
return function ($request, $options) use ($handler) {
822-
$promise = $handler($this->runBeforeSendingCallbacks($request, $options), $options);
822+
$promise = $handler($request, $options);
823823

824824
return $promise->then(function ($response) use ($request, $options) {
825825
optional($this->factory)->recordRequestResponsePair(

src/Illuminate/Http/JsonResponse.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ class JsonResponse extends BaseJsonResponse
2222
* @param int $status
2323
* @param array $headers
2424
* @param int $options
25+
* @param bool $json
2526
* @return void
2627
*/
27-
public function __construct($data = null, $status = 200, $headers = [], $options = 0)
28+
public function __construct($data = null, $status = 200, $headers = [], $options = 0, $json = false)
2829
{
2930
$this->encodingOptions = $options;
3031

31-
parent::__construct($data, $status, $headers);
32+
parent::__construct($data, $status, $headers, $json);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public static function fromJsonString(?string $data = null, int $status = 200, array $headers = [])
39+
{
40+
return new static($data, $status, $headers, 0, true);
3241
}
3342

3443
/**

src/Illuminate/Http/Resources/Json/JsonResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class JsonResource implements ArrayAccess, JsonSerializable, Responsable, UrlRou
4242
/**
4343
* The "data" wrapper that should be applied.
4444
*
45-
* @var string
45+
* @var string|null
4646
*/
4747
public static $wrap = 'data';
4848

src/Illuminate/Mail/MailManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function createTransport(array $config)
168168
return call_user_func($this->customCreators[$transport], $config);
169169
}
170170

171-
if (trim($transport) === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
171+
if (trim($transport ?? '') === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
172172
throw new InvalidArgumentException("Unsupported mail transport [{$transport}].");
173173
}
174174

src/Illuminate/Routing/AbstractRouteCollection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ protected function addToSymfonyRoutesCollection(SymfonyRouteCollection $symfonyR
199199
{
200200
$name = $route->getName();
201201

202-
if (Str::endsWith($name, '.') &&
203-
! is_null($symfonyRoutes->get($name))) {
202+
if (
203+
! is_null($name)
204+
&& Str::endsWith($name, '.')
205+
&& ! is_null($symfonyRoutes->get($name))
206+
) {
204207
$name = null;
205208
}
206209

src/Illuminate/Support/Facades/Http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @method static \Illuminate\Http\Client\PendingRequest dump()
3434
* @method static \Illuminate\Http\Client\PendingRequest dd()
3535
* @method static \Illuminate\Http\Client\PendingRequest async()
36-
* @method static \Illuminate\Http\Client\Pool pool(callable $callback)
36+
* @method static array pool(callable $callback)
3737
* @method static \Illuminate\Http\Client\Response delete(string $url, array $data = [])
3838
* @method static \Illuminate\Http\Client\Response get(string $url, array $query = [])
3939
* @method static \Illuminate\Http\Client\Response head(string $url, array $query = [])

src/Illuminate/Support/Facades/Lang.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Illuminate\Support\Facades;
44

55
/**
6-
* @method static bool has(string $key)
6+
* @method static bool hasForLocale(string $key, string $locale = null)
7+
* @method static bool has(string $key, string $locale = null, bool $fallback = true)
78
* @method static mixed get(string $key, array $replace = [], string $locale = null, bool $fallback = true)
89
* @method static string choice(string $key, \Countable|int|array $number, array $replace = [], string $locale = null)
910
* @method static string getLocale()

src/Illuminate/Support/Facades/Route.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
* @method static \Illuminate\Routing\Route put(string $uri, array|string|callable|null $action = null)
2121
* @method static \Illuminate\Routing\Route redirect(string $uri, string $destination, int $status = 302)
2222
* @method static \Illuminate\Routing\Route substituteBindings(\Illuminate\Support\Facades\Route $route)
23-
* @method static \Illuminate\Routing\Route view(string $uri, string $view, array $data = [], int $status = 200, array $headers = [])
23+
* @method static \Illuminate\Routing\Route view(string $uri, string $view, array $data = [], int|array $status = 200, array $headers = [])
2424
* @method static \Illuminate\Routing\RouteRegistrar as(string $value)
2525
* @method static \Illuminate\Routing\RouteRegistrar domain(string $value)
2626
* @method static \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
2727
* @method static \Illuminate\Routing\RouteRegistrar name(string $value)
2828
* @method static \Illuminate\Routing\RouteRegistrar namespace(string|null $value)
29-
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
30-
* @method static \Illuminate\Routing\RouteRegistrar where(array $where)
29+
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
30+
* @method static \Illuminate\Routing\RouteRegistrar where(array $where)
3131
* @method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(\Closure|string|array $attributes, \Closure|string $routes)
3232
* @method static \Illuminate\Routing\ResourceRegistrar resourceVerbs(array $verbs = [])
3333
* @method static string|null currentRouteAction()

0 commit comments

Comments
 (0)