Laravel 13 upgrade, updates and fixes

This commit is contained in:
mchev
2026-03-21 18:53:33 +01:00
parent 48abd9020d
commit 186ab35fd4
34 changed files with 3849 additions and 2098 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Hashids;
use Hashids\Hashids;
use Illuminate\Support\Arr;
class HashidsFactory
{
public function make(array $config): Hashids
{
$config = $this->getConfig($config);
return $this->getClient($config);
}
/**
* @return array{salt: string, length: int, alphabet: string}
*/
protected function getConfig(array $config): array
{
return [
'salt' => Arr::get($config, 'salt', ''),
'length' => Arr::get($config, 'length', 0),
'alphabet' => Arr::get($config, 'alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
];
}
protected function getClient(array $config): Hashids
{
return new Hashids($config['salt'], $config['length'], $config['alphabet']);
}
}

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace App\Hashids;
use Hashids\Hashids;
use Illuminate\Contracts\Config\Repository;
use InvalidArgumentException;
/**
* Resolves named Hashids clients from config/hashids.php (one "connection" per model class).
*
* @method string encode(mixed ...$numbers)
* @method array decode(string $hash)
* @method string encodeHex(string $str)
* @method string decodeHex(string $hash)
*/
class HashidsManager
{
/**
* @var array<string, Hashids>
*/
protected array $connections = [];
public function __construct(
protected Repository $config,
protected HashidsFactory $factory
) {}
public function connection(?string $name = null): Hashids
{
$name = $name ?? $this->getDefaultConnection();
if (! isset($this->connections[$name])) {
$this->connections[$name] = $this->factory->make(
$this->getConnectionConfig($name)
);
}
return $this->connections[$name];
}
public function getDefaultConnection(): string
{
return (string) $this->config->get('hashids.default');
}
public function getFactory(): HashidsFactory
{
return $this->factory;
}
/**
* @return array<string, mixed>
*/
protected function getConnectionConfig(string $name): array
{
$connections = $this->config->get('hashids.connections', []);
if (! is_array($connections) || ! isset($connections[$name])) {
throw new InvalidArgumentException("Hashids connection [{$name}] not configured.");
}
return $connections[$name];
}
public function __call(string $method, array $parameters): mixed
{
return $this->connection()->$method(...$parameters);
}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace App\Hashids;
use Hashids\Hashids as HashidsClient;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider;
class HashidsServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('hashids.factory', function () {
return new HashidsFactory;
});
$this->app->alias('hashids.factory', HashidsFactory::class);
$this->app->singleton('hashids', function (Container $app) {
return new HashidsManager($app['config'], $app['hashids.factory']);
});
$this->app->alias('hashids', HashidsManager::class);
$this->app->bind('hashids.connection', function (Container $app) {
return $app['hashids']->connection();
});
$this->app->alias('hashids.connection', HashidsClient::class);
}
/**
* @return list<string>
*/
public function provides(): array
{
return [
'hashids',
'hashids.factory',
'hashids.connection',
];
}
}