Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Mar 5, 2022
2 parents f88d4ac + 72ab17a commit 2e5c758
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Exclude files from exporting
#

/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 1 addition & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php

/** @noinspection PhpMissingParentCallCommonInspection */

declare(strict_types=1);

namespace Vdlp\Hashids;

use System\Classes\PluginBase;

class Plugin extends PluginBase
final class Plugin extends PluginBase
{
public function pluginDetails(): array
{
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion classes/Hashids.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,46 @@

class Hashids implements HashidsInterface
{
private $hashids;
private HashidsHelper $hashids;

public function __construct(HashidsHelper $hashids)
{
$this->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];
}

return 0;
}

/**
* @inheritDoc
*/
public function encodeHex($str): string
{
return $this->hashids->encodeHex($str);
}

/**
* @inheritDoc
*/
public function decodeHex($hash): string
{
return $this->hashids->decodeHex($hash);
Expand Down
24 changes: 11 additions & 13 deletions classes/HashidsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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]);
Expand All @@ -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];
Expand All @@ -90,6 +86,7 @@ public function getInstanceConfig(string $name = null): array

/**
* @return mixed
*
* @throws InvalidArgumentException
*/
public function __call(string $method, array $parameters)
Expand All @@ -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);
}

Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"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",
"email": "[email protected]"
}
],
"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/"
]
}
Expand Down
5 changes: 4 additions & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

'configurations' => [

'main' => [
'salt' => 'insert-salt-string-here',
'length' => 10,
Expand All @@ -36,7 +37,9 @@
'different-configuration' => [
'salt' => 'insert-different-salt-string-here',
'length' => 100,
'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', # Default alphabet
'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
],

],

];
11 changes: 6 additions & 5 deletions updates/version.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2e5c758

Please sign in to comment.