From 7447a70c475d4c811bda57e920f5a27b4394fd25 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Fri, 18 Jan 2019 16:27:40 +0100 Subject: [PATCH 1/5] Fix @package docblock --- Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin.php b/Plugin.php index 5c5de95..4993f1c 100644 --- a/Plugin.php +++ b/Plugin.php @@ -10,7 +10,7 @@ /** * Class Plugin * - * @package Vdlp\Redirect + * @package Vdlp\Hashids */ class Plugin extends PluginBase { From 4eacf51f4040fdd85531a60a997b1c40812f39d6 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 19 Jan 2019 12:17:39 +0100 Subject: [PATCH 2/5] Update README --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2879bd8..d91e0c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. -It converts numbers like 347 into strings like “yr8”, or array of numbers like [27, 986] into “3kTMd”. +It converts numbers like 347 into strings like "yr8", or array of numbers like [27, 986] into "3kTMd". You can also decode those ids back. This is useful in bundling several parameters into one or simply using them as short UIDs. @@ -15,7 +15,9 @@ You can also decode those ids back. This is useful in bundling several parameter *CLI:* -`php artisan plugin:install Vdlp.Hashids` +``` +php artisan plugin:install Vdlp.Hashids +``` *October CMS:* @@ -25,7 +27,9 @@ Go to Settings > Updates & Plugins > Install plugins and search for 'Hashids'. To configure this plugin execute the following command: -`php artisan vendor:publish --provider="Vdlp\Hashids\ServiceProviders\HashidsServiceProvider" --tag="config"` +``` +php artisan vendor:publish --provider="Vdlp\Hashids\ServiceProviders\HashidsServiceProvider" --tag="config" +``` This will create a `config/hashids.php` file in your app where you can modify the configuration. @@ -34,17 +38,17 @@ This will create a `config/hashids.php` file in your app where you can modify th Here you can see an example of how to use this plugin. Out of the box, the default configuration used is `main`. ``` -// You can use this class also with Dependency Injection +// You can use this class with Dependency Injection use Vdlp\Hashids\Classes\HashidsManager; /** @var HashidsManager $hashids */ $hashidsManager = resolve(HashidsManager::class); -// Encodes the integer 1 to an hashid using the default configuration +// Encodes the integer 1 to a hashid using the default configuration $hashidsManager->encode(1); $hashidsManager->instance()->encode(1); -// Encodes the integer 1 to an hashid using a different configuration +// Encodes the integer 1 to a hashid using a different configuration $hashidsManager->instance('different-configuration')->encode(1); ``` From 0409a5ae63cbfeb84ec50849688c7feecc655c42 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Fri, 25 Jan 2019 11:55:42 +0100 Subject: [PATCH 3/5] Fix license file --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index b41c570..8df7e90 100644 --- a/LICENSE +++ b/LICENSE @@ -344,4 +344,4 @@ WRITTEN OFFER The source code for any program binaries or compressed scripts that are included with this plugin can be freely obtained at the following URL: - https://github.com/vdlp/oc-redirect-plugin + https://github.com/vdlp/oc-hashids-plugin From 9ca300d7c26c4a4a7ff52e4a49161f2a4a66acb5 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 20 Apr 2020 11:11:42 +0200 Subject: [PATCH 4/5] Code optimizations --- Plugin.php | 16 ++------ README.md | 2 +- ...ServiceProvider.php => ServiceProvider.php | 19 ++++------ classes/Hashids.php | 27 -------------- classes/HashidsFactory.php | 13 ------- classes/HashidsManager.php | 37 ------------------- composer.json | 6 +++ 7 files changed, 17 insertions(+), 103 deletions(-) rename serviceproviders/HashidsServiceProvider.php => ServiceProvider.php (54%) diff --git a/Plugin.php b/Plugin.php index 4993f1c..8acfde4 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,22 +1,15 @@ app->register(HashidsServiceProvider::class); + $this->app->register(ServiceProvider::class); } } diff --git a/README.md b/README.md index d91e0c4..9d6c7cc 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ You can also decode those ids back. This is useful in bundling several parameter ## Requirements * PHP 7.1 or higher -* October CMS build 420 or higher +* Preferably one of the latest October CMS build ## Installation diff --git a/serviceproviders/HashidsServiceProvider.php b/ServiceProvider.php similarity index 54% rename from serviceproviders/HashidsServiceProvider.php rename to ServiceProvider.php index 78a243f..4ede677 100644 --- a/serviceproviders/HashidsServiceProvider.php +++ b/ServiceProvider.php @@ -2,20 +2,15 @@ declare(strict_types=1); -namespace Vdlp\Hashids\ServiceProviders; +namespace Vdlp\Hashids; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Container\Container; -use October\Rain\Support\ServiceProvider; +use October\Rain\Support\ServiceProvider as BaseServiceProvider; use Vdlp\Hashids\Classes\HashidsFactory; use Vdlp\Hashids\Classes\HashidsManager; -/** - * Class HashidsServiceProvider - * - * @package Vdlp\Hashids\ServiceProviders - */ -class HashidsServiceProvider extends ServiceProvider +class ServiceProvider extends BaseServiceProvider { /** * @return void @@ -23,10 +18,10 @@ class HashidsServiceProvider extends ServiceProvider public function boot(): void { $this->publishes([ - __DIR__ . '/../config.php' => config_path('hashids.php'), + __DIR__ . '/config.php' => config_path('hashids.php'), ], 'config'); - $this->mergeConfigFrom(__DIR__ . '/../config.php', 'hashids'); + $this->mergeConfigFrom(__DIR__ . '/config.php', 'hashids'); } /** @@ -34,11 +29,11 @@ public function boot(): void */ public function register(): void { - $this->app->singleton(HashidsFactory::class, function (): HashidsFactory { + $this->app->singleton(HashidsFactory::class, static function (): HashidsFactory { return new HashidsFactory(); }); - $this->app->singleton(HashidsManager::class, function (Container $container): HashidsManager { + $this->app->singleton(HashidsManager::class, static function (Container $container): HashidsManager { return new HashidsManager( $container->make(Repository::class), $container->make(HashidsFactory::class) diff --git a/classes/Hashids.php b/classes/Hashids.php index 2dca0b0..dd89078 100644 --- a/classes/Hashids.php +++ b/classes/Hashids.php @@ -7,39 +7,20 @@ use Hashids\Hashids as HashidsHelper; use Hashids\HashidsInterface; -/** - * Class Hashids - * - * @package Vdlp\Hashids\Classes - */ class Hashids implements HashidsInterface { - /** - * @var HashidsHelper - */ private $hashids; - /** - * @param HashidsHelper $hashids - */ public function __construct(HashidsHelper $hashids) { $this->hashids = $hashids; } - /** - * @param array $numbers - * @return string - */ public function encode(...$numbers): string { return $this->hashids->encode($numbers); } - /** - * @param string $hash - * @return int - */ public function decode($hash): int { $result = $this->hashids->decode($hash); @@ -50,19 +31,11 @@ public function decode($hash): int return 0; } - /** - * @param string $str - * @return string - */ public function encodeHex($str): string { return $this->hashids->encodeHex($str); } - /** - * @param string $hash - * @return string - */ public function decodeHex($hash): string { return $this->hashids->decodeHex($hash); diff --git a/classes/HashidsFactory.php b/classes/HashidsFactory.php index 4445c37..deec0df 100644 --- a/classes/HashidsFactory.php +++ b/classes/HashidsFactory.php @@ -7,16 +7,9 @@ use Hashids\Hashids as HashidsBase; use Hashids\HashidsException; -/** - * Class HashidsFactory - * - * @package Vdlp\Hashids\Classes - */ class HashidsFactory { /** - * @param array $config - * @return Hashids * @throws HashidsException */ public function make(array $config): Hashids @@ -24,10 +17,6 @@ public function make(array $config): Hashids return $this->getInstance($this->getConfig($config)); } - /** - * @param array $config - * @return array - */ protected function getConfig(array $config): array { return [ @@ -38,8 +27,6 @@ protected function getConfig(array $config): array } /** - * @param array $config - * @return Hashids * @throws HashidsException */ protected function getInstance(array $config): Hashids diff --git a/classes/HashidsManager.php b/classes/HashidsManager.php index 2c4a40e..4861c72 100644 --- a/classes/HashidsManager.php +++ b/classes/HashidsManager.php @@ -9,22 +9,12 @@ use InvalidArgumentException; /** - * Class HashidsManager - * - * @package Vdlp\Hashids\Classes - * * @mixin Hashids */ class HashidsManager { - /** - * @var Repository - */ protected $config; - /** - * @var HashidsFactory - */ protected $factory; /** @@ -32,10 +22,6 @@ class HashidsManager */ protected $instances = []; - /** - * @param Repository $config - * @param HashidsFactory $factory - */ public function __construct(Repository $config, HashidsFactory $factory) { $this->config = $config; @@ -43,8 +29,6 @@ public function __construct(Repository $config, HashidsFactory $factory) } /** - * @param string|null $name - * @return Hashids * @throws InvalidArgumentException */ public function instance(string $name = null): Hashids @@ -59,8 +43,6 @@ public function instance(string $name = null): Hashids } /** - * @param string|null $name - * @return Hashids * @throws InvalidArgumentException */ public function reloadInstance(string $name = null): Hashids @@ -72,36 +54,23 @@ public function reloadInstance(string $name = null): Hashids return $this->instance($name); } - /** - * @param string|null $name - * @return void - */ public function removeInstance(string $name = null): void { $name = $name ?: $this->getDefaultInstance(); unset($this->instances[$name]); } - /** - * @return string - */ public function getDefaultInstance(): string { return $this->config->get('hashids.default'); } - /** - * @param string $name - * @return void - */ public function setDefaultInstance(string $name): void { $this->config->set('hashids.default', $name); } /** - * @param string|null $name - * @return array * @throws InvalidArgumentException */ public function getInstanceConfig(string $name = null): array @@ -120,8 +89,6 @@ public function getInstanceConfig(string $name = null): array } /** - * @param string $method - * @param array $parameters * @return mixed * @throws InvalidArgumentException */ @@ -131,8 +98,6 @@ public function __call(string $method, array $parameters) } /** - * @param string $name - * @return Hashids * @throws InvalidArgumentException */ protected function makeInstance(string $name): Hashids @@ -142,8 +107,6 @@ protected function makeInstance(string $name): Hashids } /** - * @param array $config - * @return Hashids * @throws HashidsException */ protected function createInstance(array $config): Hashids diff --git a/composer.json b/composer.json index a06f51f..fe71561 100644 --- a/composer.json +++ b/composer.json @@ -12,5 +12,11 @@ "require": { "php": ">=7.1", "hashids/hashids": "^3.0" + }, + "archive": { + "exclude": [ + ".gitignore", + ".idea/" + ] } } From 35f67310cda9e0c2ce884919576651bba94d73ac Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 20 Apr 2020 11:11:49 +0200 Subject: [PATCH 5/5] Bump version to 1.1.0 --- updates/version.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/updates/version.yaml b/updates/version.yaml index 01c1562..9220207 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1,2 +1,5 @@ 1.0.0: First version of Vdlp.Hashids 1.0.1: Add PHP >= 7.1 as dependency +1.1.0: + - Code optimizations + - Moved service provider