Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone #152

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
issue #155 - better dependency management in composer.json file
  • Loading branch information
pounard committed Jun 4, 2024
commit f4ffec1227e15926bbe1c9748f5ac081567754b4
17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@
"prefer-stable": true,
"require": {
"php": ">=8.1",
"doctrine/doctrine-bundle": "^2.10.0",
"makinacorpus/query-builder": "^1.6.1",
"psr/log": "^3.0",
"symfony/config": "^6.0|^7.0",
"symfony/console": "^6.0|^7.0",
"symfony/dependency-injection": "^6.0|^7.0",
"symfony/filesystem": "^6.0|^7.0",
"symfony/finder": "^6.0|^7.0",
"symfony/options-resolver": "^6.0|^7.0",
"symfony/password-hasher": "^6.0|^7.0",
"symfony/process": "^6.0|^7.0",
"symfony/yaml": "^6.0|^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.10.0",
"doctrine/orm": "^2.15|^3.0",
"friendsofphp/php-cs-fixer": "^3.34",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.4",
"symfony/dependency-injection": "^6.0|^7.0",
"symfony/framework-bundle": "^6.0|^7.0",
"symfony/password-hasher": "^6.0|^7.0",
"symfony/validator": "^6.3|^7.0"
},
"suggest": {
"doctrine/doctrine-bundle": "For autoconfiguration in Symfony project context",
"symfony/console": "In order to use the standalone CLI tool or Symfony console commands",
"symfony/password-hasher": "In order to use the password hash anonymizer"
},
"conflict": {
"symfony/console": "<6.0|>=8.0",
"symfony/password-hasher": "<6.0|>=8.0"
pounard marked this conversation as resolved.
Show resolved Hide resolved
},
"autoload": {
"psr-4": {
"MakinaCorpus\\DbToolsBundle\\" : "src/"
Expand Down
3 changes: 3 additions & 0 deletions src/Anonymization/Anonymizer/Core/PasswordAnonymizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AbstractAnonymizer;
use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer;
use MakinaCorpus\DbToolsBundle\Error\MissingDependencyException;
use MakinaCorpus\QueryBuilder\Query\Update;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;

Expand All @@ -22,6 +23,8 @@ class PasswordAnonymizer extends AbstractAnonymizer
#[\Override]
protected function validateOptions(): void
{
MissingDependencyException::check('symfony/password-hasher', PasswordHasherFactory::class);
pounard marked this conversation as resolved.
Show resolved Hide resolved

$algorithm = $this->options->getString('algorithm', 'auto');
$this->options->getString('password', 'password');

Expand Down
32 changes: 32 additions & 0 deletions src/Error/MissingDependencyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare (strict_types=1);

namespace MakinaCorpus\DbToolsBundle\Error;

class MissingDependencyException extends \RuntimeException
{
/**
* Create new missing dependency exception.
*/
public static function create(string $package, ?string $className = null): self
{
if ($className) {
$message = \sprintf("'%s' dependency is missing in order to use '%s' class, please consider running 'composer require %s'", $package, $className, $package);
} else {
$message = \sprintf("'%s' dependency is missing, please consider running 'composer require %s'", $package, $package);
}

return new self($message);
}

/**
* Check class exists, raise missing dependency exception if not.
*/
public static function check(string $package, string $className): void
{
if (!\class_exists($className)) {
throw self::create($package, $className);
}
}
}