Skip to content

Commit bdac8cf

Browse files
committed
Merge branch '11.x' of github.com:laravel/framework into 11.x
2 parents 60e183e + 85a02ca commit bdac8cf

27 files changed

+411
-134
lines changed

src/Illuminate/Cache/DatabaseStore.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Database\ConnectionInterface;
99
use Illuminate\Database\PostgresConnection;
1010
use Illuminate\Database\QueryException;
11+
use Illuminate\Database\SQLiteConnection;
1112
use Illuminate\Database\SqlServerConnection;
1213
use Illuminate\Support\Arr;
1314
use Illuminate\Support\Collection;
@@ -487,7 +488,7 @@ protected function serialize($value)
487488
{
488489
$result = serialize($value);
489490

490-
if ($this->connection instanceof PostgresConnection && str_contains($result, "\0")) {
491+
if (($this->connection instanceof PostgresConnection || $this->connection instanceof SQLiteConnection) && str_contains($result, "\0")) {
491492
$result = base64_encode($result);
492493
}
493494

@@ -502,7 +503,7 @@ protected function serialize($value)
502503
*/
503504
protected function unserialize($value)
504505
{
505-
if ($this->connection instanceof PostgresConnection && ! Str::contains($value, [':', ';'])) {
506+
if (($this->connection instanceof PostgresConnection || $this->connection instanceof SQLiteConnection) && ! Str::contains($value, [':', ';'])) {
506507
$value = base64_decode($value);
507508
}
508509

src/Illuminate/Console/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\StringInput;
1818
use Symfony\Component\Console\Output\BufferedOutput;
1919

20+
use function Illuminate\Support\artisan_binary;
2021
use function Illuminate\Support\php_binary;
2122

2223
class Application extends SymfonyApplication implements ApplicationContract
@@ -95,7 +96,7 @@ public static function phpBinary()
9596
*/
9697
public static function artisanBinary()
9798
{
98-
return ProcessUtils::escapeArgument(defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan');
99+
return ProcessUtils::escapeArgument(artisan_binary());
99100
}
100101

101102
/**

src/Illuminate/Contracts/Pipeline/Pipeline.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
interface Pipeline
88
{
99
/**
10-
* Set the traveler object being sent on the pipeline.
10+
* Set the object being sent through the pipeline.
1111
*
12-
* @param mixed $traveler
12+
* @param mixed $passable
1313
* @return $this
1414
*/
15-
public function send($traveler);
15+
public function send($passable);
1616

1717
/**
18-
* Set the stops of the pipeline.
18+
* Set the array of pipes.
1919
*
20-
* @param dynamic|array $stops
20+
* @param array|mixed $pipes
2121
* @return $this
2222
*/
23-
public function through($stops);
23+
public function through($pipes);
2424

2525
/**
26-
* Set the method to call on the stops.
26+
* Set the method to call on the pipes.
2727
*
2828
* @param string $method
2929
* @return $this

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ trait HasRelationships
5858
/**
5959
* Get the dynamic relation resolver if defined or inherited, or return null.
6060
*
61-
* @param string $class
61+
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
62+
*
63+
* @param class-string<TRelatedModel> $class
6264
* @param string $key
63-
* @return mixed
65+
* @return Closure|null
6466
*/
6567
public function relationResolver($class, $key)
6668
{
@@ -851,8 +853,10 @@ public function getMorphClass()
851853
/**
852854
* Create a new model instance for a related model.
853855
*
854-
* @param string $class
855-
* @return mixed
856+
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
857+
*
858+
* @param class-string<TRelatedModel> $class
859+
* @return TRelatedModel
856860
*/
857861
protected function newRelatedInstance($class)
858862
{
@@ -866,8 +870,10 @@ protected function newRelatedInstance($class)
866870
/**
867871
* Create a new model instance for a related "through" model.
868872
*
869-
* @param string $class
870-
* @return mixed
873+
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
874+
*
875+
* @param class-string<TRelatedModel> $class
876+
* @return TRelatedModel
871877
*/
872878
protected function newRelatedThroughInstance($class)
873879
{

src/Illuminate/Database/Events/MigrationsEvent.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ abstract class MigrationsEvent implements MigrationEventContract
1313
*/
1414
public $method;
1515

16+
/**
17+
* The options provided when the migration method was invoked.
18+
*
19+
* @var array<string, mixed>
20+
*/
21+
public $options;
22+
1623
/**
1724
* Create a new event instance.
1825
*
1926
* @param string $method
27+
* @param array<string, mixed> $options
2028
* @return void
2129
*/
22-
public function __construct($method)
30+
public function __construct($method, array $options = [])
2331
{
2432
$this->method = $method;
33+
$this->options = $options;
2534
}
2635
}

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function runPending(array $migrations, array $options = [])
169169

170170
$step = $options['step'] ?? false;
171171

172-
$this->fireMigrationEvent(new MigrationsStarted('up'));
172+
$this->fireMigrationEvent(new MigrationsStarted('up', $options));
173173

174174
$this->write(Info::class, 'Running migrations.');
175175

@@ -184,7 +184,7 @@ public function runPending(array $migrations, array $options = [])
184184
}
185185
}
186186

187-
$this->fireMigrationEvent(new MigrationsEnded('up'));
187+
$this->fireMigrationEvent(new MigrationsEnded('up', $options));
188188

189189
$this->output?->writeln('');
190190
}
@@ -278,7 +278,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
278278

279279
$this->requireFiles($files = $this->getMigrationFiles($paths));
280280

281-
$this->fireMigrationEvent(new MigrationsStarted('down'));
281+
$this->fireMigrationEvent(new MigrationsStarted('down', $options));
282282

283283
$this->write(Info::class, 'Rolling back migrations.');
284284

@@ -302,7 +302,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
302302
);
303303
}
304304

305-
$this->fireMigrationEvent(new MigrationsEnded('down'));
305+
$this->fireMigrationEvent(new MigrationsEnded('down', $options));
306306

307307
return $rolledBack;
308308
}

src/Illuminate/Database/Query/Builder.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,17 @@ public function count($columns = '*')
35613561
return (int) $this->aggregate(__FUNCTION__, Arr::wrap($columns));
35623562
}
35633563

3564+
/**
3565+
* Retrieve the "count" of the distinct results of a given column for each group.
3566+
*
3567+
* @param \Illuminate\Contracts\Database\Query\Expression|string $columns
3568+
* @return \Illuminate\Support\Collection
3569+
*/
3570+
public function countByGroup($columns = '*')
3571+
{
3572+
return $this->aggregateByGroup('count', Arr::wrap($columns));
3573+
}
3574+
35643575
/**
35653576
* Retrieve the minimum value of a given column.
35663577
*
@@ -3572,6 +3583,17 @@ public function min($column)
35723583
return $this->aggregate(__FUNCTION__, [$column]);
35733584
}
35743585

3586+
/**
3587+
* Retrieve the minimum value of a given column by group.
3588+
*
3589+
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
3590+
* @return \Illuminate\Support\Collection
3591+
*/
3592+
public function minByGroup($column)
3593+
{
3594+
return $this->aggregateByGroup('min', [$column]);
3595+
}
3596+
35753597
/**
35763598
* Retrieve the maximum value of a given column.
35773599
*
@@ -3583,6 +3605,17 @@ public function max($column)
35833605
return $this->aggregate(__FUNCTION__, [$column]);
35843606
}
35853607

3608+
/**
3609+
* Retrieve the maximum value of a given column by group.
3610+
*
3611+
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
3612+
* @return \Illuminate\Support\Collection
3613+
*/
3614+
public function maxByGroup($column)
3615+
{
3616+
return $this->aggregateByGroup('max', [$column]);
3617+
}
3618+
35863619
/**
35873620
* Retrieve the sum of the values of a given column.
35883621
*
@@ -3596,6 +3629,17 @@ public function sum($column)
35963629
return $result ?: 0;
35973630
}
35983631

3632+
/**
3633+
* Retrieve the sum of the values of a given column by group.
3634+
*
3635+
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
3636+
* @return \Illuminate\Support\Collection
3637+
*/
3638+
public function sumByGroup($column)
3639+
{
3640+
return $this->aggregateByGroup('sum', [$column]);
3641+
}
3642+
35993643
/**
36003644
* Retrieve the average of the values of a given column.
36013645
*
@@ -3607,6 +3651,17 @@ public function avg($column)
36073651
return $this->aggregate(__FUNCTION__, [$column]);
36083652
}
36093653

3654+
/**
3655+
* Retrieve the average of the values of a given column by group.
3656+
*
3657+
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
3658+
* @return \Illuminate\Support\Collection
3659+
*/
3660+
public function avgByGroup($column)
3661+
{
3662+
return $this->aggregateByGroup('avg', [$column]);
3663+
}
3664+
36103665
/**
36113666
* Alias for the "avg" method.
36123667
*
@@ -3637,6 +3692,21 @@ public function aggregate($function, $columns = ['*'])
36373692
}
36383693
}
36393694

3695+
/**
3696+
* Execute an aggregate function for each group.
3697+
*
3698+
* @param string $function
3699+
* @param array $columns
3700+
* @return \Illuminate\Support\Collection
3701+
*/
3702+
public function aggregateByGroup(string $function, array $columns = ['*'])
3703+
{
3704+
return $this->cloneWithout($this->unions || $this->havings ? [] : ['columns'])
3705+
->cloneWithoutBindings($this->unions || $this->havings ? [] : ['select'])
3706+
->setAggregate($function, $columns)
3707+
->get($columns);
3708+
}
3709+
36403710
/**
36413711
* Execute a numeric aggregate function on the database.
36423712
*

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ protected function compileAggregate(Builder $query, $aggregate)
139139
$column = 'distinct '.$column;
140140
}
141141

142-
return 'select '.$aggregate['function'].'('.$column.') as aggregate';
142+
$sql = 'select ';
143+
144+
$sql .= $aggregate['function'].'('.$column.') as aggregate';
145+
146+
if ($query->groups) {
147+
$sql .= ', '.$this->columnize($query->groups);
148+
}
149+
150+
return $sql;
143151
}
144152

145153
/**
@@ -1131,10 +1139,12 @@ protected function wrapUnion($sql)
11311139
protected function compileUnionAggregate(Builder $query)
11321140
{
11331141
$sql = $this->compileAggregate($query, $query->aggregate);
1142+
$groups = $query->groups ? ' '.$this->compileGroups($query, $query->groups) : '';
11341143

11351144
$query->aggregate = null;
1145+
$query->groups = null;
11361146

1137-
return $sql.' from ('.$this->compileSelect($query).') as '.$this->wrapTable('temp_table');
1147+
return $sql.' from ('.$this->compileSelect($query).') as '.$this->wrapTable('temp_table').$groups;
11381148
}
11391149

11401150
/**
@@ -1168,11 +1178,8 @@ public function compileInsert(Builder $query, array $values)
11681178
return "insert into {$table} default values";
11691179
}
11701180

1171-
if (! array_is_list($values)) {
1172-
$values = (new Collection(array_keys($values)))
1173-
->some(fn ($key) => ! is_numeric($key))
1174-
? [$values]
1175-
: array_values($values);
1181+
if (! is_array(reset($values))) {
1182+
$values = [$values];
11761183
}
11771184

11781185
$columns = $this->columnize(array_keys(reset($values)));

src/Illuminate/Foundation/Bus/Dispatchable.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait Dispatchable
1616
*/
1717
public static function dispatch(...$arguments)
1818
{
19-
return new PendingDispatch(new static(...$arguments));
19+
return static::newPendingDispatch(new static(...$arguments));
2020
}
2121

2222
/**
@@ -32,12 +32,12 @@ public static function dispatchIf($boolean, ...$arguments)
3232
$dispatchable = new static(...$arguments);
3333

3434
return value($boolean, $dispatchable)
35-
? new PendingDispatch($dispatchable)
35+
? static::newPendingDispatch($dispatchable)
3636
: new Fluent;
3737
}
3838

3939
return value($boolean)
40-
? new PendingDispatch(new static(...$arguments))
40+
? static::newPendingDispatch(new static(...$arguments))
4141
: new Fluent;
4242
}
4343

@@ -54,12 +54,12 @@ public static function dispatchUnless($boolean, ...$arguments)
5454
$dispatchable = new static(...$arguments);
5555

5656
return ! value($boolean, $dispatchable)
57-
? new PendingDispatch($dispatchable)
57+
? static::newPendingDispatch($dispatchable)
5858
: new Fluent;
5959
}
6060

6161
return ! value($boolean)
62-
? new PendingDispatch(new static(...$arguments))
62+
? static::newPendingDispatch(new static(...$arguments))
6363
: new Fluent;
6464
}
6565

@@ -97,4 +97,15 @@ public static function withChain($chain)
9797
{
9898
return new PendingChain(static::class, $chain);
9999
}
100+
101+
/**
102+
* Create a new pending job dispatch instance.
103+
*
104+
* @param mixed $job
105+
* @return \Illuminate\Foundation\Bus\PendingDispatch
106+
*/
107+
protected static function newPendingDispatch($job)
108+
{
109+
return new PendingDispatch($job);
110+
}
100111
}

src/Illuminate/Foundation/Bus/PendingDispatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function shouldDispatch()
179179
/**
180180
* Get the underlying job instance.
181181
*
182-
* @var mixed
182+
* @return mixed
183183
*/
184184
public function getJob()
185185
{

0 commit comments

Comments
 (0)