phpolar / model
Provides support for configuring the properties of an object for validation, formatting, and storage.
1.2.3
2024-12-02 02:47 UTC
Requires
- php: >=8.1
- php-contrib/validator: ^1.0
- phpolar/core: ^4.0.0
- phpolar/model-resolver: ^1.0
- phpolar/storage-driver: ^1.0
Requires (Dev)
- ext-ast: *
- ext-openssl: *
- phan/phan: ^5.4
- php-coveralls/php-coveralls: ^2.5
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^11.1.3
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-12-09 04:03:27 UTC
README
PHPolar Model
Provides support for configuring the properties of an object for validation, formatting, and storage.
Example 1
<!DOCTYPE html> <?php namespace MyApp; use Phpolar\Phpolar\FormControlTypes; (function (PersonForm $view) { ?> <html> <body style="text-align:center"> <h1><?= $view->title ?></h1> <div class="container"> <form action="<?= $view->action ?>" method="post"> <?php foreach ($view as $propName => $propVal): ?> <label><?= $view->getLabel($propName) ?></label> <?php switch ($view->getFormControlType($propName)): ?> <?php case FormControlTypes::Input: ?> <input type="text" value="<?= $propVal ?>" /> <?php case FormControlTypes::Select: ?> <select> <?php foreach ($propVal as $name => $item): ?> <option value="<?= $item ?>"><?= $name ?></option> <?php endforeach ?> </select> <?php endswitch ?> <?php endforeach ?> </form> </div> </body> </html> <?php })($this);
Use Attributes to Configure Models
use Phpolar\Phpolar\AbstractModel; class Person extends AbstractModel { public string $title = "Person Form"; public string $action = "somewhere"; #[MaxLength(20)] public string $firstName; #[MaxLength(20)] public string $lastName; #[Column("Residential Address")] #[Label("Residential Address")] #[MaxLength(200)] public string $address1; #[Column("Business Address")] #[Label("Business Address")] #[MaxLength(200)] public string $address2; }