Skip to content

Commit b0bc39f

Browse files
committed
Initial commit: Implement lemmon/validator package with quality tools and documentation.
0 parents  commit b0bc39f

20 files changed

Lines changed: 5779 additions & 0 deletions

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Validate composer.json and composer.lock
17+
run: composer validate --strict
18+
19+
- name: Cache Composer packages
20+
id: composer-cache
21+
uses: actions/cache@v3
22+
with:
23+
path: vendor
24+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
25+
restore-keys: |
26+
${{ runner.os }}-php-
27+
28+
- name: Install dependencies
29+
run: composer install --prefer-dist --no-progress
30+
31+
- name: Run test suite
32+
run: vendor/bin/pest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests');
6+
7+
$config = new PhpCsFixer\Config();
8+
return $config->setRules([
9+
'@PSR12' => true,
10+
'strict_param' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
])
13+
->setFinder($finder);

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [Unreleased]
6+
7+
### Added
8+
9+
- Initial release of the `lemmon/validator` package.

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing
2+
3+
Contributions are welcome! Please feel free to submit a pull request.
4+
5+
## Development
6+
7+
To get started, you will need to have PHP 8.4+ and Composer installed.
8+
9+
1. Fork the repository and clone it to your local machine.
10+
2. Install the dependencies:
11+
12+
```bash
13+
composer install
14+
```
15+
16+
3. Run the tests:
17+
18+
```bash
19+
composer test
20+
```
21+
22+
## Pull Requests
23+
24+
- Please ensure that the tests are passing before submitting a pull request.
25+
- Please follow the existing code style.
26+
- Please add a clear description of the changes you have made.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Jakub Pelák
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Lemmon Validator
2+
3+
[![CI](https://github.com/lemmon/validator-php/actions/workflows/ci.yml/badge.svg)](https://github.com/lemmon/validator-php/actions/workflows/ci.yml)
4+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5+
6+
A lightweight, fluent validation library for PHP, inspired by Valibot and Zod.
7+
8+
## Usage
9+
10+
```php
11+
use Lemmon\Validator;
12+
13+
$schema = Validator::isArray([
14+
'required' => Validator::isString()->required(),
15+
'optional' => Validator::isString(),
16+
'forced' => Validator::isString()->default('Hello!'),
17+
'level' => Validator::isInt()->coerce()->oneOf([3, 5, 8])->default(3),
18+
'override' => Validator::isBool()->coerce()->default(false),
19+
])->coerceAll();
20+
21+
$input = [
22+
'required' => 'test',
23+
'level' => '5',
24+
];
25+
26+
// throws ValidationException on error
27+
$data = $schema->validate($input);
28+
29+
// or
30+
[$valid, $data, $errors] = $schema->tryValidate($input);
31+
```

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "lemmon/validator",
3+
"description": "A lightweight, fluent validation library for PHP.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Jakub Pelák",
9+
"email": "jpelak@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.4"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"Lemmon\\": "src/Lemmon/"
18+
}
19+
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"Lemmon\\Tests\\": "tests/"
23+
}
24+
},
25+
"require-dev": {
26+
"pestphp/pest": "^2.0",
27+
"friendsofphp/php-cs-fixer": "^3.84",
28+
"phpstan/phpstan": "^2.1"
29+
},
30+
"config": {
31+
"allow-plugins": {
32+
"pestphp/pest-plugin": true
33+
}
34+
},
35+
"scripts": {
36+
"test": "vendor/bin/pest",
37+
"lint": "php-cs-fixer fix --dry-run --diff --allow-risky=yes",
38+
"fix": "php-cs-fixer fix --allow-risky=yes",
39+
"analyse": "phpstan analyse"
40+
}
41+
}

0 commit comments

Comments
 (0)