├── LICENSE ├── composer.json ├── config └── hashids.php └── src ├── Facades └── Hashids.php ├── HashidsFactory.php ├── HashidsManager.php └── HashidsServiceProvider.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Vincent Klaiber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vinkla/hashids", 3 | "description": "A Hashids bridge for Laravel", 4 | "license": "MIT", 5 | "keywords": [ 6 | "hashids", 7 | "laravel" 8 | ], 9 | "authors": [ 10 | { 11 | "name": "Vincent Klaiber", 12 | "homepage": "https://github.com/vinkla" 13 | } 14 | ], 15 | "require": { 16 | "php": "^8.2", 17 | "graham-campbell/manager": "^5.2", 18 | "hashids/hashids": "^5.0", 19 | "illuminate/contracts": "^12.0", 20 | "illuminate/support": "^12.0" 21 | }, 22 | "require-dev": { 23 | "graham-campbell/analyzer": "^5.0", 24 | "graham-campbell/testbench": "^6.1", 25 | "mockery/mockery": "^1.6.6", 26 | "phpunit/phpunit": "^11.5 || ^12.1" 27 | }, 28 | "minimum-stability": "dev", 29 | "prefer-stable": true, 30 | "autoload": { 31 | "psr-4": { 32 | "Vinkla\\Hashids\\": "src/" 33 | } 34 | }, 35 | "autoload-dev": { 36 | "psr-4": { 37 | "Vinkla\\Tests\\Hashids\\": "tests/" 38 | } 39 | }, 40 | "config": { 41 | "preferred-install": "dist" 42 | }, 43 | "extra": { 44 | "laravel": { 45 | "aliases": { 46 | "Hashids": "Vinkla\\Hashids\\Facades\\Hashids" 47 | }, 48 | "providers": [ 49 | "Vinkla\\Hashids\\HashidsServiceProvider" 50 | ] 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /config/hashids.php: -------------------------------------------------------------------------------- 1 | 'main', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Hashids Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here are each of the connections setup for your application. Example 24 | | configuration has been included, but you may add as many connections as 25 | | you would like. 26 | | 27 | */ 28 | 29 | 'connections' => [ 30 | 31 | 'main' => [ 32 | 'salt' => '', 33 | 'length' => 0, 34 | // 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' 35 | ], 36 | 37 | 'alternative' => [ 38 | 'salt' => 'your-salt-string', 39 | 'length' => 'your-length-integer', 40 | // 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' 41 | ], 42 | 43 | ], 44 | 45 | ]; 46 | -------------------------------------------------------------------------------- /src/Facades/Hashids.php: -------------------------------------------------------------------------------- 1 | getConfig($config); 24 | 25 | return $this->getClient($config); 26 | } 27 | 28 | protected function getConfig(array $config): array 29 | { 30 | return [ 31 | 'salt' => Arr::get($config, 'salt', ''), 32 | 'length' => Arr::get($config, 'length', 0), 33 | 'alphabet' => Arr::get($config, 'alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), 34 | ]; 35 | } 36 | 37 | protected function getClient(array $config): Hashids 38 | { 39 | return new Hashids($config['salt'], $config['length'], $config['alphabet']); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/HashidsManager.php: -------------------------------------------------------------------------------- 1 | factory = $factory; 35 | } 36 | 37 | protected function createConnection(array $config): Hashids 38 | { 39 | return $this->factory->make($config); 40 | } 41 | 42 | protected function getConfigName(): string 43 | { 44 | return 'hashids'; 45 | } 46 | 47 | public function getFactory(): HashidsFactory 48 | { 49 | return $this->factory; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/HashidsServiceProvider.php: -------------------------------------------------------------------------------- 1 | setupConfig(); 25 | } 26 | 27 | protected function setupConfig(): void 28 | { 29 | $source = realpath($raw = __DIR__ . '/../config/hashids.php') ?: $raw; 30 | 31 | $this->publishes([$source => config_path('hashids.php')]); 32 | 33 | $this->mergeConfigFrom($source, 'hashids'); 34 | } 35 | 36 | public function register(): void 37 | { 38 | $this->registerFactory(); 39 | $this->registerManager(); 40 | $this->registerBindings(); 41 | } 42 | 43 | protected function registerFactory(): void 44 | { 45 | $this->app->singleton('hashids.factory', function () { 46 | return new HashidsFactory(); 47 | }); 48 | 49 | $this->app->alias('hashids.factory', HashidsFactory::class); 50 | } 51 | 52 | protected function registerManager(): void 53 | { 54 | $this->app->singleton('hashids', function (Container $app) { 55 | $config = $app['config']; 56 | $factory = $app['hashids.factory']; 57 | 58 | return new HashidsManager($config, $factory); 59 | }); 60 | 61 | $this->app->alias('hashids', HashidsManager::class); 62 | } 63 | 64 | protected function registerBindings(): void 65 | { 66 | $this->app->bind('hashids.connection', function (Container $app) { 67 | $manager = $app['hashids']; 68 | 69 | return $manager->connection(); 70 | }); 71 | 72 | $this->app->alias('hashids.connection', Hashids::class); 73 | } 74 | 75 | public function provides(): array 76 | { 77 | return [ 78 | 'hashids', 79 | 'hashids.factory', 80 | 'hashids.connection', 81 | ]; 82 | } 83 | } 84 | --------------------------------------------------------------------------------