Download the PHP package philiprehberger/php-schema-validator without Composer

On this page you can find all versions of the php package philiprehberger/php-schema-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 php-schema-validator

PHP Schema Validator

Tests Latest Version on Packagist Last updated

Fluent data schema validator with nested objects, arrays, and dot-notation errors.

Requirements

Installation

Usage

Nested Objects

Typed Arrays

Optional and Nullable Fields

String Validators

Enum Values

Any Value

Custom Validation Rules

Add custom validation logic to any schema type using custom(). The callable receives the value and returns null if valid, or an error message string if invalid.

Custom validators only run when all built-in checks pass.

Value Transformers

Use transform() to normalize a value before validation. The callable receives the raw value and returns the transformed value.

Transformers run before any type or constraint checks (but after the null check).

Cross-Field Validation

Use crossField() on an ObjectSchema to validate relationships between fields. Each callable receives the full data array and returns null if valid, or an error message string.

Cross-field validators only run when all individual field validations pass.

Conditional Fields

Use when() on an ObjectSchema to conditionally require additional fields based on the value of another field.

Schema Composition

Use extend() to create a new schema that combines the fields of the current schema with additional fields.

Custom Error Messages

Use withMessages() on a ValidationResult to replace default error messages for specific fields.

API

Schema (static factory)

Method Returns Description
Schema::object(array $fields) ObjectSchema Create an object schema with field definitions
Schema::string() StringSchema Create a string schema
Schema::int() IntSchema Create an integer schema
Schema::float() FloatSchema Create a float schema
Schema::bool() BoolSchema Create a boolean schema
Schema::arrayOf(SchemaType $item) ArraySchema Create a typed array schema
Schema::enum(array $values) EnumSchema Create an enum schema
Schema::any() AnySchema Create a schema that accepts any value

ValidationResult

Method Returns Description
passes() bool True if validation passed
fails() bool True if validation failed
errors() array<string> All error messages
firstError() ?string First error message or null
withMessages(array $messages) ValidationResult Replace errors for matching field paths with custom messages

ObjectSchema extras

Method Description
crossField(callable $validator) Add a cross-field validator (receives full data array, returns ?string)
when(string $field, mixed $value, array $thenSchema) Conditionally validate additional fields when a field matches a value
extend(array $additionalFields) Create a new schema combining current fields with additional fields

Common Modifiers

All schema types support:

Method Description
optional() Field may be absent from the parent object
nullable() Field may be null
custom(callable $validator) Add a custom validation callback (receives value, returns ?string)
transform(callable $transformer) Transform the value before validation

Development

Support

If you find this project useful:

⭐ Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of php-schema-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 philiprehberger/php-schema-validator contains the following files

Loading the files please wait ...