https://github.com/eghojansu/bumbon-validation
PHP Validation
https://github.com/eghojansu/bumbon-validation
Last synced: 2 months ago
JSON representation
PHP Validation
- Host: GitHub
- URL: https://github.com/eghojansu/bumbon-validation
- Owner: eghojansu
- License: mit
- Created: 2017-11-24T03:34:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-24T03:45:16.000Z (over 7 years ago)
- Last Synced: 2025-03-16T06:19:24.937Z (3 months ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bumbon/Validation
PHP Validation.
## Installation
```
composer require bumbon/validation
```## Usage
```php
NotBlank(),
'baz' => [
new NotBlank(),
new Length([
'min' => 5,
])
],
],
[
'foo' => 'bar',
'baz' => 'qux'
]
);
$violation = $validation->validate();// or
// $validation->validate(['foo' => 'bar','baz' => 'qux']);if ($violation->hasViolation()) {
echo 'Invalid data';
} else {
echo 'Data valid';
}// or
if ($violation->noViolation()) {
echo 'Data valid';
} else {
echo 'Invalid data';
}// get violation message
var_dump($violation->all());// [
// 'foo' => ['Nilai ini tidak boleh kosong']
// ]```
## Available Constraints
All option can be passed in each constraint via associative array.
All constraint has parent option. Default message is Bahasa Indonesia.```php
'Custom message',
// group validate
'groups' => ['Default'],
// trim value
'trim' => true,
// callback for normalize data (before validate)
'normalizer' => null,
];
```- Between
```php
5,
'max' => 5,
];
```
- Blank
- Boolean
- Callback```php
null,
];
```
- Choice```php
[],
];
```
- Equal```php
null,
];
```
- GreaterThanEqual```php
null,
];
```
- GreaterThan```php
null,
];
```
- Identical```php
null,
];
```
- InTable```php
null,
// table to lookup
'table' => null,
// field to find
'field' => 'ID',
];
```
- Ip
- IsFalse
- IsTrue
- Length```php
5,
'max' => 5,
];
```
- LessThanEqual```php
null,
];
```
- LessThan```php
null,
];
```
- NotBlank
- NotEqual```php
null,
];
```
- NotIdentical```php
null,
];
```
- NotInTable```php
null,
// table to lookup
'table' => null,
// field to find
'field' => 'ID',
// primary key, can be array
'id' => 'ID',
// current primary key value, can be array
'current_id' => null,
];
```
- Numeric
- PhoneNumber
- Regex```php
null,
];
```
- Url## Custom Constraints
Implements Constraint Interface.
```php
valid = $this->value == 'true';return $this;
}
}
```## Inspiration
This library was inspired by Symfony/Validation. I created this for my own project.