PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.41
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.41
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / vendor / wpfluent / framework / src / WPFluent / Support / Conditionable.php

Conditionable.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.41, at vendor/wpfluent/framework/src/WPFluent/Support/Conditionable.php

74 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\Framework\Support;
4
5 use Closure;
6 use FluentBoards\Framework\Support\HigherOrderWhenProxy;
7
8 trait Conditionable
9 {
10 /**
11 * Apply the callback if the given "value" is (or resolves to) truthy.
12 *
13 * @template TWhenParameter
14 * @template TWhenReturnType
15 *
16 * @param (\Closure($this): TWhenParameter)|TWhenParameter|null $value
17 * @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback
18 * @param (callable($this, TWhenParameter): TWhenReturnType)|null $default
19 * @return $this|TWhenReturnType
20 */
21 public function when($value = null, ?callable $callback = null, ?callable $default = null)
22 {
23 $value = $value instanceof Closure ? $value($this) : $value;
24
25 if (func_num_args() === 0) {
26 return new HigherOrderWhenProxy($this);
27 }
28
29 if (func_num_args() === 1) {
30 return (new HigherOrderWhenProxy($this))->condition($value);
31 }
32
33 if ($value) {
34 return $callback($this, $value) ?? $this;
35 } elseif ($default) {
36 return $default($this, $value) ?? $this;
37 }
38
39 return $this;
40 }
41
42 /**
43 * Apply the callback if the given "value" is (or resolves to) falsy.
44 *
45 * @template TUnlessParameter
46 * @template TUnlessReturnType
47 *
48 * @param (\Closure($this): TUnlessParameter)|TUnlessParameter|null $value
49 * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback
50 * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default
51 * @return $this|TUnlessReturnType
52 */
53 public function unless($value = null, callable $callback = null, callable $default = null)
54 {
55 $value = $value instanceof Closure ? $value($this) : $value;
56
57 if (func_num_args() === 0) {
58 return (new HigherOrderWhenProxy($this))->negateConditionOnCapture();
59 }
60
61 if (func_num_args() === 1) {
62 return (new HigherOrderWhenProxy($this))->condition(! $value);
63 }
64
65 if (! $value) {
66 return $callback($this, $value) ?? $this;
67 } elseif ($default) {
68 return $default($this, $value) ?? $this;
69 }
70
71 return $this;
72 }
73 }
74