Download the PHP package chevere/parameter without Composer

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

Parameter

Build Code size PHPStan Mutation testing badge

Quality Gate Status Maintainability Rating Reliability Rating Security Rating Coverage Technical Debt CodeFactor

Summary

Parameter is a library around parameter-argument which provides additional functionality with validation rules and schema introspection.

Installing

Parameter is available through Packagist and the repository source is at chevere/parameter.

What it does?

Parameter enables to spawn dynamic parameters of any type with extra rules.

For example, an integer of minimum value 10.

In function or method parameters you can use attributes to define validation rules for parameters and return value.

Validation can be triggered using validated (example above), delegated to a caller wrapper. Parameter provides helpers to access rules for both parameters and return value to ease wiring process.

Rules defined by each parameter provide a human-readable schema which allows to expose the validation criteria.

How to use

Parameter provides an API which can be used to create parameters using functions and/or attributes. Parameter objects can be used directly in the logic while attributes requires a read step.

Inline usage

Use inline validation to go from this:

To this:

Attribute-based usage

Use attributes to define rules for parameters and return value.

Use attribute delegated validation with the validated() function to go from this:

To this:

Use reflectionToParameters and reflectionToReturn functions for manual validation for arguments and return value:

Use attribute inline validation for manual validation within the function body:

CallableAttr

Attributes in PHP only support expressions you can use on class constants. Is not possible to directly define dynamic parameters using attributes.

To avoid this limitation you can use CallableAttr attribute which enables to forward parameter resolution to a callable returning a ParameterInterface instance.

Types

A Parameter is an object implementing ParameterInterface. Every Parameter can define a description and a default value, plus additional validation rules depending on the type.

A Parameter can be defined using functions and/or attributes, it takes same arguments for both.

When invoking a Parameter $param('value') it will trigger validation against the passed argument.

String

Use function string to create a StringParameter. Pass a regex for string matching.

Use StringAttr attribute to define a string parameter.

String pseudo-parameters

The following parameters are based on String.

Enum string

Use function enum to create a StringParameter matching a list of strings.

Use EnumAttr attribute to define an enum string parameter.

Int string

Use function intString to create a StringParameter matching a string integers.

Bool string

Use function boolString to create a StringParameter matching 0 and 1 strings.

Date string

Use function date to create a StringParameter matching YYYY-MM-DD strings.

Time string

Use function time to create a StringParameter matching hh:mm:ss strings.

Datetime string

Use function datetime to create a StringParameter matching YYYY-MM-DD hh:mm:ss strings.

Int

Use function int to create a IntParameter. Pass min and max values for integer range, accept for a list of accepted integers and reject for a list of rejected integers.

Use IntAttr attribute to define an integer parameter.

Int pseudo-parameters

The following parameters are based on Int.

Bool int

Use function boolInt to create a IntParameter matching 0 and 1 integers.

Float

Use function float to create a FloatParameter. Pass min and max values for float range, accept for a list of accepted floats and reject for a list of rejected floats.

Use FloatAttr attribute to define a float parameter.

Bool

Use function bool to create a BoolParameter.

Use BoolAttr attribute to define a bool parameter.

Null

Use function null to create a NullParameter.

Use NullAttr attribute to define a null parameter.

Object

Use function object to create a ObjectParameter. Pass a className for the object class name.

Use ObjectAttr attribute to define an object parameter.

Mixed

Use function mixed to create a MixedParameter.

Union

Use function union to create a UnionParameter. Pass a list of parameters to match, target value must match at least one.

Array

Parameter for type array is handled as a composite Parameter holding parameter definition for each one of its members.

Use function arrayp to create an ArrayParameter for named arguments as required array keys.

Parameter supports nested arrays of any depth:

Use ArrayAttr attribute to define an array parameter.

With required

use method withRequired to define required parameters.

With optional

use method withOptional to define optional parameters.

👉 Note: Optional parameters will be validated only if a matching key is provided.

With modify

use method withModify to define modify parameters.

With make optional

use method withMakeOptional to make required parameters optional.

With make required

use method withMakeRequired to make optional parameters required.

Without

use method without to remove parameters.

With optional minimum

use method withOptionalMinimum to define a minimum number of optional parameters. Useful if all parameters are optional but 1.

Array pseudo-parameters

The following parameters are based on Array.

Array String

Use function arrayString to create an ArrayStringParameterInterface for string values. It only supports string parameters.

File

Use function file to create an ArrayParameter for file uploads.

By default it provides validation for $_FILES shape, but you can define your own validation rules. For example, to validate name and contents:

Iterable

Iterable type Traversable|array is considered as a composite Parameter holding a generic definition for key and value. Parameter enables to describe this collection of items sharing the same shape.

Use function iterable to create an IterableParameter. Pass a V and K parameters for generic key and value.

It also works with named keys:

Helpers

parameters

Use function parameters to create a Parameters instance.

arguments

Use function arguments to create a Arguments instance.

assertNamedArgument

Use function assertNamedArgument to assert a named argument.

toParameter

Use function toParameter to create a ParameterInterface instance from a type string. In the example below the resulting $parameter will be an IntParameter.

arrayFrom

Use function arrayFrom to create an Array parameter from another array parameter. In the example below the resulting $array will contain only name and id keys as defined in $source.

takeKeys

Use function takeKeys to retrieve an array with the keys from a parameter. In the example below $keys will contain id and size.

takeFrom

Use function takeFrom to retrieve an iterator with the desired keys from a parameter. In the example below $iterator will yield size and name keys.

parametersFrom

Use function parametersFrom to create a Parameters with desired keys from a parameter. In the example below $parameters will contain size and name keys.

getParameters

Use function getParameters to retrieve a Parameters instance from an object implementing either ParameterAccessInterface or ParametersInterface.

getType

Use function getType to retrieve the type as is known by this library.

parameterAttr

Use function parameterAttr to retrieve an object implementing ParameterAttributeInterface from a function or class method parameter.

reflectionToParameters

Use function reflectionToParameters to retrieve a Parameters instance from a ReflectionFunction or ReflectionMethod instance.

reflectionToReturn

Use function reflectionToReturn to retrieve a ParameterInterface instance from a ReflectionFunction or ReflectionMethod instance.

reflectedParameterAttribute

Use function reflectedParameterAttribute to retrieve an object implementing ParameterAttributeInterface from a ReflectionParameter instance.

validated

Use function validated to validate a function or method arguments.

Examples

Inline validation

Attribute delegated validation

Attribute inline validation

Use valid() on the function/method body to trigger validation for arguments.

Use function returnAttr() on the function/method body.

💡 By convention when omitting ReturnAttr the method public static function return(): ParameterInterface (if any) will be used to determine return validation rules.

Documentation

Documentation is available at chevere.org.

License

Copyright Rodolfo Berrios A.

Chevere is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


All versions of parameter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
chevere/data-structure Version ^1.0.1
chevere/message Version ^1.0.0
chevere/regex Version ^1.0.1
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 chevere/parameter contains the following files

Loading the files please wait ....