# Overview

### Meet SimpleValidator

SimpleValidator is a lightweight and flexible data validation library for PHP.

It allows validating complex data structures, such as nested arrays, JSON APIs, and forms, using an expressive fluent syntax or string-based definitions.

Whether building a simple contact form or validating complex API payloads with nested objects and arrays, SimpleValidator provides powerful tools to ensure your data meets your application's requirements.

#### Why SimpleValidator?

There are several reasons why SimpleValidator might be the right choice for your project:

**Expressive Syntax**

SimpleValidator lets you define validation rules clearly and readably.

You can use the fluent API with method chaining or an easy-to-store and configure string-based syntax:

{% code title="Example (fluent vs string)" %}

```php
// Fluent Syntax
_String::new()->min(3)->max(100)->required()

// String Syntax
'type: string | min: 3 | max: 100 | required'
```

{% endcode %}

**Nested Data Structures**

Unlike many validation libraries, SimpleValidator was built from the ground up to handle nested data.

It provides three powerful structures: `Struct`, `Slice`, and `Map` that can be combined to validate any data format.

{% code title="Validation with Struct, Slice, and Map" %}

```php
use Lucasjs7\SimpleValidator\{Struct, Slice, Map};
use Lucasjs7\SimpleValidator\Type\{_String, _Int};

$validator = Struct::new([
    // Struct: Nested object
    'user' => Struct::new([
        'name' => _String::new()->required(),
    ]),

    // Slice: List of strings
    'tags' => Slice::new(
        _String::new()->min(3)
    ),

    // Map: Dynamic keys
    'settings' => Map::new(
        _String::new(), // Key (string)
        _Int::new()     // Value (int)
    ),
]);
```

{% endcode %}

**Reflection Coverage**

SimpleValidator can automatically create validators from your existing PHP classes using Reflection.

No need to duplicate your validation rules - just annotate constructor parameters or properties.

{% code title="Generating validator with StructParser" %}

```php
use Lucasjs7\SimpleValidator\StructParser;

class UserDTO {
    public function __construct(
        public string $name,
        public string $email,
    ) {
        // ...
    }
}

$validator = StructParser::new(UserDTO::class);
```

{% endcode %}

### Next Steps

Now that you've installed SimpleValidator, you might want to learn more about:

* [**Quick Start**](/simplevalidator/getting-started/quickstart.md) - Learn the basics with complete examples
* [**Data Structures**](/simplevalidator/base/structures.md) - Understand Struct, Slice, and Map
* [**Available Types**](/simplevalidator/base/types.md) - Explore all validation types
* [**Available Rules**](/simplevalidator/base/rules.md) - Learn about rules like min, max, regex

### License

SimpleValidator is open-source software licensed under the MIT license.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ljs.gitbook.io/simplevalidator/introduction/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
