File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Microwin7 \PHPUtils \Request ;
4+
5+ use Microwin7 \PHPUtils \Exceptions \RequiredArgumentMissingException ;
6+
7+ class RequiredArguments
8+ {
9+ private array $ arguments ;
10+ public function __construct ()
11+ {
12+ }
13+ public function __get ($ name ): string |array
14+ {
15+ return $ this ->arguments [$ name ];
16+ }
17+ public static function validate (array $ requiredArguments , ?array $ where ): static
18+ {
19+ if ((!empty ($ requiredArguments ) && !empty ($ where )) && count ($ requiredArguments ) > count ($ where )) {
20+ $ class = new static ();
21+ foreach ($ requiredArguments as $ argument ) {
22+ $ class ->with ($ argument , $ where [$ argument ] ?? new RequiredArgumentMissingException ($ requiredArguments ));
23+ }
24+ } else throw new RequiredArgumentMissingException ($ requiredArguments );
25+ return $ class ;
26+ }
27+ private function with (string $ property , string |array $ value ): void
28+ {
29+ $ this ->arguments [$ property ] = $ value ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments