Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Feb 14, 2025
1 parent 26974bc commit 9355d29
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@ A Parameter is an object implementing `ParameterInterface`. Every Parameter can

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.

```php
// Base generic methods
public function withDescription(string $description): self;
public function withIsSensitive(bool $isSensitive = true): self;
```

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

```php
use function Chevere\Parameter\int;

$int = int(min: 0, max: 100);
// Same as:
$int = int()->withMin(0)->withMax(100);
```

Methods unique to each parameter:

* IntParameter: `withMin`, `withMax`, `withAccept`, `withReject`
* FloatParameter: `withMin`, `withMax`, `withAccept`, `withReject`
* StringParameter: `withRegex`
* ArrayParameter: `withRequired`, `withOptional`, `withModify`, `withMakeOptional`, `withMakeRequired`, `without`, `withOptionalMinimum`
* ObjectParameter: `withClassName`
* IterableParameter: `withKey`, `withValue`

### Invoke a Parameter

When invoking a Parameter `$param($arg)` or `$param->__invoke($arg)` it will trigger validation against the passed argument. This method will fill-in any missing optional parameters with their default values. It will also exclude any extra unexpected parameters.

## String
Expand Down

0 comments on commit 9355d29

Please sign in to comment.