Skip to content

Commit a990b19

Browse files
authored
Merge branch 'laravel:8.x' into 8.x
2 parents f34ffda + b0a2d85 commit a990b19

File tree

14 files changed

+202
-11
lines changed

14 files changed

+202
-11
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public function flip()
397397
/**
398398
* Remove an item from the collection by key.
399399
*
400-
* @param string|array $keys
400+
* @param string|int|array $keys
401401
* @return $this
402402
*/
403403
public function forget($keys)
@@ -1628,7 +1628,7 @@ public function offsetSet($key, $value)
16281628
/**
16291629
* Unset the item at a given offset.
16301630
*
1631-
* @param string $key
1631+
* @param mixed $key
16321632
* @return void
16331633
*/
16341634
#[\ReturnTypeWillChange]

src/Illuminate/Console/Scheduling/Schedule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function call($callback, array $parameters = [])
120120
public function command($command, array $parameters = [])
121121
{
122122
if (class_exists($command)) {
123-
$command = Container::getInstance()->make($command)->getName();
123+
$command = Container::getInstance()->make($command);
124+
125+
return $this->exec(
126+
Application::formatCommandString($command->getName()), $parameters,
127+
)->description($command->getDescription());
124128
}
125129

126130
return $this->exec(

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

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

55
use Cron\CronExpression;
6+
use DateTimeZone;
67
use Illuminate\Console\Command;
78
use Illuminate\Support\Carbon;
89

@@ -39,7 +40,7 @@ public function handle(Schedule $schedule)
3940
$event->description,
4041
(new CronExpression($event->expression))
4142
->getNextRunDate(Carbon::now()->setTimezone($event->timezone))
42-
->setTimezone($this->option('timezone', config('app.timezone')))
43+
->setTimezone(new DateTimeZone($this->option('timezone') ?? config('app.timezone')))
4344
->format('Y-m-d H:i:s P'),
4445
];
4546
}

src/Illuminate/Database/Connection.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ class Connection implements ConnectionInterface
177177
*/
178178
protected $doctrineConnection;
179179

180+
/**
181+
* Type mappings that should be registered with new Doctrine connections.
182+
*
183+
* @var array
184+
*/
185+
protected $doctrineTypeMappings = [];
186+
180187
/**
181188
* The connection resolvers.
182189
*
@@ -1007,6 +1014,12 @@ public function getDoctrineConnection()
10071014
'driver' => method_exists($driver, 'getName') ? $driver->getName() : null,
10081015
'serverVersion' => $this->getConfig('server_version'),
10091016
]), $driver);
1017+
1018+
foreach ($this->doctrineTypeMappings as $name => $type) {
1019+
$this->doctrineConnection
1020+
->getDatabasePlatform()
1021+
->registerDoctrineTypeMapping($type, $name);
1022+
}
10101023
}
10111024

10121025
return $this->doctrineConnection;
@@ -1035,9 +1048,7 @@ public function registerDoctrineType(string $class, string $name, string $type):
10351048
Type::addType($name, $class);
10361049
}
10371050

1038-
$this->getDoctrineSchemaManager()
1039-
->getDatabasePlatform()
1040-
->registerDoctrineTypeMapping($type, $name);
1051+
$this->doctrineTypeMappings[$name] = $type;
10411052
}
10421053

10431054
/**

src/Illuminate/Database/DatabaseManager.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Illuminate\Database;
44

5+
use Doctrine\DBAL\Types\Type;
56
use Illuminate\Database\Connectors\ConnectionFactory;
67
use Illuminate\Support\Arr;
78
use Illuminate\Support\ConfigurationUrlParser;
89
use Illuminate\Support\Str;
910
use InvalidArgumentException;
1011
use PDO;
12+
use RuntimeException;
1113

1214
/**
1315
* @mixin \Illuminate\Database\Connection
@@ -49,6 +51,13 @@ class DatabaseManager implements ConnectionResolverInterface
4951
*/
5052
protected $reconnector;
5153

54+
/**
55+
* The custom Doctrine column types.
56+
*
57+
* @var array
58+
*/
59+
protected $doctrineTypes = [];
60+
5261
/**
5362
* Create a new database manager instance.
5463
*
@@ -207,16 +216,46 @@ protected function setPdoForType(Connection $connection, $type = null)
207216
}
208217

209218
/**
210-
* Register custom Doctrine types from the configuration with the connection.
219+
* Register custom Doctrine types with the connection.
211220
*
212221
* @param \Illuminate\Database\Connection $connection
213222
* @return void
214223
*/
215224
protected function registerConfiguredDoctrineTypes(Connection $connection): void
216225
{
217226
foreach ($this->app['config']->get('database.dbal.types', []) as $name => $class) {
218-
$connection->registerDoctrineType($class, $name, $name);
227+
$this->registerDoctrineType($class, $name, $name);
228+
}
229+
230+
foreach ($this->doctrineTypes as $name => [$type, $class]) {
231+
$connection->registerDoctrineType($class, $name, $type);
232+
}
233+
}
234+
235+
/**
236+
* Register a custom Doctrine type.
237+
*
238+
* @param string $class
239+
* @param string $name
240+
* @param string $type
241+
* @return void
242+
*
243+
* @throws \Doctrine\DBAL\DBALException
244+
* @throws \RuntimeException
245+
*/
246+
public function registerDoctrineType(string $class, string $name, string $type): void
247+
{
248+
if (! class_exists('Doctrine\DBAL\Connection')) {
249+
throw new RuntimeException(
250+
'Registering a custom Doctrine type requires Doctrine DBAL (doctrine/dbal).'
251+
);
219252
}
253+
254+
if (! Type::hasType($name)) {
255+
Type::addType($name, $class);
256+
}
257+
258+
$this->doctrineTypes[$name] = [$type, $class];
220259
}
221260

222261
/**

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,13 @@ protected function mergeAttributesFromClassCasts()
16371637
protected function mergeAttributesFromAttributeCasts()
16381638
{
16391639
foreach ($this->attributeCastCache as $key => $value) {
1640-
$callback = $this->{Str::camel($key)}()->set ?: function ($value) use ($key) {
1640+
$attribute = $this->{Str::camel($key)}();
1641+
1642+
if ($attribute->get && ! $attribute->set) {
1643+
continue;
1644+
}
1645+
1646+
$callback = $attribute->set ?: function ($value) use ($key) {
16411647
$this->attributes[$key] = $value;
16421648
};
16431649

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,22 @@ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'p
431431
return $this->query->simplePaginate($perPage, $columns, $pageName, $page);
432432
}
433433

434+
/**
435+
* Paginate the given query into a cursor paginator.
436+
*
437+
* @param int|null $perPage
438+
* @param array $columns
439+
* @param string $cursorName
440+
* @param string|null $cursor
441+
* @return \Illuminate\Contracts\Pagination\CursorPaginator
442+
*/
443+
public function cursorPaginate($perPage = null, $columns = ['*'], $cursorName = 'cursor', $cursor = null)
444+
{
445+
$this->query->addSelect($this->shouldSelect($columns));
446+
447+
return $this->query->cursorPaginate($perPage, $columns, $cursorName, $cursor);
448+
}
449+
434450
/**
435451
* Set the select clause for the relation query.
436452
*

src/Illuminate/Log/LogManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use Monolog\Formatter\LineFormatter;
99
use Monolog\Handler\ErrorLogHandler;
10+
use Monolog\Handler\FingersCrossedHandler;
1011
use Monolog\Handler\FormattableHandlerInterface;
1112
use Monolog\Handler\HandlerInterface;
1213
use Monolog\Handler\RotatingFileHandler;
@@ -416,6 +417,10 @@ protected function prepareHandlers(array $handlers)
416417
*/
417418
protected function prepareHandler(HandlerInterface $handler, array $config = [])
418419
{
420+
if (isset($config['action_level'])) {
421+
$handler = new FingersCrossedHandler($handler, $this->actionLevel($config));
422+
}
423+
419424
if (Monolog::API !== 1 && (Monolog::API !== 2 || ! $handler instanceof FormattableHandlerInterface)) {
420425
return $handler;
421426
}

src/Illuminate/Log/ParsesLogConfiguration.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ protected function level(array $config)
4949
throw new InvalidArgumentException('Invalid log level.');
5050
}
5151

52+
/**
53+
* Parse the action level from the given configuration.
54+
*
55+
* @param array $config
56+
* @return int
57+
*/
58+
protected function actionLevel(array $config)
59+
{
60+
$level = $config['action_level'] ?? 'debug';
61+
62+
if (isset($this->levels[$level])) {
63+
return $this->levels[$level];
64+
}
65+
66+
throw new InvalidArgumentException('Invalid log action level.');
67+
}
68+
5269
/**
5370
* Extract the log channel from the given configuration.
5471
*

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public function validateDigitsBetween($attribute, $value, $parameters)
555555

556556
$length = strlen((string) $value);
557557

558-
return ! preg_match('/[^0-9]/', $value)
558+
return ! preg_match('/[^0-9.]/', $value)
559559
&& $length >= $parameters[0] && $length <= $parameters[1];
560560
}
561561

0 commit comments

Comments
 (0)