PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.1.1
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.1.1
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Support / Conditionable.php

Conditionable.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.1.1, 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 FluentBooking\Framework\Support;
4
5 use Closure;
6 use FluentBooking\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