Releases: PhpGt/DomTemplate
Upgrade dom requirement and loosen version range
This minor patch release bumps the Dom version, but loosens the semver range as defined by Composer. This will allow future minor releases of Dom to be included by DomTempalte without having to make a new release.
ReadOnly property bugfix
What's Changed
- Build(deps-dev): bump phpstan/phpstan from 1.8.0 to 1.8.1 by @dependabot in #360
- 361 bugfix by @Tom-Clare in #362
New Contributors
- @Tom-Clare made their first contribution in #362
Full Changelog: v3.1.2...v3.1.3
Stabalise dependencies
A minor patch release to stabalise the dependency on php.gt/dom
Temporary fix for PHP XML bug 81506
The bug in PHP's XML implementation deallocates the Text node from memory, even though it might be referenced later. This patch release includes a number of hacky fixes to resolve this downstream, which is a good solution before the PHP bug is fixed.
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>
Native DOMDocument extension
The major change in this release is the switch to phpgt/dom v4, which now extends the native DOMDocument rather than using a Facade pattern. This greatly improves efficiency.
Changes in functionality also include:
- cyclic recursion in partials is now handled
- binding of data only occurs once per bind, unless the
data-rebind
attribute is present
Full Changelog: v2.2.4...v3.0.0
Minor bugfixes & PHP 8.1 compatibility
fix: bind multiple attribute placeholders #327
Example: <a href="/path/to/{{project}}/with/{{another}}/attribute/placeholder">
- any attribute can now contain multiple placeholders.
290 default placeholder #328
Example:
Hello, {{name ?? you}}!
fix: resolve deprecation notices #329
PHP 9 will introduce a lot more strict typing, and 8.1 has started emitting deprecation notices. These have all been addressed in this release.
fix: insert template before correct element #330
When template elements have more than one similar siblings, the correct next sibling is remembered, and the template element is inserted in the correct position.
Identify template parents when there are ambiguous XPath selectors #337
Similarly to above, when two or more template elements have similarly-addressed parents, the template element is now always added to the correct one.
Move responsibility of HTMLSelectElement::$value to PhpGt/Dom
The functionality added in the previous release has been moved to be implemented and tested within PHP.Gt/Dom so other projects can take advantage of the functionality, without using DomTemplate.
Select binding by value
Along with some dependency upgrades, the extra functionality introduced in this release allows an HTMLSelectElement to have its value bound, so the relevant HTMLOptionElement is selected. This works using the value attribute whether or not the option has a value - without a value, the textContent of the option will be used.
Binding tweaks
In this minor patch release, there are two improvements:
- Table bind attributes like
data-template-key
are removed during thecleanBindAttributes()
call. - Strings that contain names of inbuilt PHP functions are not treated as "callable" types when binding values.