Files
pterodactyl-panel/app/Providers/HashidsServiceProvider.php
T

34 lines
1.0 KiB
PHP
Raw Normal View History

2017-09-09 23:55:21 -05:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2017-09-09 23:55:21 -05:00
namespace Pterodactyl\Providers;
2026-10-05 18:10:18 -04:00
use Illuminate\Contracts\Config\Repository;
2017-09-09 23:55:21 -05:00
use Illuminate\Support\ServiceProvider;
use Pterodactyl\Contracts\Extensions\HashidsInterface;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Extensions\Hashids;
use Pterodactyl\Support\JsonValueGuard;
2017-09-09 23:55:21 -05:00
class HashidsServiceProvider extends ServiceProvider
{
/**
* Register the ability to use Hashids.
*/
2023-02-23 12:30:16 -07:00
public function register(): void
2017-09-09 23:55:21 -05:00
{
2026-10-05 18:10:18 -04:00
$this->app->singleton(function (): HashidsInterface {
$config = $this->app->make(Repository::class);
$length = filter_var($config->get('hashids.length', 0), FILTER_VALIDATE_INT);
2017-09-09 23:55:21 -05:00
return new Hashids(
2026-10-05 18:10:18 -04:00
JsonValueGuard::string($config->get('hashids.salt', '')),
$length === false ? 0 : $length,
JsonValueGuard::string($config->get('hashids.alphabet', 'abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'))
2017-09-09 23:55:21 -05:00
);
});
$this->app->alias(HashidsInterface::class, 'hashids');
}
}