Login::class, 'register' => Register::class, ]; protected const fields = []; abstract public function handle(): bool; abstract public function preSubmitField(Server $server,Field $field): ?string; public static function factory(string $class): self { if (array_key_exists($class,self::actions)) { $class = self::actions[$class]; return new $class; } throw new \Exception(sprintf('Call to action [%s] doesnt have a class to execute',$class)); } public function __get(string $key): mixed { switch ($key) { case 'fields_input': return $this->{$key}; default: if (($x=$this->fields_input->search(function($item) use ($key) { return $item->name === $key; })) !== FALSE) return $this->fields_input->get($x)->value; else return NULL; } } public function __set(string $key,mixed $value): void { switch ($key) { case 'fields_input': $this->{$key} = $value; break; default: throw new \Exception('Unknown key: '.$key); } } public function init(): void { if (! isset($this->fields_input)) throw new \Exception(sprintf('Missing fields_input in [%s]',get_class($this))); // First field data element is user, the second is the password if (count($x=collect(static::fields)->diff($this->fields_input->pluck('name')))) throw new ActionMissingInputsException(sprintf('Login missing %s',$x->join(','))); } }