docs: Improve documentation and translate comments to English

This commit is contained in:
kj
2025-10-10 21:18:22 -03:00
parent 674c9d5ff4
commit 7f62e06ff9
8 changed files with 369 additions and 307 deletions

View File

@@ -7,43 +7,48 @@ use Exception;
/**
* Validator - DuckBrain
*
* Libería complementaria de la libería Request.
* Sirve para simplpificar la verificación de valores.
* Complementary library to the Request library.
* Simplifies value verification.
*
* Tiene la posibilida de verificar tanto reglas individuales como en lote.
* It has the ability to verify both individual rules and in batches.
*
* |----------+--------------------------------------------------------|
* | Regla | Descripción |
* | Rule | Description |
* |----------+--------------------------------------------------------|
* | not | Niega la siguiente regla. Ej: not:float |
* | exists | Es requerido; debe estar definido y puede estar vacío |
* | required | Es requerido; debe estar definido y no vacío |
* | number | Es numérico |
* | int | Es entero |
* | float | Es un float |
* | bool | Es booleano |
* | email | Es un correo |
* | enum | Esta en un lista ve valores. Ej: enum:admin,user,guest |
* | url | Es una url válida |
* | not | Negates the next rule. Ex: not:float |
* | exists | Is required; must be defined and can be empty |
* | required | Is required; must be defined and not empty |
* | number | Is numeric |
* | int | Is an integer |
* | float | Is a float |
* | bool | Is a boolean |
* | email | Is an email |
* | enum | Is in a list of values. Ex: enum:admin,user,guest |
* | url | Is a valid URL |
* |----------+--------------------------------------------------------|
*
* Las listas de reglas están separadas por |, Ej: required|email
* Rule lists are separated by |, e.g., required|email
*
* @author KJ
* @website https://kj2.me
* @licence MIT
* @license MIT
*/
class Validator
{
/**
* Stores the last failed rule.
*
* @var string
*/
public static string $lastFailed = '';
/**
* Validar lista de reglas sobre las propiedades de un objeto.
* Validates a list of rules against the properties of an object.
*
* @param array $rulesList Lista de reglas.
* @param Neuron $haystack Objeto al que se le verificarán las reglas.
* @param array $rulesList The list of rules.
* @param Neuron $haystack The object whose properties will be validated.
*
* @return bool Retorna true solo si todas las reglas se cumplen y false en cuanto una falle.
* @return bool Returns true only if all rules are met, and false as soon as one fails.
*/
public static function validateList(array $rulesList, Neuron $haystack): bool
{
@@ -62,12 +67,13 @@ class Validator
}
/**
* Revisa si una regla se cumple.
* Checks if a rule is met.
*
* @param mixed $subject Lo que se va a verfificar.
* @param string $rule La regla a probar.
* @param mixed $subject The value to verify.
* @param string $rule The rule to test.
*
* @return bool
* @throws Exception If the rule is not callable.
*/
public static function checkRule(mixed $subject, string $rule): bool
{
@@ -83,10 +89,10 @@ class Validator
}
/**
* Verifica la regla de manera negativa.
* Verifies the rule in a negative way.
*
* @param mixed $subject Lo que se va a verfificar.
* @param mixed $rule La regla a probar.
* @param mixed $subject The value to verify.
* @param mixed $rule The rule to test.
*
* @return bool
*/
@@ -96,9 +102,9 @@ class Validator
}
/**
* Comprueba que que esté definido/exista.
* Checks if the value is defined/exists.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -108,9 +114,9 @@ class Validator
}
/**
* Comprueba que que esté definido y no esté vacío.
* Checks if the value is defined and not empty.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -120,9 +126,9 @@ class Validator
}
/**
* number
* Checks if the value is numeric.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -132,9 +138,9 @@ class Validator
}
/**
* int
* Checks if the value is an integer.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -144,9 +150,9 @@ class Validator
}
/**
* float
* Checks if the value is a float.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -156,9 +162,9 @@ class Validator
}
/**
* bool
* Checks if the value is a boolean.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -168,9 +174,9 @@ class Validator
}
/**
* email
* Checks if the value is a valid email address.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -180,9 +186,9 @@ class Validator
}
/**
* url
* Checks if the value is a valid URL.
*
* @param mixed $subject
* @param mixed $subject The value to check.
*
* @return bool
*/
@@ -192,10 +198,10 @@ class Validator
}
/**
* enum
* Checks if the value is present in a list of allowed values.
*
* @param mixed $subject
* @param mixed $values
* @param mixed $subject The value to check.
* @param mixed ...$values A variable number of allowed values.
*
* @return bool
*/