PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / ConditionAssesor.php

ConditionAssesor.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/ConditionAssesor.php

96 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services;
4
5
6 use FluentCart\Framework\Support\Arr;
7 use FluentCart\Framework\Support\Str;
8
9 class ConditionAssesor
10 {
11 public static function evaluate(&$field, &$inputs)
12 {
13 $status = Arr::get($field, 'conditionals.status');
14
15 $conditionals = $status ? Arr::get($field, 'conditionals.conditions') : false;
16
17 $hasConditionMet = true;
18
19 if ($conditionals) {
20 $toMatch = Arr::get($field, 'conditionals.type');
21
22
23 foreach ($conditionals as $conditional) {
24
25 $hasConditionMet = static::assess($conditional, $inputs);
26
27 if ($hasConditionMet && $toMatch == 'any') {
28 return true;
29 }
30
31 if ($toMatch === 'all' && !$hasConditionMet) {
32 return false;
33 }
34 }
35 }
36
37 return $hasConditionMet;
38 }
39
40 public static function assess(&$conditional, &$inputs)
41 {
42 if ($conditional['field']) {
43 $inputValue = Arr::get($inputs, $conditional['field']);
44
45 switch ($conditional['operator']) {
46 case '=':
47 if (is_array($inputValue)) {
48 return in_array($conditional['value'], $inputValue);
49 }
50 return $inputValue == $conditional['value'];
51 case '!=':
52 if (is_array($inputValue)) {
53 return !in_array($conditional['value'], $inputValue);
54 }
55 return $inputValue != $conditional['value'];
56 case '>':
57 return $inputValue > $conditional['value'];
58 case '<':
59 return $inputValue < $conditional['value'];
60 case '>=':
61 return $inputValue >= $conditional['value'];
62 case '<=':
63 return $inputValue <= $conditional['value'];
64 case 'startsWith':
65 return Str::startsWith($inputValue, $conditional['value']);
66 case 'endsWith':
67 return Str::endsWith($inputValue, $conditional['value']);
68 case 'contains':
69 return Str::contains($inputValue, $conditional['value']);
70 case 'doNotContains':
71 return !Str::contains($inputValue, $conditional['value']);
72 case 'length_equal':
73 if (is_array($inputValue)) {
74 return count($inputValue) == $conditional['value'];
75 }
76 $inputValue = strval($inputValue);
77 return strlen($inputValue) == $conditional['value'];
78 case 'length_less_than':
79 if (is_array($inputValue)) {
80 return count($inputValue) < $conditional['value'];
81 }
82 $inputValue = strval($inputValue);
83 return strlen($inputValue) < $conditional['value'];
84 case 'length_greater_than':
85 if (is_array($inputValue)) {
86 return count($inputValue) > $conditional['value'];
87 }
88 $inputValue = strval($inputValue);
89 return strlen($inputValue) > $conditional['value'];
90 }
91 }
92
93 return false;
94 }
95 }
96