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. Go to chevere/action for our object-oriented convention around this package.

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.

Reference

Core types provided by Parameter.

Type Helper Attribute Description
Array arrayp ArrayAttr Array with named parameters
Bool bool BoolAttr Boolean
Float float FloatAttr Floating point number
Int int IntAttr Integer
Iterable iterable IterableAttr Iterable of key-value pairs
Mixed mixed -- Mixed
Null null NullAttr Null
Object object -- Object
String string StringAttr String matching a regex
Union union UnionAttr Union of parameters

Array based-parameters provided.

Type Helper Description
ArrayString arrayString Array with string values
File file File upload

String based-parameters provided.

Type Helper Description
BoolString boolString Bool string
Date date Date string
Datetime datetime Datetime string
Enum enum Enum string
IntString intString Int string
Time time Time string

Int based-parameters provided.

Type Helper Description
BoolInt boolInt Bool int

Non-type attributes provided.

Attribute Description
CallableAttr Forward parameter resolution to a callable
ReturnAttr Return value validation

Inline usage

Inline usage refers to the direct use of functions to create parameters and validate arguments.

Use inline validation to go from this:

To this:

When invoking a Parameter $param($arg) or $param->__invoke($arg) it will trigger validation against the passed argument and return the validated argument:

Attribute usage

Attribute usage refers to the use of attributes to define parameters and return rules. You can use attribute notation for class properties, methods/functions 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:

Native attributes support

Parameter will understand/complement native attribute annotations.

#[SensitiveParameter]

ReturnAttr

Use ReturnAttr attribute to define a return value validation rule.

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, default value, sensitive flag, plus additional validation rules depending on the type.

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

Immutable methods

A Parameter provides immutable methods to re-define its rules. Every with method returns a new instance preserving the original state. This enables to create Parameter variations from a base definition.

Immutable methods of a Parameter can be used to re-define its rules. For example, IntParameter provides additional methods to define integer range:

Methods unique to each parameter:

String

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

Use StringAttr attribute to define a string parameter using attribute notation.

String based-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 using attribute notation.

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 using attribute notation.

Int based-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 using attribute notation.

Bool

Use function bool to create a BoolParameter.

Use BoolAttr attribute to define a bool parameter using attribute notation.

Null

Use function null to create a NullParameter.

Use NullAttr attribute to define a null parameter using attribute notation.

Object

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

Use ObjectAttr attribute to define an object parameter using attribute notation.

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.

Use UnionAttr attribute to define an union parameter using attribute notation.

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 using attribute notation.

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 based-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.1.0
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 ....