Download the PHP package guide42/plan without Composer

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

Plan

Plan is a data validation library for PHP. It's planed to be used for validating data from external sources.

It has two core design goals:

  1. Simple: use language own features: construct schema from literals and function composition, errors are exceptions;
  2. Lightweight: lots of validations included without 3rd party libraries;

Usage

Simplest way would be requiring guide42/plan with composer.

Concepts

Defining schemas is the first step to validate an input data. An schema is a tree of validators that can be manually defined or created based on literals and arrays.

With the schema defined, a plan must be make to validate data. This is made through the \plan\Schema class. This object, when called like a function, will validate the data and return the modified (or not) data. If any error occurs and exception will be thrown.

Schema information will be always be trusted, therefore will not be validate. Contrary input data will be never be trusted.

Literals

Scalars are treated as literals that are matched using the identity operator.

As any plan validator it throws an \plan\Invalid when fails.

Arrays

Plan will distinguish between indexed and associative arrays. If an array has all indexes numeric and sequential will be considerer a sequence. If not will be considerer a dictionary.

Sequences

A sequence will be treated as a list of possible valid values. Will require that the input data is sequence that contains one or more elements of the schema. Elements can be repeated.

An array of possible values:

An empty array will be a sequence that accept any value.

Dictionaries

A dictionary will be used to validate structures. Each key in data will be checked with the validator of the same key in the schema.

Validators

All core validators live in \plan\assert namespace.

literal

See Literals.

type

Will validate the type of data. The data type will be not casted.

Aliases of this validator are: bool, int, float, str.

scalar

Wrapper around is_scalar function.

instance

Wrapper around instanceof type operator.

iterable

Given data must be an array or implement Iterable interface.

required

Rejected values are null and ''.

optional

Accepts null and empty string without calling the given schema.

seq

See Sequences.

This is normally accepted as "a list of something (or something else)".

dict

See Dictionaries.

Elements of the dictionary not found in data will be called with null; any additional data key will throw an exception.

The validator dict accept two more parameters to change this behavior.

Both parameters (required and extra) could be arrays, so only the given keys will be taken in account.

If the extra parameter is a dictionary it will be compiled and treat it as a validator for each extra key.

There is no way of treat all items with the same validator. Nor having a default validator for extra keys.

keys

Is also possible to validate and/or filter the list of keys of a dictionary.

object

The structure of an object can also be validated.

any

Accept any of the given list of validators, as a valid value.

This is useful when you only need one choice a of set of values. If you need any quantity of choices use a sequence instead.

all

Require all validators to be valid.

not

Negative the given validator.

iif

Simple conditional.

length

The given data length is between some minimum and maximum value. This works with strings using strlen or count for everything else.

validate

A wrapper for validate filters using filter_var.

It accepts the name of the filter.

Aliases are: url, email, ip. And the "like-type": boolval, intval, floatval. Note that this will check that a string resemble to a boolean/int/float; for checking if the input data IS a boolean/int/float use the type validator. None of this will modify the input data.

datetime

Validates if given datetime in string can be parsed by given format.

match

Value must be a string that matches the regular expression.

Filters

The input data can also be filtered, and the validation will return the modified data. By convention is called validator when it will not modified the input data; and filter when modification to the data are performed.

Core filters will be found in the \plan\filter namespace.

type

Will cast the data into the given type.

Note that boolval, strval, intval, floatval are not aliases of this filter but wrappers of the homonymous functions.

sanitize

Sanitization filters.

Aliases are: url, email.

datetime

Will parse a datetime formated string into a \DateTimeImmutable object.

String Filters

All string transformations fall under the \plan\filter\str namespace.

nullempty

Change empty strings into nulls.

strip

Wrapper of trim function.

Internationalization

This library supports some filters to be language dependant. Before using any of them make sure that the correct locale is set (ex. by using setlocale).

chars

Will keep only characters in the current language and numbers. Optionally white-space could be keeped too.

Aliases are: alpha, alnum.

Writing Validators

A simple callable can be a validator.

Any validation error is thrown with the Invalid exception. If several errors must be reported, MultipleInvalid is an exception that could contain multiple exceptions. All other exceptions are considerer as errors in the validator.

Acknowledgments

This library is heavily inspired in Voluptuous by Alec Thomas.

Badges

Build Status Total Downloads Coverage Status


All versions of plan with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 guide42/plan contains the following files

Loading the files please wait ....