Download the PHP package squirrelphp/validator-cascade without Composer

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

Squirrel Validator Cascade

Build Status Test Coverage PHPStan Packagist Version PHP Version

Reimplements the Valid constraint in the Symfony validator component as Cascade attribute which is more straightforward to use than Valid and has no surprising behavior.

This component is compatible with the Symfony validator component in version 5.x (v2.x with annotation/attribute support) and 6.x/7.x (v3.x with only attribute support) and will be adapted to support future versions of Symfony (if any changes are necessary for that).

Installation

composer require squirrelphp/validator-cascade

Table of contents

Usage

Cascade is a constraint validation which makes sure an object or an array of objects are validated by the Symfony validator component, so it cascades validation.

There are only two options:

That is it!

Example

Below is a common example in real applications: You might have an order and multiple possible addresses for the order (one for shipping, one for invoice) with different requirements, and some addresses should be optional, but if they are specified they should still be validated.

$shippingAddress shows how to trigger specific validation groups in the child object, in this case to make the phone number a mandatory part of the information (often the case for shipping, but usually not necessary for other uses) in addition to the "Default" constraints.

$invoiceAddress is only validated if the validation group "alternateInvoiceAddress" is passed to the validator (which could be done if the user selected an option like "choose different invoice address"). The phone number is optional, as we do not pass the trigger option so only the Default group is validated in the Adress object.

Why not use the Valid constraint?

The current implementation of the Valid constraint in the Symfony validator component has severe limitations when it comes to validation groups and behaves differently than any other constraint:

Valid constraint without validation group

The above code looks like a regular assertion, but it behaves differently:

This is fine for simple objects or when you don't need any validation groups at all, but it is still different from any other assertion, as you cannot "skip" this constraint even if you later add validation groups.

Valid constraint with validation group(s)

The Valid assertion above only triggers when you validate the "invoice" validation group, which is what you would expect. Yet there is plenty of unexpected behavior:

Having validation groups both as a trigger and as a filter severly limits how you can use it, and makes most use cases (like our example with addresses) impossible to do with Valid. Even if you manage to make it work, your code will not be self explanatory and it is easy to make mistakes or misunderstand the attributes.

Cascade as defined in this component separates which validation group the constraint belongs to and which validation groups are triggered in the child object(s). What it cannot do is cascade the validation groups of the parent to the child object, as this information is only available in the RecursiveContextualValidator class of the validator component and cannot be accessed without changing a lot of the internals of the validator component (unfortunately).


All versions of validator-cascade with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
symfony/validator Version ^6.0|^7.0
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 squirrelphp/validator-cascade contains the following files

Loading the files please wait ....