Skip to content

Commit 9a6f75d

Browse files
authored
Use name instead of getByValue (#18)
Use name instead of key
1 parent c6700c7 commit 9a6f75d

17 files changed

+258
-258
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use Bakame\Http\StructuredFields\OuterList;
1919
$fieldValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
2020
$container = OuterList::fromRfc9651($fieldValue);
2121
$container[1]->value()->toString(); // returns 'application/xhtml+xml'
22-
$container[1]->parameterByKey(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
22+
$container[1]->parameterByName(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
2323
```
2424

2525
## System Requirements

docs/00-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Bakame\Http\StructuredFields\DataType;
1616
$fieldValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
1717
$container = DataType::List->parse($fieldValue);
1818
$container[1]->value()->toString(); // returns 'application/xhtml+xml'
19-
$container[1]->parameterByKey(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
19+
$container[1]->parameterByName(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
2020
```
2121

2222
## Motivation

docs/02-parsing-serializing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ The following field is an example from the Accept header which is already struct
128128
$fieldValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
129129
$field = DataType::List->parse($fieldValue);
130130
$field[2]->value()->toString(); // returns 'application/xml'
131-
$field[2]->parameterByKey('q'); // returns (float) 0.9
131+
$field[2]->parameterByName('q'); // returns (float) 0.9
132132
$field[0]->value()->toString(); // returns 'text/html'
133-
$field[0]->parameterByKey('q'); // returns null
133+
$field[0]->parameterByName('q'); // returns null
134134
```
135135

136136
- The Accept header is an `List` field made of `Item` only.

docs/04-item.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ They can be accessed by their indices **but also** by their required key attache
6464

6565
$item = Item::fromHttpValue('application/xml;q=0.9;foobar');
6666
$item->value()->toString(); // returns 'application/xhtml+xml'
67-
$item->parameterByKey(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
67+
$item->parameterByName(key: 'q', default: 1.0); // returns 1.0 if the parameter is not defined
6868
$item->parameterByIndex(index: 1, default: ['toto', false]); // returns ['foobar', true] because there's a parameter at index 1
6969
$item->parameters(); // returns a Parameters instance.
7070
```
7171

7272
By default, you can access the member `Item` of a parameters using the following methods:
7373

7474
- `Item::parameters` returns a `Parameters` instance;
75-
- `Item::parameterByKey` returns the value of the bare item instance attached to the supplied `key`;
75+
- `Item::parameterByName` returns the value of the bare item instance attached to the supplied `key`;
7676
- `Item::parameterByIndex` returns the value of the bare item instance attached to the supplied `index`;
7777

7878
It is possible to alter and modify the `Parameters` attached to an `Item` but this section

docs/05-containers.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,39 @@ unset($permissions['a']); // triggers a ForbiddenOperation exception
5757
The `Dictionary` and `Parameters` classes also allow accessing its members as value using their key:
5858

5959
```php
60-
$permissions->hasKey('picture-in-picture'); // returns true
61-
$permissions->hasKey('picture-in-picture', 'foobar'); // returns false
60+
$permissions->hasName('picture-in-picture'); // returns true
61+
$permissions->hasName('picture-in-picture', 'foobar'); // returns false
6262
// 'foobar' is not a valid key or at least it is not present
6363

64-
$permissions->getByKey('camera'); // returns Item::fromToken('*');
64+
$permissions->getByName('camera'); // returns Item::fromToken('*');
6565
$permissions->toAssociative(); // returns an iterator
6666
// the iterator key is the member key and the value is the member value
6767
// the offset is "lost"
68-
$permissions->keyByIndex(42); // returns null because there's no member with the offset 42
69-
$permissions->keyByIndex(2); // returns 'camera'
68+
$permissions->nameByIndex(42); // returns null because there's no member with the offset 42
69+
$permissions->nameByIndex(2); // returns 'camera'
7070

71-
$permissions->indexByKey('foobar'): // returns null because there's no member with the key 'foobar'
72-
$permissions->indexByKey('geolocation'): // returns 1
71+
$permissions->indexByName('foobar'): // returns null because there's no member with the key 'foobar'
72+
$permissions->indexByName('geolocation'): // returns 1
7373
```
7474

7575
> [!IMPORTANT]
76-
> The `getByKey` method will throw an `InvalidOffset` exception if no member exists for the given `$offset`.
76+
> The `getByName` method will throw an `InvalidOffset` exception if no member exists for the given `$offset`.
7777
7878
> [!TIP]
7979
> The `ArrayAccess` interface proxy the result from `getByIndex` in list.
80-
> The `ArrayAccess` interface proxy the result from `getByKey` in ordered map.
80+
> The `ArrayAccess` interface proxy the result from `getByName` in ordered map.
8181
8282
### Accessing the parameters values
8383

8484
As we have already seen, it is possible to access the `Parameters` values directly
8585
from the `Item` instance. The same public API is used from the `InnerList`.
8686

8787
On the other hand if you already have a `Parameters` instance you can use the
88-
`valueByKey` and `valueByIndex` methods to directly access the value from a single
88+
`valueByName` and `valueByIndex` methods to directly access the value from a single
8989
parameter.
9090

9191
> [!TIP]
92-
> The `parameterByKey` proxy the result from `valueByKey`.
92+
> The `parameterByKey` proxy the result from `valueByName`.
9393
> The `parameterByIndex` proxy the result from `valueByIndex`.
9494
9595
## Building and Updating Structured Fields Values
@@ -138,11 +138,11 @@ following steps. You, first, create a `Parameters` or a `Dictionary` instance us
138138
use any of the following modifying methods to populate it.
139139

140140
```php
141-
$map->add(string $key, $value): static;
142-
$map->append(string $key, $value): static;
143-
$map->prepend(string $key, $value): static;
141+
$map->add(string $name, $value): static;
142+
$map->append(string $name, $value): static;
143+
$map->prepend(string $name, $value): static;
144144
$map->mergeAssociative(...$others): static;
145-
$map->removeByKeys(string ...$keys): static;
145+
$map->removeByKeys(string ...$names): static;
146146
```
147147

148148
As shown below:
@@ -384,9 +384,9 @@ Both objects provide additional modifying methods to help deal with parameters.
384384
You can attach and update the associated `Parameters` instance using the following methods.
385385

386386
```php
387-
$field->addParameter(string $key, mixed $value): static;
388-
$field->appendParameter(string $key, mixed $value): static;
389-
$field->prependParameter(string $key, mixed $value): static;
387+
$field->addParameter(string $name, mixed $value): static;
388+
$field->appendParameter(string $name, mixed $value): static;
389+
$field->prependParameter(string $name, mixed $value): static;
390390
$field->withoutParameters(string ...$keys): static; // this method is deprecated as of version 1.1 use withoutParametersByKeys instead
391391
$field->withoutAnyParameter(): static;
392392
$field->withParameters(Parameters $parameters): static;

docs/06-validation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Because parameters are optional by default and the `longitude` parameter is requ
172172
require its presence. So to fully validate the parameter we need to do the following
173173

174174
```php
175-
$member->parameterBykey(
175+
$member->parameterByName(
176176
key: 'longitude',
177177
validate: fn (mixed $value) => match (true) {
178178
Type::Decimal->supports($value) => true,
@@ -257,9 +257,9 @@ use Bakame\Http\StructuredFields\Validation\ParametersValidator;
257257
$parametersValidator = ParametersValidator::new()
258258
->filterByCriteria(
259259
fn (Parameters $parameters): bool|string => $parameters
260-
->allowedKeys(['location', 'longitude', 'latitude', 'date'])
260+
->allowedNames(['location', 'longitude', 'latitude', 'date'])
261261
)
262-
->filterByKeys([
262+
->filterByNames([
263263
'location' => [
264264
'validate' => fn (mixed $value) => Type::fromVariable($value)->isOneOf(Type::String, Type::DisplayString),
265265
],

0 commit comments

Comments
 (0)