Download the PHP package tetthys/commit-validator without Composer

On this page you can find all versions of the php package tetthys/commit-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package commit-validator

tetthys/commit-validator

A fast, framework-agnostic validator designed for commit-time validation of session-aggregated payloads (multi-step forms), using DTOs + PHP Attributes and an optional lightweight DSL for commit-only rules.

This library is intentionally minimal: it validates the final, assembled data right before you “commit” it to your database (or any durable store).


Table of Contents


Why this library exists

Many validators are request-scoped: they validate a single request.
But multi-step forms often work like this:

  1. Step 1 validates and stores partial data (session, cache, temp DB row, etc.)
  2. Step 2 validates and stores more data
  3. Step N stores the last piece
  4. Commit: assemble the final payload and validate it holistically

At commit-time you need constraints like:

tetthys/commit-validator focuses specifically on this commit-time validation problem.


Install

`

Requirements:


Concepts

Commit-time validation

“Commit-time validation” means you validate the final assembled payload, not each partial step in isolation.

This library assumes you already have a mechanism to store intermediate step data and to assemble it into a final array or DTO at commit time.

DTOs and Attributes

You define a DTO (data transfer object) and attach validation rules to its public properties using PHP Attributes:

Paths and error format

Validation errors are keyed by a dot path:

Errors are returned as a map:

This makes it easy to match errors back to nested form inputs and UI components.


Quick Start

1) Define DTO + Attributes

2) Assemble your final payload and create the DTO

3) Validate at commit-time


Recommended: define a local cv() helper (optional)

This package does not ship a global helper function to avoid collisions with user code and other packages.

If you like a short DSL entry point, define your own helper in your application (and autoload it however you prefer):

Then you can write:


Defining DTOs

Basic fields

Available built-in attributes:

Example:

Nested DTOs

Use #[Nested(SomeDTO::class)] to validate a nested object recursively.

If address is present, the validator will validate AddressDTO and produce paths like:

Arrays of DTOs (Each)

Use #[Each(ItemDTO::class)] to validate every element in an array as a DTO.

Errors point to the exact index:

Collection constraints (Count)

Use #[Count(min: X, max: Y)] on arrays to validate the number of items.


Validating

Validating a DTO instance

Adding commit-only rules (DSL overlays)

Attributes define your “always-on” rules.

Sometimes you want stricter commit-time constraints without affecting draft saves. For that, use a DSL overlay:

DSL methods:


Multi-step form workflow (session aggregation pattern)

This library does not manage session storage. It assumes you do.

Step storage

Example (pseudo-code):

Final aggregation

At commit time, you assemble the final structure:

You can normalize it (remove nulls, ensure arrays exist, etc.) before creating DTOs.

Commit validation

Construct DTO(s) from the final array and validate:


Error handling

Displaying errors

A simple rendering loop:

If you JSON-encode the Result, codes become strings:

Mapping paths to form field names (recommended pattern)

Many frontends use bracket-style names:

While validator paths are dot-style:

A common pattern is to keep a mapping function:

Use this to attach errors to specific form controls.


Examples

Example: product.images is required and must have 1..6 items

This is the exact rule: required array, 1..6 items, and each item must be a valid ImageDTO.

Validate:

Example: nested address + items list

Paths:

Example: draft vs commit strictness

Attributes always apply. For draft saves, you may want to accept looser rules and only enforce strict rules at commit.

Recommended pattern:

Overlay example:


Performance notes


API reference

CommitValidator::for(class-string $dtoClass): CommitValidator

Create a validator for a DTO class.

CommitValidator->with(string $property, RuleSet $rules): CommitValidator

Return a cloned validator with extra commit-only rules applied to $property.

CommitValidator->validate(object $dto): Result

Validate a DTO instance (plus any overlays).

Result->isValid(): bool

Returns true when no errors exist.

Result->errors(): array

Returns array<string, list<array{code: ErrorCode, message: string}>>

DSL

The package does not ship a global helper. Define cv() locally (optional):

Then use:


License

MIT


All versions of commit-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tetthys/commit-validator contains the following files

Loading the files please wait ...