First pass of the RequestInterface and default implementation

master
Brady McDonough 2 years ago
parent 8d50708e93
commit 96ce850b53

@ -0,0 +1,47 @@
<?php
namespace BradyMcD\TAATP\Request;
use BradyMcD\TAATP\Required\RequestInterface;
use BradyMcD\TAATP\Required\RequestTargets;
class Base implements RequestInterface
{
public function __construct(private mixed $paths)
{
if(\is_array($paths))
{
foreach($paths as $r => $p)
{
// ::from will throw a ValueError if invalid
RequestTargets::from($r);
}
}
else if(!\is_string($paths))
{
throw new \IllegalArgumentException("You must either provide a single path as a string or a list of RequestTargets as keys to paths.");
}
}
public function form_props(string $place): string
{
$method = 'method="post"';
if(\is_array($this->paths))
{
$action = 'action="' . $this->paths[$place] . '"';
}
else
{
$action = 'action="' . $this->paths . '"';
}
return $action . ' ' . $method;
}
public function get_resp(string $k): string
{
return $__REQUEST[$k];
}
}
?>

@ -16,14 +16,14 @@ interface RequestInterface
* @param string $place One of "enroll", "unenroll" or "authenticate" * @param string $place One of "enroll", "unenroll" or "authenticate"
* @return string * @return string
*/ */
function form_props(string $place): string; public function form_props(string $place): string;
/** /**
* Returns a referred user response variable. * Returns a referred user response variable.
* @param string $k The key the user is sending * @param string $k The key the user is sending
* @return string * @return string
*/ */
function get_resp(string $k): string; public function get_resp(string $k): string;
} }

@ -0,0 +1,11 @@
<?php
namespace BradyMcD\TAATP\Required;
enum RequestTargets: string{
case Authenticate = "authenticate";
case Enroll = "enroll";
case Unenroll = "unenroll";
}
?>
Loading…
Cancel
Save