Skip to content

Implies that the package is intelligent and adaptive in its validation approach.

Notifications You must be signed in to change notification settings

geekGroveOfficial/php-smart-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

To incorporate the supported validation rules into your README for the php-smart-validator package, I suggest adding a dedicated section that clearly outlines all the available validation rules. This will help users understand the capabilities of your package right away.

Here's an updated version of your README with the supported validation rules included:


PHP Smart Validator

php-smart-validator is a flexible and extensible PHP package for validating data. It provides a set of common validation rules and allows for custom rule definitions. This package is designed to be easy to use and integrate into any PHP project.

Features

  • Supports common validation rules like required
  • Easy to extend with new validation rules
  • PSR-4 autoloading for seamless integration

Installation

You can install the package via Composer. Run the following command in your terminal:

composer require GeekGroveOfficial/php-smart-validator

Supported Validation Rules

The following validation rules are supported out of the box:

  • required: Ensures the field is present and not empty.
  • min: Ensures the field value is at least a certain length or size.
  • max: Ensures the field value does not exceed a certain length or size.
  • string: Ensures the field value is a string.
  • integer or int: Ensures the field value is an integer.
  • boolean or bool: Ensures the field value is a boolean.
  • email: Ensures the field value is a valid email address.
  • date: Ensures the field value is a valid date.
  • array: Ensures the field value is an array.
  • in: Ensures the field value is within a specified set of values.
  • url: Ensures the field value is a valid URL.
  • ip: Ensures the field value is a valid IP address.
  • json: Ensures the field value is a valid JSON string.
  • regex: Ensures the field value matches a specified regular expression pattern.
  • uuid: Ensures the field value is a valid UUID.
  • image: Ensures the field value is a valid image file.
  • files: Ensures the field value is valid files according to specified rules.

Basic Usage

Setting Up

First, create a validation instance by passing the data and rules:

use GeekGroveOfficial\PhpSmartValidator\Validator\Validator;

$data = [
    'email' => '[email protected]',
    'password' => 'secret'
];

$rules = [
    'email' => ['required','email'],
    'password' => ['required','min:6']
];

$validator = new Validator($data, $rules);

if ($validator->validate()) {
    echo "Validation passed!";
} else {
    print_r($validator->errors());
}

Running Tests

To ensure everything is working correctly, you can run the tests using PHPUnit. First, install PHPUnit if you haven't already:

composer require --dev phpunit/phpunit

Then run the tests:

./vendor/bin/phpunit

Contributing

Contributions are welcome! If you have suggestions, improvements, or bug fixes, please follow these steps:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

Please ensure that your code adheres to the existing style and includes appropriate tests.

License

About

Implies that the package is intelligent and adaptive in its validation approach.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages