Support for Read Only properties
What's changed:
In this minor release, classes of the application can now take advantage of PHP 8.1's new readonly keyword. Any properties that are marked as public readonly will be exposed as Bindable values now, removing a lot of boilerplate code on Model classes.
Example:
// Model class:
class PersonModel {
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly int $age,
) {}
#[BindGetter]
public function getAgeStatus():string {
return $this->age >= 18
? "adult"
: "minor";
}
}// Page code:
function go(Input $input, DocumentBinder $binder, PersonRepository $personRepo):void {
$binder->bindData($personRepo->getById($input->getString("id"));
}<!-- Page view -->
<div class="user-profile">
<h1 data-bind:text="name">User name<h1>
<img src="/asset/img/user-profile/{{id}}.jpg" alt="{{name}}'s user profile" />
<p>This user is marked as <span data-bind:text="ageStatus">Age Status</span></p>
</div>