Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 11/persist-databa…
Browse files Browse the repository at this point in the history
…se-connections
  • Loading branch information
crynobone committed Jan 18, 2024
2 parents 2a14d0a + 7fcb2f7 commit 3c3ce3e
Show file tree
Hide file tree
Showing 47 changed files with 959 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ permissions:
pull-requests: write

jobs:
uneditable:
pull-requests:
uses: laravel/.github/.github/workflows/pull-requests.yml@main
4 changes: 2 additions & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
|--------------------------------------------------------------------------
|
| This key is utilized by Laravel's encryption services and should be set
| to a random, 32 character string or all of the encrypted strings are
| not secure. You should do this prior to deploying the application.
| to a random, 32 character string to ensure that all encrypted values
| are secure. You should do this prior to deploying the application.
|
*/

Expand Down
4 changes: 2 additions & 2 deletions config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
| stores there might be other applications using the same cache. For
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
| stores, there might be other applications using the same cache. For
| that reason, you may prefix every cache key to avoid collisions.
|
*/
Expand Down
2 changes: 1 addition & 1 deletion config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
| for each backend included with Laravel. You are free to add more.
|
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,25 @@ public function after(callable $callback)
/**
* Determine if all of the given abilities should be granted for the current user.
*
* @param iterable|string $abilities
* @param iterable|string $ability
* @param array|mixed $arguments
* @return bool
*/
public function allows($abilities, $arguments = [])
public function allows($ability, $arguments = [])
{
return $this->check($abilities, $arguments);
return $this->check($ability, $arguments);
}

/**
* Determine if any of the given abilities should be denied for the current user.
*
* @param iterable|string $abilities
* @param iterable|string $ability
* @param array|mixed $arguments
* @return bool
*/
public function denies($abilities, $arguments = [])
public function denies($ability, $arguments = [])
{
return ! $this->allows($abilities, $arguments);
return ! $this->allows($ability, $arguments);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected function possibleModels()
{
$modelPath = is_dir(app_path('Models')) ? app_path('Models') : app_path();

return collect((new Finder)->files()->depth(0)->in($modelPath))
return collect(Finder::create()->files()->depth(0)->in($modelPath))
->map(fn ($file) => $file->getBasename('.php'))
->sort()
->values()
Expand All @@ -269,7 +269,7 @@ protected function possibleEvents()
return [];
}

return collect((new Finder)->files()->depth(0)->in($eventPath))
return collect(Finder::create()->files()->depth(0)->in($eventPath))
->map(fn ($file) => $file->getBasename('.php'))
->sort()
->values()
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Contracts/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ public function after(callable $callback);
/**
* Determine if all of the given abilities should be granted for the current user.
*
* @param iterable|string $abilities
* @param iterable|string $ability
* @param array|mixed $arguments
* @return bool
*/
public function allows($abilities, $arguments = []);
public function allows($ability, $arguments = []);

/**
* Determine if any of the given abilities should be denied for the current user.
*
* @param iterable|string $abilities
* @param iterable|string $ability
* @param array|mixed $arguments
* @return bool
*/
public function denies($abilities, $arguments = []);
public function denies($ability, $arguments = []);

/**
* Determine if all of the given abilities should be granted for the current user.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function get($key, array $replace = [], $locale = null);
* Get a translation according to an integer value.
*
* @param string $key
* @param \Countable|int|array $number
* @param \Countable|int|float|array $number
* @param array $replace
* @param string|null $locale
* @return string
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ protected function createMissingSqliteDatabase($path)
return false;
}

$this->components->warn('The SQLite database does not exist: '.$path);
$this->components->warn('The SQLite database configured for this application does not exist: '.$path);

if (! confirm('Would you like to create it?', default: false)) {
if (! confirm('Would you like to create it?', default: true)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Console/PruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function models()
throw new InvalidArgumentException('The --models and --except options cannot be combined.');
}

return collect((new Finder)->in($this->getPath())->files()->name('*.php'))
return collect(Finder::create()->in($this->getPath())->files()->name('*.php'))
->map(function ($model) {
$namespace = $this->laravel->getNamespace();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,7 @@ public function originalIsEquivalent($key)
}

return is_numeric($attribute) && is_numeric($original)
&& BigDecimal::of($attribute)->isEqualTo($original);
&& strcmp((string) $attribute, (string) $original) === 0;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
use Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithDictionary;
use Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Support\Str;
use InvalidArgumentException;
Expand Down Expand Up @@ -1347,6 +1348,42 @@ public function getRelationExistenceQueryForSelfJoin(Builder $query, Builder $pa
return parent::getRelationExistenceQuery($query, $parentQuery, $columns);
}

/**
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function take($value)
{
return $this->limit($value);
}

/**
* Set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function limit($value)
{
if ($this->parent->exists) {
$this->query->limit($value);
} else {
$column = $this->getExistenceCompareKey();

$grammar = $this->query->getQuery()->getGrammar();

if ($grammar instanceof MySqlGrammar && $grammar->useLegacyGroupLimit($this->query->getQuery())) {
$column = 'pivot_'.last(explode('.', $column));
}

$this->query->groupLimit($value, $column);
}

return $this;
}

/**
* Get the key for comparing against the parent key in "has" query.
*
Expand Down
37 changes: 37 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithDictionary;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\UniqueConstraintViolationException;

class HasManyThrough extends Relation
Expand Down Expand Up @@ -762,6 +763,42 @@ public function getRelationExistenceQueryForThroughSelfRelation(Builder $query,
);
}

/**
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function take($value)
{
return $this->limit($value);
}

/**
* Set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function limit($value)
{
if ($this->farParent->exists) {
$this->query->limit($value);
} else {
$column = $this->getQualifiedFirstKeyName();

$grammar = $this->query->getQuery()->getGrammar();

if ($grammar instanceof MySqlGrammar && $grammar->useLegacyGroupLimit($this->query->getQuery())) {
$column = 'laravel_through_key';
}

$this->query->groupLimit($value, $column);
}

return $this;
}

/**
* Get the qualified foreign key on the related model.
*
Expand Down
28 changes: 28 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,34 @@ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder
);
}

/**
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function take($value)
{
return $this->limit($value);
}

/**
* Set the "limit" value of the query.
*
* @param int $value
* @return $this
*/
public function limit($value)
{
if ($this->parent->exists) {
$this->query->limit($value);
} else {
$this->query->groupLimit($value, $this->getExistenceCompareKey());
}

return $this;
}

/**
* Get the key for comparing against the parent key in "has" query.
*
Expand Down
55 changes: 54 additions & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ class Builder implements BuilderContract
*/
public $limit;

/**
* The maximum number of records to return per group.
*
* @var array
*/
public $groupLimit;

/**
* The number of records to skip.
*
Expand Down Expand Up @@ -2444,6 +2451,22 @@ public function limit($value)
return $this;
}

/**
* Add a "group limit" clause to the query.
*
* @param int $value
* @param string $column
* @return $this
*/
public function groupLimit($value, $column)
{
if ($value >= 0) {
$this->groupLimit = compact('value', 'column');
}

return $this;
}

/**
* Set the limit and offset for a given page.
*
Expand Down Expand Up @@ -2737,9 +2760,13 @@ public function soleValue($column)
*/
public function get($columns = ['*'])
{
return collect($this->onceWithColumns(Arr::wrap($columns), function () {
$items = collect($this->onceWithColumns(Arr::wrap($columns), function () {
return $this->processor->processSelect($this, $this->runSelect());
}));

return isset($this->groupLimit)
? $this->withoutGroupLimitKeys($items)
: $items;
}

/**
Expand All @@ -2754,6 +2781,32 @@ protected function runSelect()
);
}

/**
* Remove the group limit keys from the results in the collection.
*
* @param \Illuminate\Support\Collection $items
* @return \Illuminate\Support\Collection
*/
protected function withoutGroupLimitKeys($items)
{
$keysToRemove = ['laravel_row'];

if (is_string($this->groupLimit['column'])) {
$column = last(explode('.', $this->groupLimit['column']));

$keysToRemove[] = '@laravel_group := '.$this->grammar->wrap($column);
$keysToRemove[] = '@laravel_group := '.$this->grammar->wrap('pivot_'.$column);
}

$items->each(function ($item) use ($keysToRemove) {
foreach ($keysToRemove as $key) {
unset($item->$key);
}
});

return $items;
}

/**
* Paginate the given query into a simple paginator.
*
Expand Down
Loading

0 comments on commit 3c3ce3e

Please sign in to comment.