Download the PHP package klimick/decode without Composer

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

Decode

psalm level psalm type coverage phpunit coverage

This library allow you to take untrusted data and check that it can be represented as type T.

Usage example

Builtin type atomics

mixed()

Represents value of any possible type.

null()

Represents type for null value. Suitable for nullable types.

int()

Represents integer number.

positiveInt()

Represents positive integer number.

float()

Represents number with floating point.

numeric()

Represents either integer or float numbers.

numericString()

Like numeric() but represents also string numbers.

bool()

Represents boolean value.

string()

Represents string value.

nonEmptyString()

Represents string that cannot be empty.

scalar()

Any scalar value.

arrKey()

Represents array key (int | string)

datetime()

Represents decoder that can create DateTimeImmutable from string. It uses the constructor of DateTimeImmutable by default.

You can specify a format, and then the decoder will be use DateTimeImmutable::createFromFormat:

It uses UTC timezone by default. You can pass different time zone during decoder instantiation:

Generic types

union(T1, T2, T3)

Represents type whose value will be of a single type out of multiple types.

arrayOf(TK, TV)

Represents array with keys of type TK and values of type TV.

nonEmptyArrayOf(TK, TV)

Represents non-empty-array with keys of type TK and values of type TV.

listOf(TV)

Represents list with values of type TV.

nonEmptyListOf(TV)

Represents non-empty-list with values of type TV.

shape(prop1: T, prop2: T, propN: T)

Represents array with knows keys.

partialShape(prop1: T, prop2: T, propN: T)

Like shape represents array with knows keys, but each key is possibly undefined.

intersection(T1, T2, T3)

Decoder that allows to combine multiple shape or partialShape into the one.

tuple(T1, T2, T3)

Represents array that indexed from zero with fixed items count.

object(SomeClass::class)(prop1: T1, prop2: T2, propN: TN)

Allows to create decoder for existed class. For each parameter of the constructor, you must explicitly specify a corresponding decoder.

partialObject(SomeClass::class)(prop1: T1, prop2: T2, propN: T3)

Like object decoder, but each parameter of the constructor must be nullable.

rec(fn() => T)

Represents recursive type. Only objects can be recursive.

fromJson(T)

Combinator for decoder of type T which will be parsed from json representation.

Higher order helpers

optional

Allows you to mark property as possibly undefined.

default

Allows you to define a fallback value if an untrusted source does not present one.

constrained

All decoders additionally can be constrained.

List of builtin constraints

from

Helper method from is defined for each decoder. It allows you to specify a path for a result property or rename one.

The $ sign means root of object. You can use just $ when you want to change decoded structure nesting:

Constraints

Constraints can be attached to decoder with the constrained higher order helper.

equal (all types)

Checks that a numeric value is equal to the given one.

greater (int, float, numeric)

Checks that a numeric value is greater than the given one.

greaterOrEqual (int, float, numeric)

Checks that a numeric value is greater or equal to the given one.

less (int, float, numeric)

Checks that a numeric value is less than the given one.

lessOrEqual (int, float, numeric)

Checks that a numeric value is less or equal to the given one.

inRange (int, float, numeric)

Checks that a numeric value is in the given range

minLength (string, non-empty-string)

Checks that a string value size is not less than given one.

maxLength (string, non-empty-string)

Checks that a string value size is not greater than given one.

startsWith (string, non-empty-string)

Checks that a string value starts with the given value.

endsWith (string, non-empty-string)

Checks that a string value ends with the given value.

uuid (string, non-empty-string)

Checks that a string value is a valid UUID.

trimmed (string, non-empty-string)

Checks that a string value has no leading or trailing whitespace.

matchesRegex (string, non-empty-string)

Checks that a string value matches the given regular expression.

forall (array<array-key, T>)

Checks that the given constraint holds for all elements of an array value.

exists (array<array-key, T>)

Checks that the given constraint holds for some elements of an array value.

inCollection (array<array-key, T>)

Checks that an array value contains a value equal to the given one.

maxSize (array<array-key, T>)

Checks that an array value size is not greater than the given one.

`

minSize (array<array-key, T>)

Checks that an array value size is not less than the given one.

`

allOf (any type)

Conjunction of all constraints.

anyOf (any type)

Disjunction of all constraints.


All versions of decode with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
whsv26/functional Version ^2.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 klimick/decode contains the following files

Loading the files please wait ....