Skip to content

Commit

Permalink
Merge tag 'v11.39.0'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jan 22, 2025
2 parents 8961a43 + 996c969 commit fa28f8e
Show file tree
Hide file tree
Showing 43 changed files with 1,262 additions and 531 deletions.
3 changes: 3 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
'report' => false,
],

'public' => [
Expand All @@ -42,6 +43,7 @@
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
'report' => false,
],

's3' => [
Expand All @@ -54,6 +56,7 @@
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'report' => false,
],

],
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/DatabaseBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function transaction(Closure $callback)
*/
public function rollBack()
{
$this->connection->rollBack();
$this->connection->rollBack(toLevel: 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/UniqueLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function release($job)
* @param mixed $job
* @return string
*/
protected function getKey($job)
public static function getKey($job)
{
$uniqueId = method_exists($job, 'uniqueId')
? $job->uniqueId()
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Cache/LuaScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

class LuaScripts
{
/**
* Get the Lua script that sets a key only when it does not yet exist.
*
* KEYS[1] - The name of the key
* ARGV[1] - The value of the key
* ARGV[2] - The number of seconds the key should be valid
*
* @return string
*/
public static function add()
{
return <<<'LUA'
return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])
LUA;
}

/**
* Get the Lua script to atomically release a lock.
*
Expand Down
86 changes: 74 additions & 12 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public function __construct(Redis $redis, $prefix = '', $connection = 'default')
*/
public function get($key)
{
$value = $this->connection()->get($this->prefix.$key);
$connection = $this->connection();

$value = $connection->get($this->prefix.$key);

return ! is_null($value) ? $this->unserialize($value) : null;
return ! is_null($value) ? $this->connectionAwareUnserialize($value, $connection) : null;
}

/**
Expand All @@ -89,12 +91,14 @@ public function many(array $keys)

$results = [];

$values = $this->connection()->mget(array_map(function ($key) {
$connection = $this->connection();

$values = $connection->mget(array_map(function ($key) {
return $this->prefix.$key;
}, $keys));

foreach ($values as $index => $value) {
$results[$keys[$index]] = ! is_null($value) ? $this->unserialize($value) : null;
$results[$keys[$index]] = ! is_null($value) ? $this->connectionAwareUnserialize($value, $connection) : null;
}

return $results;
Expand All @@ -110,8 +114,10 @@ public function many(array $keys)
*/
public function put($key, $value, $seconds)
{
return (bool) $this->connection()->setex(
$this->prefix.$key, (int) max(1, $seconds), $this->serialize($value)
$connection = $this->connection();

return (bool) $connection->setex(
$this->prefix.$key, (int) max(1, $seconds), $this->connectionAwareSerialize($value, $connection)
);
}

Expand Down Expand Up @@ -165,10 +171,10 @@ public function putMany(array $values, $seconds)
*/
public function add($key, $value, $seconds)
{
$lua = "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])";
$connection = $this->connection();

return (bool) $this->connection()->eval(
$lua, 1, $this->prefix.$key, $this->serialize($value), (int) max(1, $seconds)
return (bool) $connection->eval(
LuaScripts::add(), 1, $this->prefix.$key, $this->pack($value, $connection), (int) max(1, $seconds)
);
}

Expand Down Expand Up @@ -205,7 +211,9 @@ public function decrement($key, $value = 1)
*/
public function forever($key, $value)
{
return (bool) $this->connection()->set($this->prefix.$key, $this->serialize($value));
$connection = $this->connection();

return (bool) $connection->set($this->prefix.$key, $this->connectionAwareSerialize($value, $connection));
}

/**
Expand Down Expand Up @@ -313,7 +321,7 @@ protected function currentTags($chunkSize = 1000)

$prefix = $connectionPrefix.$this->getPrefix();

return LazyCollection::make(function () use ($connection, $chunkSize, $prefix, $defaultCursorValue) {
return (new LazyCollection(function () use ($connection, $chunkSize, $prefix, $defaultCursorValue) {
$cursor = $defaultCursorValue;

do {
Expand All @@ -336,7 +344,7 @@ protected function currentTags($chunkSize = 1000)
yield $tag;
}
} while (((string) $cursor) !== $defaultCursorValue);
})->map(fn (string $tagKey) => Str::match('/^'.preg_quote($prefix, '/').'tag:(.*):entries$/', $tagKey));
}))->map(fn (string $tagKey) => Str::match('/^'.preg_quote($prefix, '/').'tag:(.*):entries$/', $tagKey));
}

/**
Expand Down Expand Up @@ -414,6 +422,28 @@ public function setPrefix($prefix)
$this->prefix = $prefix;
}

/**
* Prepare a value to be used with the Redis cache store when used by eval scripts.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function pack($value, $connection)
{
if ($connection instanceof PhpRedisConnection) {
if ($connection->serialized()) {
return $connection->pack([$value])[0];
}

if ($connection->compressed()) {
return $connection->pack([$this->serialize($value)])[0];
}
}

return $this->serialize($value);
}

/**
* Serialize the value.
*
Expand All @@ -435,4 +465,36 @@ protected function unserialize($value)
{
return is_numeric($value) ? $value : unserialize($value);
}

/**
* Handle connection specific considerations when a value needs to be serialized.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function connectionAwareSerialize($value, $connection)
{
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
return $value;
}

return $this->serialize($value);
}

/**
* Handle connection specific considerations when a value needs to be unserialized.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function connectionAwareUnserialize($value, $connection)
{
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
return $value;
}

return $this->unserialize($value);
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisTagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function entries()
default => '0',
};

return LazyCollection::make(function () use ($connection, $defaultCursorValue) {
return new LazyCollection(function () use ($connection, $defaultCursorValue) {
foreach ($this->tagIds() as $tagKey) {
$cursor = $defaultCursorValue;

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function lazy($chunkSize = 1000)

$this->enforceOrderBy();

return LazyCollection::make(function () use ($chunkSize) {
return new LazyCollection(function () use ($chunkSize) {
$page = 1;

while (true) {
Expand Down Expand Up @@ -327,7 +327,7 @@ protected function orderedLazyById($chunkSize = 1000, $column = null, $alias = n

$alias ??= $column;

return LazyCollection::make(function () use ($chunkSize, $column, $alias, $descending) {
return new LazyCollection(function () use ($chunkSize, $column, $alias, $descending) {
$lastId = null;

while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace Illuminate\Database\Console\Migrations;

use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

#[AsCommand('migrate:rollback')]
class RollbackCommand extends BaseCommand
{
use ConfirmableTrait;
use ConfirmableTrait, Prohibitable;

/**
* The console command name.
Expand Down Expand Up @@ -53,8 +55,9 @@ public function __construct(Migrator $migrator)
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return 1;
if ($this->isProhibited() ||
! $this->confirmToProceed()) {
return Command::FAILURE;
}

$this->migrator->usingConnection($this->option('database'), function () {
Expand Down
19 changes: 19 additions & 0 deletions src/Illuminate/Database/Eloquent/Attributes/UseFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Database\Eloquent\Attributes;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
class UseFactory
{
/**
* Create a new attribute instance.
*
* @param class-string<\Illuminate\Database\Eloquent\Factories\Factory> $factoryClass
* @return void
*/
public function __construct(public string $factoryClass)
{
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public function pluck($column, $key = null)
if (! $this->model->hasAnyGetMutator($column) &&
! $this->model->hasCast($column) &&
! in_array($column, $this->model->getDates())) {
return $results;
return $this->applyAfterQueryCallbacks($results);
}

return $this->applyAfterQueryCallbacks(
Expand Down
25 changes: 24 additions & 1 deletion src/Illuminate/Database/Eloquent/Factories/HasFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Database\Eloquent\Factories;

use Illuminate\Database\Eloquent\Attributes\UseFactory;

/**
* @template TFactory of \Illuminate\Database\Eloquent\Factories\Factory
*/
Expand Down Expand Up @@ -34,6 +36,27 @@ protected static function newFactory()
return static::$factory::new();
}

return null;
return static::getUseFactoryAttribute() ?? null;
}

/**
* Get the factory from the UseFactory class attribute.
*
* @return TFactory|null
*/
protected static function getUseFactoryAttribute()
{
$attributes = (new \ReflectionClass(static::class))
->getAttributes(UseFactory::class);

if ($attributes !== []) {
$useFactory = $attributes[0]->newInstance();

$factory = new $useFactory->factoryClass;

$factory->guessModelNamesUsing(fn () => static::class);

return $factory;
}
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function lines($path)
);
}

return LazyCollection::make(function () use ($path) {
return new LazyCollection(function () use ($path) {
$file = new SplFileObject($path);

$file->setFlags(SplFileObject::DROP_NEW_LINE);
Expand Down
Loading

0 comments on commit fa28f8e

Please sign in to comment.