Add hash generator service and test command #639

This commit is contained in:
Kendrick Chan 2021-11-23 01:08:21 +08:00
parent 26293e4239
commit c03c793d04
6 changed files with 888 additions and 1047 deletions

View file

@ -10,10 +10,16 @@
"ext-iconv": "*",
"catalyst/auth-bundle": "dev-master",
"catalyst/menu-bundle": "dev-master",
"composer/package-versions-deprecated": "1.11.99.4",
"creof/doctrine2-spatial": "^1.2",
"data-dog/audit-bundle": "^0.1.10",
"doctrine/common": "^2",
"doctrine/doctrine-bundle": "^2",
"doctrine/doctrine-migrations-bundle": "^2",
"doctrine/orm": "^2",
"edwinhoksberg/php-fcm": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"hashids/hashids": "^4.1",
"microsoft/azure-storage-blob": "^1.5",
"predis/predis": "^1.1",
"sensio/framework-extra-bundle": "^5.1",
@ -26,9 +32,7 @@
"symfony/framework-bundle": "^4.0",
"symfony/maker-bundle": "^1.0",
"symfony/monolog-bundle": "^3.7",
"symfony/orm-pack": "^1.0",
"symfony/process": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/security-bundle": "^4.0",
"symfony/translation": "^4.0",
"symfony/twig-bundle": "^4.0",
@ -38,7 +42,9 @@
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/dotenv": "^4.0",
"symfony/thanks": "^1.0"
"symfony/stopwatch": "^4.0",
"symfony/thanks": "^1.0",
"symfony/web-profiler-bundle": "^4.0"
},
"config": {
"preferred-install": {

1802
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,43 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Service\HashGenerator;
class TestHashGeneratorCommand extends Command
{
protected $hash;
protected function configure()
{
$this->setName('test:hash')
->setDescription('Test hash generator.')
->setHelp('Test hash generator service.');
}
public function __construct(HashGenerator $hash)
{
$this->hash = $hash;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$orig_id = 39095;
error_log('original id - ' . $orig_id);
$hash_id = $this->hash->getHash($orig_id);
error_log('hash id - ' . $hash_id);
$id = $this->hash->getID($hash_id);
error_log('id - ' . $id);
return 0;
}
}

View file

@ -4,7 +4,8 @@ namespace App\DataFixtures;
use App\Entity\Role;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
// use Doctrine\Common\Persistence\ObjectManager;
class RoleFixtures extends Fixture
{

View file

@ -0,0 +1,27 @@
<?php
namespace App\Service;
use Hashids\Hashids;
class HashGenerator
{
// TODO: set in env file and set in constructor
protected $salt = 'salt that should be in the env file 230498';
protected $length = 15;
public function getHash($id)
{
$hi = new Hashids($this->salt, $this->length);
return $hi->encode($id);
}
public function getID($hash)
{
$hi = new Hashids($this->salt, $this->length);
$id_array = $hi->decode($hash);
// first one should be the id
return $id_array[0];
}
}

View file

@ -44,6 +44,9 @@
"doctrine/dbal": {
"version": "v2.6.3"
},
"doctrine/deprecations": {
"version": "v0.5.3"
},
"doctrine/doctrine-bundle": {
"version": "1.6",
"recipe": {
@ -96,7 +99,10 @@
"version": "v1.0.1"
},
"doctrine/reflection": {
"version": "v1.0.0"
"version": "1.2.2"
},
"doctrine/sql-formatter": {
"version": "1.1.2"
},
"edwinhoksberg/php-fcm": {
"version": "1.0.0"
@ -110,8 +116,11 @@
"guzzlehttp/psr7": {
"version": "1.4.2"
},
"jdorn/sql-formatter": {
"version": "v1.2.17"
"hashids/hashids": {
"version": "4.1.0"
},
"laminas/laminas-zendframework-bridge": {
"version": "1.1.1"
},
"microsoft/azure-storage-blob": {
"version": "1.5.2"
@ -233,15 +242,15 @@
"ref": "18f6fdceb63737d991efbb37ae9619a6f6c978c8"
}
},
"symfony/http-client-contracts": {
"version": "v2.4.0"
},
"symfony/http-foundation": {
"version": "v4.0.2"
},
"symfony/http-kernel": {
"version": "v4.0.2"
},
"symfony/inflector": {
"version": "v4.0.2"
},
"symfony/maker-bundle": {
"version": "1.0",
"recipe": {
@ -251,9 +260,6 @@
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
}
},
"symfony/mime": {
"version": "v4.3.0"
},
"symfony/monolog-bridge": {
"version": "v5.2.5"
},
@ -272,15 +278,18 @@
"config/packages/test/monolog.yaml"
]
},
"symfony/orm-pack": {
"version": "v1.0.5"
},
"symfony/polyfill-ctype": {
"version": "v1.9.0"
},
"symfony/polyfill-intl-grapheme": {
"version": "v1.23.1"
},
"symfony/polyfill-intl-idn": {
"version": "v1.11.0"
},
"symfony/polyfill-intl-normalizer": {
"version": "v1.23.0"
},
"symfony/polyfill-mbstring": {
"version": "v1.6.0"
},
@ -290,15 +299,21 @@
"symfony/polyfill-php73": {
"version": "v1.11.0"
},
"symfony/polyfill-php80": {
"version": "v1.23.1"
},
"symfony/polyfill-php81": {
"version": "v1.23.0"
},
"symfony/process": {
"version": "v4.4.9"
},
"symfony/profiler-pack": {
"version": "v1.0.3"
},
"symfony/property-access": {
"version": "v4.0.2"
},
"symfony/property-info": {
"version": "v5.3.8"
},
"symfony/routing": {
"version": "4.0",
"recipe": {
@ -335,6 +350,9 @@
"symfony/stopwatch": {
"version": "v4.0.2"
},
"symfony/string": {
"version": "v5.3.10"
},
"symfony/thanks": {
"version": "v1.1.0"
},