Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ vendor
coverage
build
.phpunit.result.cache
.php-cs-fixer.cache
user.env
composer.lock
22 changes: 22 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('dev')
->name('*.php');

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'no_extra_blank_lines' => true,
'no_whitespace_in_blank_line' => true,
'blank_line_before_statement' => ['statements' => ['return']],
])
->setFinder($finder)
->setRiskyAllowed(false);
182 changes: 93 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,40 @@
[![Coverage Status](https://coveralls.io/repos/github/Wixel/GUMP/badge.svg?branch=master)](https://coveralls.io/github/Wixel/GUMP?branch=master)
[![License](https://poser.pugx.org/wixel/gump/license)](https://packagist.org/packages/wixel/gump)

## 🚀 Overview
## Overview

GUMP is a standalone PHP data validation and filtering library that makes validating any data easy and painless without
the reliance on a framework. GUMP has been serving the PHP community since **2013** and is trusted by thousands of
developers worldwide.

### Key Features

- **🔒 Zero Dependencies** - Pure PHP, no external dependencies required
- **🌍 19 Languages** - Built-in internationalization support
- **High Performance** - Lightweight and fast validation processing
- **🔧 Extensible** - Easy to add custom validators and filters
- **📋 76 Validators** - Comprehensive set of validation rules out of the box
- **🛡️ Security Focused** - Built-in XSS protection and data sanitization
- **🎯 Framework Agnostic** - Works with any PHP project or framework
- **📱 Modern PHP** - Supports PHP 7.1 to 8.4+
- **Zero Dependencies** - Pure PHP, no external dependencies required
- **19 Languages** - Built-in internationalization support
- **High Performance** - Lightweight and fast validation processing
- **Extensible** - Easy to add custom validators and filters
- **76 Validators** - Comprehensive set of validation rules out of the box
- **Security Focused** - Built-in XSS protection and data sanitization
- **Framework Agnostic** - Works with any PHP project or framework
- **Modern PHP** - Supports PHP 7.1 to 8.4+

## Table of Contents

- [Installation](#-installation)
- [Requirements](#-requirements)
- [Quick Start](#-quick-start)
- [Usage Examples](#-usage-examples)
- [Available Validators](#-available-validators)
- [Available Filters](#-available-filters)
- [Advanced Usage](#-advanced-usage)
- [Internationalization](#-internationalization)
- [Custom Validators & Filters](#-custom-validators--filters)
- [Configuration](#-configuration)
- [Testing](#-testing)
- [Contributing](#-contributing)
- [Security](#-security)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Installation](#installation)
- [Requirements](#requirements)
- [Quick Start](#quick-start)
- [Usage Examples](#usage-examples)
- [Available Validators](#available-validators)
- [Available Filters](#available-filters)
- [Advanced Usage](#advanced-usage)
- [Internationalization](#internationalization)
- [Custom Validators & Filters](#custom-validators--filters)
- [Configuration](#configuration)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Support](#support)
- [License](#license)

## Installation

Expand All @@ -63,11 +62,11 @@ require_once 'path/to/gump.class.php';

- **PHP**: 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4+
- **Extensions**:
- `ext-mbstring` - Multibyte string support
- `ext-json` - JSON processing
- `ext-intl` - Internationalization functions
- `ext-bcmath` - Arbitrary precision mathematics
- `ext-iconv` - Character encoding conversion
- `ext-mbstring` - Multibyte string support
- `ext-json` - JSON processing
- `ext-intl` - Internationalization functions
- `ext-bcmath` - Arbitrary precision mathematics
- `ext-iconv` - Character encoding conversion

## Quick Start

Expand All @@ -88,11 +87,11 @@ $is_valid = GUMP::is_valid([
]);

if ($is_valid === true) {
echo "All data is valid!";
echo "All data is valid!";
} else {
// Display validation errors
foreach ($is_valid as $error) {
echo " " . $error . "\n";
echo "Error: " . $error . "\n";
}
}
```
Expand Down Expand Up @@ -289,6 +288,7 @@ GUMP provides **76 built-in validators** for comprehensive data validation:
| **camel_case** | Validate camelCase format. |
| **snake_case** | Validate snake_case format. |
| **url_slug** | Validate URL slug format. |

</div>

## Comprehensive Validator Reference
Expand Down Expand Up @@ -446,27 +446,30 @@ $rules = [
];
```

> **💡 Pro Tips**:
> **Pro Tips**:
>
> **Parameter Conflicts**: When using pipe (`|`) or semicolon (`;`) in validator parameters, use array format:
>
> ```php
> // Wrong - will break parsing
> // Wrong - will break parsing
> 'field' => 'regex,/part|of;pattern/'
>
> // Correct - use array format
>
> // Correct - use array format
> 'field' => ['regex' => '/part|of;pattern/']
> ```
>
> **Performance**: Put faster validators first in chains:
>
> ```php
> // Good - required fails fast for empty values
> // Good - required fails fast for empty values
> 'email' => 'required|valid_email|max_len,255'
>
> // Less efficient - validates email format on empty values
>
> // Less efficient - validates email format on empty values
> 'email' => 'valid_email|required|max_len,255'
> ```
>
> **Boolean Values**: The `boolean` filter accepts various formats:
>
> ```php
> // All these become TRUE: '1', 1, 'true', true, 'yes', 'on'
> // All these become FALSE: '0', 0, 'false', false, 'no', 'off', null, ''
Expand Down Expand Up @@ -496,6 +499,7 @@ GUMP includes 16 filters for data sanitization and transformation:
| **upper_case** | Converts to uppercase. |
| **slug** | Converts value to url-web-slugs. |
| **trim** | Remove spaces from the beginning and end of strings. |

</div>

### Filter Chaining Example
Expand All @@ -522,6 +526,42 @@ $filtered = GUMP::filter_input([

## Advanced Usage

### Singleton Pattern

GUMP supports a singleton pattern for cases where you want to reuse the same instance across your application:

```php
// Get the singleton instance
$gump = GUMP::get_instance();

// Subsequent calls return the same instance
$sameGump = GUMP::get_instance();

// Both variables reference the same object
var_dump($gump === $sameGump); // true
```

### Field Helper Method

The `field()` static method provides safe array access with a default fallback:

```php
// Safely get a value from an array with a default
$username = GUMP::field('username', $_POST, 'guest');

// Returns 'guest' if 'username' key doesn't exist
$email = GUMP::field('email', $_POST); // Returns null if not set

// Useful for optional form fields
$data = [
'name' => 'John',
'age' => 25
];

$name = GUMP::field('name', $data); // 'John'
$country = GUMP::field('country', $data, 'US'); // 'US' (default)
```

### Instance Methods

```php
Expand Down Expand Up @@ -750,11 +790,17 @@ We welcome contributions! Please read our [Contributing Guidelines](CONTRIBUTING

### Areas We Need Help With

- 🌍 **Translations** - Help us support more languages
- 🧪 **Test Coverage** - Add more edge case tests
- 📚 **Documentation** - Improve examples and guides
- 🚀 **Performance** - Optimize validation algorithms
- 🛡️ **Security** - Security audits and improvements
- **Translations** - Help us support more languages
- **Test Coverage** - Add more edge case tests
- **Documentation** - Improve examples and guides
- **Performance** - Optimize validation algorithms
- **Security** - Security audits and improvements

### Contributors

<a href="https://github.com/wixel/gump/graphs/contributors">
<img src="https://contrib.rocks/image?repo=wixel/gump" />
</a>

## Security

Expand All @@ -779,51 +825,9 @@ We welcome contributions! Please read our [Contributing Guidelines](CONTRIBUTING

### Community Support

- 🐛 **Bug Reports**: [GitHub Issues](https://github.com/wixel/gump/issues)
- 💡 **Feature Requests**: [GitHub Discussions](https://github.com/wixel/gump/discussions)
- 📚 **Documentation**: [GitHub Wiki](https://github.com/wixel/gump/wiki)

## Statistics

- ⭐ **GitHub Stars**: 1000+
- 📦 **Downloads**: 1M+ via Packagist
- 🏭 **Production Use**: Thousands of projects
- 🌍 **Languages**: 19 supported languages
- ⚡ **Performance**: <1ms validation time for typical forms
- 🧪 **Test Coverage**: 100%

## Why Choose GUMP?

### ✅ Battle-Tested

- **10+ years** in production
- **Trusted** by thousands of developers
- **Proven** in high-traffic applications

### ⚡ Performance First

- **Zero dependencies** - no bloat
- **Optimized algorithms** - fast validation
- **Memory efficient** - low resource usage

### 🔒 Security Focused

- **XSS protection** built-in
- **Regular security audits**
- **Secure defaults** everywhere

### 🌍 Global Ready

- **19 languages** supported
- **UTF-8 compatible**
- **Timezone aware** date validation

### 🛠️ Developer Friendly

- **Clean, simple API**
- **Excellent documentation**
- **Extensive examples**
- **Framework agnostic**
- **Bug Reports**: [GitHub Issues](https://github.com/wixel/gump/issues)
- **Feature Requests**: [GitHub Discussions](https://github.com/wixel/gump/discussions)
- **Documentation**: [GitHub Wiki](https://github.com/wixel/gump/wiki)

## License

Expand Down
31 changes: 17 additions & 14 deletions ci/boot.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

require_once 'vendor/autoload.php';

const README_FILE = 'README.md';

const VALIDATORS_PREFIX = 'validate_';
const FILTERS_PREFIX = 'filter_';

function get_gump_validators() {
$reflect = new ReflectionClass("GUMP");
function get_gump_validators()
{
$reflect = new ReflectionClass('GUMP');

$validators = array_filter($reflect->getMethods(), function($method) {
$validators = array_filter($reflect->getMethods(), function ($method) {
return strpos($method->name, VALIDATORS_PREFIX) !== false;
});

Expand All @@ -22,7 +24,7 @@ function get_gump_validators() {
$ruleExampleParameter = $docblock->getTag('example_parameter');

$item = [
'description' => $ruleDescription
'description' => $ruleDescription,
];

if (!is_null($ruleExampleParameter)) {
Expand All @@ -37,7 +39,8 @@ function get_gump_validators() {
return $result;
}

function get_docs_validators(string $readmePath) {
function get_docs_validators(string $readmePath)
{
$readmeContents = file_get_contents($readmePath);

preg_match_all('/<div id="available_validators">(.*?)<.div>/ms', $readmeContents, $outerMatches);
Expand All @@ -56,19 +59,20 @@ function get_docs_validators(string $readmePath) {

$result[$ruleMatch[1]] = [
'rule' => $rawRule,
'description' => trim($matches[2][$key])
'description' => trim($matches[2][$key]),
];
}

return $result;
}

function get_gump_filters() {
$reflect = new ReflectionClass("GUMP");
function get_gump_filters()
{
$reflect = new ReflectionClass('GUMP');

$methodsToIgnore = ['filter_input', 'filter_rules', 'filter_to_method'];

$filters = array_filter($reflect->getMethods(), function($method) use($methodsToIgnore) {
$filters = array_filter($reflect->getMethods(), function ($method) use ($methodsToIgnore) {
return strpos($method->name, FILTERS_PREFIX) === 0 && !in_array($method->name, $methodsToIgnore);
});

Expand All @@ -81,7 +85,7 @@ function get_gump_filters() {
$ruleExampleParameter = $docblock->getTag('example_parameter');

$item = [
'description' => $ruleDescription
'description' => $ruleDescription,
];

if (!is_null($ruleExampleParameter)) {
Expand All @@ -96,8 +100,8 @@ function get_gump_filters() {
return $result;
}


function get_docs_filters(string $readmePath) {
function get_docs_filters(string $readmePath)
{
$readmeContents = file_get_contents($readmePath);

preg_match_all('/<div id="available_filters">(.*?)<.div>/ms', $readmeContents, $outerMatches);
Expand All @@ -116,10 +120,9 @@ function get_docs_filters(string $readmePath) {

$result[$ruleMatch[1]] = [
'rule' => $rawRule,
'description' => trim($matches[2][$key])
'description' => trim($matches[2][$key]),
];
}

return $result;
}

Loading