Skip to content

Commit

Permalink
Merge branch '11.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 2, 2024
2 parents 87932fb + 46dc7a4 commit f53c7bc
Show file tree
Hide file tree
Showing 39 changed files with 562 additions and 63 deletions.
33 changes: 27 additions & 6 deletions src/Illuminate/Cache/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Illuminate\Cache;

use BackedEnum;
use Closure;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Support\InteractsWithTime;
use UnitEnum;

class RateLimiter
{
Expand Down Expand Up @@ -38,26 +40,30 @@ public function __construct(Cache $cache)
/**
* Register a named limiter configuration.
*
* @param string $name
* @param \BackedEnum|\UnitEnum|string $name
* @param \Closure $callback
* @return $this
*/
public function for(string $name, Closure $callback)
public function for($name, Closure $callback)
{
$this->limiters[$name] = $callback;
$resolvedName = $this->resolveLimiterName($name);

$this->limiters[$resolvedName] = $callback;

return $this;
}

/**
* Get the given named rate limiter.
*
* @param string $name
* @param \BackedEnum|\UnitEnum|string $name
* @return \Closure|null
*/
public function limiter(string $name)
public function limiter($name)
{
return $this->limiters[$name] ?? null;
$resolvedName = $this->resolveLimiterName($name);

return $this->limiters[$resolvedName] ?? null;
}

/**
Expand Down Expand Up @@ -248,4 +254,19 @@ public function cleanRateLimiterKey($key)
{
return preg_replace('/&([a-z])[a-z]+;/i', '$1', htmlentities($key));
}

/**
* Resolve the rate limiter name.
*
* @param \BackedEnum|\UnitEnum|string $name
* @return string
*/
private function resolveLimiterName($name): string
{
return match (true) {
$name instanceof BackedEnum => $name->value,
$name instanceof UnitEnum => $name->name,
default => (string) $name,
};
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public function hasAny($key)
/**
* Concatenate values of a given key as a string.
*
* @param callable|string|null $value
* @param (callable(TValue, TKey): mixed)|string|null $value
* @param string|null $glue
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public function hasAny($key);
/**
* Concatenate values of a given key as a string.
*
* @param callable|string $value
* @param (callable(TValue, TKey): mixed)|string $value
* @param string|null $glue
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function hasAny($key)
/**
* Concatenate values of a given key as a string.
*
* @param callable|string $value
* @param (callable(TValue, TKey): mixed)|string $value
* @param string|null $glue
* @return string
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,8 +1634,10 @@ public function setTablePrefix($prefix)
/**
* Set the table prefix and return the grammar.
*
* @param \Illuminate\Database\Grammar $grammar
* @return \Illuminate\Database\Grammar
* @template TGrammar of \Illuminate\Database\Grammar
*
* @param TGrammar $grammar
* @return TGrammar
*/
public function withTablePrefix(Grammar $grammar)
{
Expand Down Expand Up @@ -1670,7 +1672,7 @@ public static function resolverFor($driver, Closure $callback)
* Get the connection resolver for the given driver.
*
* @param string $driver
* @return mixed
* @return \Closure|null
*/
public static function getResolver($driver)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public function isGuarded($key)
*/
protected function isGuardableColumn($key)
{
if ($this->hasSetMutator($key) || $this->hasAttributeSetMutator($key)) {
return true;
}

if (! isset(static::$guardableColumns[get_class($this)])) {
$columns = $this->getConnection()
->getSchemaBuilder()
Expand All @@ -222,6 +226,7 @@ protected function isGuardableColumn($key)
if (empty($columns)) {
return true;
}

static::$guardableColumns[get_class($this)] = $columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ protected function withoutRecursion($callback, $default = null)

$onceable = Onceable::tryFromTrace($trace, $callback);

if (is_null($onceable)) {
return call_user_func($callback);
}

$stack = static::getRecursiveCallStack($this);

if (array_key_exists($onceable->hash, $stack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public function whereBelongsTo($related, $relationshipName = null, $boolean = 'a
}

/**
* Add an "BelongsTo" relationship with an "or where" clause to the query.
* Add a "BelongsTo" relationship with an "or where" clause to the query.
*
* @param \Illuminate\Database\Eloquent\Model $related
* @param string|null $relationshipName
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function getRelationCountHash($incrementJoinCount = true)
*
* @param array<int, TDeclaringModel> $models
* @param string|null $key
* @return array<int, int|string>
* @return array<int, int|string|null>
*/
protected function getKeys(array $models, $key = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Builder implements BuilderContract
/**
* The maximum number of records to return.
*
* @var int
* @var int|null
*/
public $limit;

Expand Down Expand Up @@ -177,14 +177,14 @@ class Builder implements BuilderContract
/**
* The maximum number of union records to return.
*
* @var int
* @var int|null
*/
public $unionLimit;

/**
* The number of union records to skip.
*
* @var int
* @var int|null
*/
public $unionOffset;

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ protected function typeComputed(Fluent $column)
*
* @param \Illuminate\Support\Fluent $column
* @return string
*
* @throws \RuntimeException
*/
protected function typeVector(Fluent $column)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,7 @@ public function withMiddleware(?callable $callback = null)
public function withCommands(array $commands = [])
{
if (empty($commands)) {
if (is_file($this->app->basePath('routes/console.php'))) {
$commands = [$this->app->basePath('routes/console.php')];
}

if (is_dir($this->app->path('Console/Commands'))) {
$commands = [...$commands, $this->app->path('Console/Commands')];
}
$commands = [$this->app->path('Console/Commands')];
}

$this->app->afterResolving(ConsoleKernel::class, function ($kernel) use ($commands) {
Expand Down
81 changes: 81 additions & 0 deletions src/Illuminate/Foundation/Console/JobMiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

#[AsCommand(name: 'make:job-middleware')]
class JobMiddlewareMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
* @var string
*/
protected $name = 'make:job-middleware';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new job middleware class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Middleware';

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/job.middleware.stub');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__.$stub;
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Jobs\Middleware';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the job middleware already exists'],
];
}
}
37 changes: 37 additions & 0 deletions src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,43 @@ protected function getDefaultNamespace($rootNamespace)
return is_dir(app_path('Models')) ? $rootNamespace.'\\Models' : $rootNamespace;
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function buildClass($name)
{
$replace = [];

if ($this->option('factory')) {
$replace['{{ factoryDocBlock }}'] = $this->buildFactoryReplacements();
} else {
$replace["\n {{ factoryDocBlock }}"] = '';
}

return str_replace(
array_keys($replace), array_values($replace), parent::buildClass($name)
);
}

/**
* Build the replacements for a factory DocBlock.
*
* @return string
*/
protected function buildFactoryReplacements()
{
$factoryNamespace = '\\Database\\Factories\\'.Str::studly($this->argument('name')).'Factory';

return <<<EOT
/** @use HasFactory<$factoryNamespace> */
EOT;
}

/**
* Get the console command options.
*
Expand Down
18 changes: 18 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/job.middleware.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace {{ namespace }};

use Closure;

class {{ class }}
{
/**
* Process the queued job.
*
* @param \Closure(object): void $next
*/
public function handle(object $job, Closure $next): void
{
$next($job);
}
}
1 change: 1 addition & 0 deletions src/Illuminate/Foundation/Console/stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ use Illuminate\Database\Eloquent\Model;

class {{ class }} extends Model
{
{{ factoryDocBlock }}
use HasFactory;
}
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Events/DiscoverEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ protected static function classFromFile(SplFileInfo $file, $basePath)

$class = trim(Str::replaceFirst($basePath, '', $file->getRealPath()), DIRECTORY_SEPARATOR);

return str_replace(
return ucfirst(Str::camel(str_replace(
[DIRECTORY_SEPARATOR, ucfirst(basename(app()->path())).'\\'],
['\\', app()->getNamespace()],
ucfirst(Str::replaceLast('.php', '', $class))
);
)));
}

/**
Expand Down
Loading

0 comments on commit f53c7bc

Please sign in to comment.