Skip to content

Commit

Permalink
Add comment for RulesMaped class
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakvGhost committed Nov 18, 2023
1 parent 1629a6d commit 2b00484
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/RulesMaped.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

/**
* RulesMaped - class that mapped all the rules used with their alias
* RulesMaped - Class that maps all the validation rules with their aliases
*
* This class provides a convenient mapping of rule aliases to their corresponding PHPValidator rules.
* It allows for easy reference and retrieval of validation rule classes.
*
* @package BlakvGhost\PHPValidator
* @author Kabirou ALASSANE
Expand Down Expand Up @@ -40,7 +43,9 @@

class RulesMaped
{

/**
* @var array Mapping of rule aliases to their corresponding rule classes.
*/
private static $rules = [
'accepted' => AcceptedRule::class,
'accepted_if' => AcceptedIfRule::class,
Expand Down Expand Up @@ -70,25 +75,43 @@ class RulesMaped
'ip' => ValidIpRule::class,
];

/**
* Get the mapping of rule aliases to their corresponding rule classes.
*
* @return array
*/
protected static function getRules(): array
{
return self::$rules;
}

/**
* Get the rule class for a given alias.
*
* @param string $alias Rule alias to retrieve the corresponding rule class.
* @return string Rule class.
* @throws ValidatorException If the rule alias is not found.
*/
protected static function getRule(string $alias): string
{
if (isset(self::$rules[$alias]) && class_exists(self::$rules[$alias])) {

return self::$rules[$alias];
}

$translatedMessage = LangManager::getTranslation('validation.rule_not_found', [
'ruleName' => $alias,
]);

throw new ValidatorException($translatedMessage);
}

/**
* Add a new rule to the mapping.
*
* @param string $alias Rule alias.
* @param string $className Rule class name.
* @return void
*/
public static function addRule(string $alias, string $className): void
{
self::$rules[$alias] = $className;
Expand Down

0 comments on commit 2b00484

Please sign in to comment.