@@ -434,3 +434,89 @@ class Response
434434 return false ;
435435 }
436436}
437+
438+ class ValuesResponse
439+ {
440+ /**
441+ * @var array
442+ */
443+ private array $ values ;
444+
445+ /**
446+ * @param string|array|null $values
447+ */
448+ public function __construct ($ values = null )
449+ {
450+ if ( ! is_array ($ values )) {
451+ if ( ! is_null ($ values ) ) {
452+ $ this ->error ('Invalid values supplied ' , true );
453+ }
454+ $ this ->values = [];
455+ } else {
456+ $ this ->values = $ values ;
457+ }
458+ }
459+
460+ /**
461+ * Expect value.
462+ *
463+ * @param string $name
464+ * @param mixed $value
465+ * @return ValuesResponse
466+ */
467+ public function expectValue (string $ name , $ value = null )
468+ {
469+ if ( ! isset ($ this ->values [$ name ])) {
470+ return $ this ->error ("Value $ name not found in values " );
471+ }
472+ if ( ! is_null ($ value ) && $ value !== $ this ->values [$ name ]) {
473+ return $ this ->error ("Value $ name is {$ this ->values [$ name ]} but expected $ value " );
474+ }
475+ return $ this ;
476+ }
477+
478+ /**
479+ * Get values.
480+ *
481+ * @return array
482+ */
483+ public function getValues ()
484+ {
485+ return $ this ->values ;
486+ }
487+
488+ /**
489+ * Debug output data.
490+ *
491+ * @return ValuesResponse
492+ */
493+ public function debugOutput ()
494+ {
495+ echo ">>> ValuesResponse \n" ;
496+ echo "----------------- Values ----------------- \n" ;
497+ var_dump ($ this ->values );
498+ echo "--------------------------------------- \n\n" ;
499+
500+ return $ this ;
501+ }
502+
503+ /**
504+ * Emit error message
505+ *
506+ * @param string $message
507+ * @param bool $throw
508+ *
509+ * @return ValuesResponse
510+ */
511+ private function error (string $ message , $ throw = false ): bool
512+ {
513+ $ errorMessage = "ERROR: $ message \n" ;
514+ if ($ throw ) {
515+ throw new \Exception ($ errorMessage );
516+ }
517+ $ this ->debugOutput ();
518+ echo $ errorMessage ;
519+
520+ return $ this ;
521+ }
522+ }
0 commit comments