Skip to content

Commit cf7c97f

Browse files
docs: document new conditionals, improve documentation structure
1 parent 6fc5b45 commit cf7c97f

File tree

3 files changed

+118
-39
lines changed

3 files changed

+118
-39
lines changed

docs/.vitepress/config.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export default defineConfig({
4646
{ text: 'Extending States', link: '/extending-states' },
4747
{ text: 'State Sharing', link: '/state-sharing' },
4848
]
49+
},
50+
{
51+
text: 'Reference',
52+
items: [
53+
{ text: 'Available Conditional Methods', link: '/reference/conditional-methods' },
54+
]
4955
}
5056
],
5157

docs/pages/basic-usage.md

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -84,45 +84,6 @@ You can also use the string representation of states instead of enum cases:
8484
'name' => $this->unlessState('minimal', $this->full_name),
8585
```
8686

87-
## Available Conditional Methods
88-
89-
The package provides several methods to conditionally include attributes:
90-
91-
### `whenState`
92-
93-
Include a value only when the current state matches the specified state:
94-
95-
```php
96-
'email' => $this->whenState(State::Full, $this->email),
97-
'admin_notes' => $this->whenState(State::Full, $this->admin_notes, 'N/A'),
98-
```
99-
100-
### `unlessState`
101-
102-
Include a value unless the current state matches the specified state:
103-
104-
```php
105-
'public_info' => $this->unlessState(State::Minimal, $this->public_information),
106-
```
107-
108-
### `whenStateIn`
109-
110-
Include a value when the current state is one of the specified states:
111-
112-
```php
113-
'detailed_info' => $this->whenStateIn([State::Full, State::Table], [
114-
'department' => $this->department,
115-
'position' => $this->position,
116-
]),
117-
```
118-
119-
### `unlessStateIn`
120-
121-
Include a value unless the current state is one of the specified states:
122-
123-
```php
124-
'sensitive_data' => $this->unlessStateIn([State::Minimal, State::Table], $this->sensitive_info),
125-
```
12687

12788
### Magic Conditionals
12889

@@ -133,6 +94,8 @@ You can also use magic methods with for cleaner syntax:
13394
'name' => $this->unlessStateMinimal($this->full_name),
13495
```
13596

97+
For a full list of available conditional methods, see the [Available Conditional Methods](reference/conditional-methods.md) reference.
98+
13699
### Manual State Access
137100

138101
If you need more complex logic than inline conditionals, you can access the resource's current state directly using the `getState()` method:
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Available Conditional Methods
2+
3+
The package provides several methods to conditionally include attributes in Stateful Resources.
4+
5+
[[toc]]
6+
7+
### `whenState`
8+
9+
Include a value only when the current state matches the specified state:
10+
11+
> 🪄 Magic method available
12+
13+
```php
14+
'email' => $this->whenState(State::Full, $this->email),
15+
// or
16+
'email' => $this->whenStateFull($this->email),
17+
```
18+
19+
### `unlessState`
20+
21+
Include a value unless the current state matches the specified state:
22+
23+
> 🪄 Magic method available
24+
25+
```php
26+
'public_info' => $this->unlessState(State::Minimal, $this->public_information),
27+
// or
28+
'public_info' => $this->unlessStateMinimal($this->public_information),
29+
```
30+
31+
### `whenStateIn`
32+
33+
Include a value when the current state is one of the specified states:
34+
35+
> No magic method available
36+
37+
```php
38+
'detailed_info' => $this->whenStateIn([State::Full, State::Table], [
39+
'department' => $this->department,
40+
'position' => $this->position,
41+
]),
42+
```
43+
44+
### `unlessStateIn`
45+
46+
Include a value unless the current state is one of the specified states:
47+
48+
> No magic method available
49+
50+
```php
51+
'sensitive_data' => $this->unlessStateIn([State::Minimal, State::Table], $this->sensitive_info),
52+
```
53+
54+
### `mergeWhenState`
55+
56+
Merge an array of attributes when the current state matches the specified state:
57+
58+
> 🪄 Magic method available
59+
60+
```php
61+
$attributes = $this->mergeWhenState(State::Full, [
62+
'email' => $this->email,
63+
'phone' => $this->phone,
64+
]);
65+
// or
66+
$attributes = $this->mergeWhenStateFull([
67+
'email' => $this->email,
68+
'phone' => $this->phone,
69+
]);
70+
```
71+
72+
### `mergeUnlessState`
73+
Merge an array of attributes unless the current state matches the specified state:
74+
75+
> 🪄 Magic method available
76+
77+
```php
78+
$attributes = $this->mergeUnlessState(State::Minimal, [
79+
'email' => $this->email,
80+
'phone' => $this->phone,
81+
]);
82+
// or
83+
$attributes = $this->mergeUnlessStateMinimal([
84+
'email' => $this->email,
85+
'phone' => $this->phone,
86+
]);
87+
```
88+
89+
### `mergeWhenStateIn`
90+
Merge an array of attributes when the current state is one of the specified states:
91+
92+
> No magic method available
93+
94+
```php
95+
$attributes = $this->mergeWhenStateIn([State::Full, State::Table], [
96+
'email' => $this->email,
97+
'phone' => $this->phone,
98+
]);
99+
```
100+
### `mergeUnlessStateIn`
101+
Merge an array of attributes unless the current state is one of the specified states:
102+
103+
> No magic method available
104+
105+
```php
106+
$attributes = $this->mergeUnlessStateIn([State::Minimal, State::Table], [
107+
'email' => $this->email,
108+
'phone' => $this->phone,
109+
]);
110+
```

0 commit comments

Comments
 (0)