nur-sery/nur_src/v/bs3/fo/FormManager.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\v\bs3\fo;
use nur\b\ValueException;
class FormManager {
const TYPE_BASIC = "basic";
const TYPE_HORIZONTAL = "horizontal";
const TYPE_INLINE = "inline";
const TYPE_NAVBAR = "navbar";
const TYPE_NAKED = "naked";
private $inNavbar = false;
function isInNavbar(): bool {
return $this->inNavbar;
}
function setInNavbar(bool $inNavbar=true): void {
$this->inNavbar = $inNavbar;
}
function get(?string $type=null, ?array $params=null): Form {
if ($type === null) {
$type = $this->inNavbar? self::TYPE_NAVBAR: self::TYPE_HORIZONTAL;
}
switch ($type) {
case self::TYPE_BASIC:
case "form":
case "b":
case "f":
return new FormBasic($params);
case self::TYPE_HORIZONTAL:
case "horiz":
case "h":
return new FormHorizontal($params);
case self::TYPE_INLINE:
case "i":
return new FormInline($params);
case self::TYPE_NAVBAR:
case "n":
return new FormNavbar($params);
case self::TYPE_NAKED:
return new FormNaked($params);
default:
throw ValueException::invalid_value($type, "form type");
}
}
}