@@ -460,3 +460,89 @@ class Response
460460 return false ;
461461 }
462462}
463+
464+ class ValuesResponse
465+ {
466+ /**
467+ * @var array
468+ */
469+ private array $ values ;
470+
471+ /**
472+ * @param string|array|null $values
473+ */
474+ public function __construct ($ values = null )
475+ {
476+ if ( ! is_array ($ values )) {
477+ if ( ! is_null ($ values ) ) {
478+ $ this ->error ('Invalid values supplied ' , true );
479+ }
480+ $ this ->values = [];
481+ } else {
482+ $ this ->values = $ values ;
483+ }
484+ }
485+
486+ /**
487+ * Expect value.
488+ *
489+ * @param string $name
490+ * @param mixed $value
491+ * @return ValuesResponse
492+ */
493+ public function expectValue (string $ name , $ value = null )
494+ {
495+ if ( ! isset ($ this ->values [$ name ])) {
496+ return $ this ->error ("Value $ name not found in values " );
497+ }
498+ if ( ! is_null ($ value ) && $ value !== $ this ->values [$ name ]) {
499+ return $ this ->error ("Value $ name is {$ this ->values [$ name ]} but expected $ value " );
500+ }
501+ return $ this ;
502+ }
503+
504+ /**
505+ * Get values.
506+ *
507+ * @return array
508+ */
509+ public function getValues ()
510+ {
511+ return $ this ->values ;
512+ }
513+
514+ /**
515+ * Debug output data.
516+ *
517+ * @return ValuesResponse
518+ */
519+ public function debugOutput ()
520+ {
521+ echo ">>> ValuesResponse \n" ;
522+ echo "----------------- Values ----------------- \n" ;
523+ var_dump ($ this ->values );
524+ echo "--------------------------------------- \n\n" ;
525+
526+ return $ this ;
527+ }
528+
529+ /**
530+ * Emit error message
531+ *
532+ * @param string $message
533+ * @param bool $throw
534+ *
535+ * @return ValuesResponse
536+ */
537+ private function error (string $ message , $ throw = false ): bool
538+ {
539+ $ errorMessage = "ERROR: $ message \n" ;
540+ if ($ throw ) {
541+ throw new \Exception ($ errorMessage );
542+ }
543+ $ this ->debugOutput ();
544+ echo $ errorMessage ;
545+
546+ return $ this ;
547+ }
548+ }
0 commit comments