From 4e4236e3928301d9849e136d1cd0ff84be1bdaa4 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:32:42 +0100 Subject: [PATCH 1/7] Add .gitattributes --- .gitattributes | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..eca2e30 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# +# Exclude files from exporting +# + +/.gitattributes export-ignore +/.github export-ignore +/.gitignore export-ignore From 7f3cbf5117ebc9b2fd9bee8e215fbda4e57727a0 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:32:51 +0100 Subject: [PATCH 2/7] Add CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5c1f858 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2.1.0] - 2022-03-05 + +### Changes + +- Changed minimum required PHP version to 7.4. +- Add .gitattributes file. +- Update composer version constraints for composer/installers package. +- Change config.php code style. +- Add version constraint for october/system. From 272f2736dd3f258bcf9e68c677a6c4c83b7e51a1 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:33:13 +0100 Subject: [PATCH 3/7] Update plugin dependencies --- composer.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e8410d9..d9861cf 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "vdlp/oc-hashids-plugin", "description": "Allows developers to use secure hashed ID's in October CMS powered websites.", - "type": "october-plugin", "license": "GPL-2.0-only", + "type": "october-plugin", "authors": [ { "name": "Van der Let & Partners", @@ -10,13 +10,15 @@ } ], "require": { - "php": "^7.2||^8.0", + "php": "^7.4 || ^8.0", + "composer/installers": "^1.0 || ^2.0", "hashids/hashids": "^4.0", - "composer/installers": "^1.0" + "october/system": "^1.0 || ^2.0" }, "archive": { "exclude": [ ".gitignore", + ".github", ".idea/" ] } From f0d51af93c177a20cb7dd48721cc4da933b5336c Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:33:53 +0100 Subject: [PATCH 4/7] Improve code style --- Plugin.php | 4 +--- classes/Hashids.php | 15 ++++++++++++++- classes/HashidsManager.php | 24 +++++++++++------------- config.php | 5 ++++- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Plugin.php b/Plugin.php index 8acfde4..1f7450c 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,14 +1,12 @@ hashids = $hashids; } + /** + * @inheritDoc + */ public function encode(...$numbers): string { return $this->hashids->encode($numbers); } + /** + * @inheritDoc + */ public function decode($hash): int { $result = $this->hashids->decode($hash); + if (array_key_exists(0, $result)) { return (int) $result[0]; } @@ -31,11 +38,17 @@ public function decode($hash): int return 0; } + /** + * @inheritDoc + */ public function encodeHex($str): string { return $this->hashids->encodeHex($str); } + /** + * @inheritDoc + */ public function decodeHex($hash): string { return $this->hashids->decodeHex($hash); diff --git a/classes/HashidsManager.php b/classes/HashidsManager.php index 4861c72..adfe8ed 100644 --- a/classes/HashidsManager.php +++ b/classes/HashidsManager.php @@ -13,14 +13,9 @@ */ class HashidsManager { - protected $config; - - protected $factory; - - /** - * @var Hashids[] - */ - protected $instances = []; + protected array $instances = []; + protected Repository $config; + protected HashidsFactory $factory; public function __construct(Repository $config, HashidsFactory $factory) { @@ -31,7 +26,7 @@ public function __construct(Repository $config, HashidsFactory $factory) /** * @throws InvalidArgumentException */ - public function instance(string $name = null): Hashids + public function instance(?string $name = null): Hashids { $name = $name ?: $this->getDefaultInstance(); @@ -45,7 +40,7 @@ public function instance(string $name = null): Hashids /** * @throws InvalidArgumentException */ - public function reloadInstance(string $name = null): Hashids + public function reloadInstance(?string $name = null): Hashids { $name = $name ?: $this->getDefaultInstance(); @@ -54,7 +49,7 @@ public function reloadInstance(string $name = null): Hashids return $this->instance($name); } - public function removeInstance(string $name = null): void + public function removeInstance(?string $name = null): void { $name = $name ?: $this->getDefaultInstance(); unset($this->instances[$name]); @@ -73,13 +68,14 @@ public function setDefaultInstance(string $name): void /** * @throws InvalidArgumentException */ - public function getInstanceConfig(string $name = null): array + public function getInstanceConfig(?string $name = null): array { $name = $name ?: $this->getDefaultInstance(); $configurations = $this->config->get('hashids.configurations'); + if (!isset($configurations[$name]) || !is_array($configurations[$name])) { - throw new InvalidArgumentException("Configuration $name is not properly configured."); + throw new InvalidArgumentException(sprintf('Configuration %s is not properly configured.', $name)); } $config = $configurations[$name]; @@ -90,6 +86,7 @@ public function getInstanceConfig(string $name = null): array /** * @return mixed + * * @throws InvalidArgumentException */ public function __call(string $method, array $parameters) @@ -103,6 +100,7 @@ public function __call(string $method, array $parameters) protected function makeInstance(string $name): Hashids { $config = $this->getInstanceConfig($name); + return $this->createInstance($config); } diff --git a/config.php b/config.php index b4b6379..17d8d35 100644 --- a/config.php +++ b/config.php @@ -28,6 +28,7 @@ */ 'configurations' => [ + 'main' => [ 'salt' => 'insert-salt-string-here', 'length' => 10, @@ -36,7 +37,9 @@ 'different-configuration' => [ 'salt' => 'insert-different-salt-string-here', 'length' => 100, - 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', # Default alphabet + 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', ], + ], + ]; From 7226375f41614f9d5d4775df34a0b80aa96e7c0b Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:34:04 +0100 Subject: [PATCH 5/7] Update version.yaml --- updates/version.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/updates/version.yaml b/updates/version.yaml index 288be5e..0ef3202 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1,7 +1,8 @@ -1.0.0: First version of Vdlp.Hashids -1.0.1: Add PHP >= 7.1 as dependency -1.1.0: +v1.0.0: First version of Vdlp.Hashids +v1.0.1: Add PHP >= 7.1 as dependency +v1.1.0: - Code optimizations - Moved service provider -2.0.0: Drop PHP 7.1 support -2.0.1: Update plugin dependencies +v2.0.0: Drop PHP 7.1 support +v2.0.1: Update plugin dependencies +v2.1.0: Maintenance release From ff40b19844163f7ae5774457a672a210a8cdca91 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:34:19 +0100 Subject: [PATCH 6/7] Update GitHub PHP workflow configuration --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index d73cbbd..b1c4618 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.0, 7.4, 7.3, 7.2 ] + php: [ 8.0, 7.4 ] stability: [ prefer-lowest, prefer-stable ] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} From 72ab17aab1435cf970f206876780753a2bd24092 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Sat, 5 Mar 2022 11:34:26 +0100 Subject: [PATCH 7/7] Update README --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e4edb86..42df0d0 100644 --- a/README.md +++ b/README.md @@ -24,21 +24,15 @@ You can also decode those ids back. This is useful in bundling several parameter ## Requirements -* PHP 7.2 or higher -* October CMS build 468 or higher +* PHP 7.4 or higher +* October CMS 1.x or 2.x ## Installation -*CLI:* - ``` -php artisan plugin:install Vdlp.Hashids +composer require vdlp/oc-hashids-plugin ``` -*October CMS:* - -Go to Settings > Updates & Plugins > Install plugins and search for 'Hashids'. - ## Configuration To configure this plugin execute the following command: