PHP.GT

Latest releases

Server: PHP 7.4 compatibility

Published on by Greg Bowler

Since the introduction of PHP 7.4, the way sub-processes are handled in PHP is a lot cleaner and more manageable. This release upgrades to the new execution model, which means that if the serve command is executed from within another PHP process, the server will no longer be left hanging after the parent process is terminated.

Daemon: Packagist release

Published on by Greg Bowler

This release contains no new files compared to v1.1.0, but is made due to an error with Packagist reading an earlier tag.

Cli: Upgrade to PHP 7.4

Published on by Greg Bowler

Since the introduction of PHP 7.4, the way sub-processes are handled in PHP is a lot cleaner and more manageable. This release upgrades to the new execution model, which means that if any Gt/Cli/Command is executed from within another PHP process, the server will no longer be left hanging after the parent process is terminated.

Daemon: Process arguments passed as array

Published on by Greg Bowler

Since PHP 7.4’s release, proc_open takes an array of arguments to start a new process, rather than a string to pass to a subshell. This change makes a huge difference, as processes are never left hanging due to their execution within a separate subshell. This does increase the minimum PHP version to 7.4, but that’s OK due to WebEngine’s support timeline.

DomValidation: <select> element implementation

Published on by Greg Bowler

The introduction of <select> validation is released in v0.3.0.

The following rules apply:

  • If a <select> element is submitted, its available <option> elements are inspected.
  • If the required attribute is present, a value must be sent.
  • Only values available within <option> elements are considered valid.
  • <option> elements can have a value attribute to indicate their value, otherwise their text content will be used.

DomValidation: Date formats

Published on by Greg Bowler

In this release, the following date validation formats are introduced:

  • type=date
  • type=month
  • type=week
  • type=datetime-local

All of these types are defined within the TypeDate Rule class.

DomValidation: Number type with min, max, range, step

Published on by Greg Bowler

When an input element’s type attribute is in the Number state, the rules in this release apply. The input element represents a control for setting the element’s value to a string representing a number.

Included in this release are the following features:

  • type=number rule
  • type=range rule
  • min
  • max
  • step

DomValidation: Regular expression patterns

Published on by Greg Bowler

The pattern attribute specifies a regular expression against which the control’s value.

Constraint validation: If the element’s value is not the empty string, and the element has a compiled pattern regular expression but that regular expression does not match the entirety of the element’s value, then the element is suffering from a pattern mismatch.

Daemon: Subprocesses handled by `exec`

Published on by Greg Bowler

Along with some examples and some defensive measures, the feature added to this release is to execute the provided command without forking a new process. This behaviour may change again soon due to #9 being implemented, so expect #10 to come first to avoid any backwards breaking changes.

DomTemplate: Improved component/template relationship

Published on by Greg Bowler

This release has two slight backwards-breaking changes:

  1. Binding lists with bindList and bindNestedList can no longer use associative arrays for the data structure, because there is not any way of differentiating between an associative array and any other type of list of data structures. If you are using associative arrays, you will need to indicate that the array is actually a data structure and not a list by casting to an object. This is good practice anyway - arrays should only contain a list of things, objects can be used to describe data.
  2. HTML components that have the data-template attribute on the component tag, rather than on the contained tag(s), can not be used if the component consists of multiple root elements. This is an edge-case and improves the readability by forcing component usage to be more expected.

DomTemplate: Bindable booleans

Published on by Greg Bowler

Prior to this release, if you were to attempt to bind a boolean value somewhere in the DOM, a 0 or a 1 would be used as the value, which doesn’t seem helpful in any way.

This release allows boolean values to behave slightly differently. Now, the boolean is used to define whether the bind value’s key should be output to the element.

This is useful when a flag is required to be output to the DOM. For example, adding a class to an element when a navigation menu is “selected” or a to do item is “completed”.

This technique can be used to bind a predefined value to an element only when the bind key is true. When a false value is bound, nothing will be bound to the DOM.

Example adding the “open” class to a <menu> element that already contains classes:

<menu class="main-menu positive" data-bind:class="open">
	...
</menu>
$document->querySelector("menu")->bindKeyValue("open", true);

Input: Loosen dependencies

Published on by Greg Bowler

For consistency, all PHP.Gt repositories are adopting a “* by default” dependency policy for internal dependencies. This will make future merges simpler.

Http: Named HTTP status codes

Published on by Greg Bowler

In the StatusCode class, all the status codes within the REASON_PHRASE constant have been extracted to named constants, allowing you to refer to status codes by name, such as StatusCode::OK.

Input: Dependency bump

Published on by Greg Bowler

A number of internal PhpGt releases are made this week. This patch release synchronises all repositories.

Input: Changes to nullable type returning

Published on by Greg Bowler

For all get* functions on InputDataGetter classes, there is now a slightly modified behavior. Apart from with getString, if the input data contains an empty string, it is represented by null, rather than the default for that type.

This means that if there is a number input on the page, and the user does not enter any data into it, calling getInt() on that field will now return null instead of 0 - properly representing an absence of data, without making any assumptions.

This is a minor release, due to minor backwards breaking changes.

Dom: Compatibility and test improvement

Published on by Greg Bowler

There are no new features included within this release, just improvements to the way Element object properties are handled, and how Element and Document objects are tested. Have fun.

Sync: Pattern argument defaults to null

Published on by Greg Bowler

The introduction of the new pattern attribute unlocked a lot of possibilities, but a glob pattern is not always required on simple usages so this argument has now been made completely optional.

Http: Uri helper methods

Published on by Greg Bowler

Within the ServerInfo class, some new helper methods have been included within this release. These methods are intended to help remove repetition when working with full URIs, including the scheme and host parts.

New functions:

  • getFullUri()
  • getServerHost()
  • getHttpHost()

CssXPath: November 2019 bugfixes

Published on by Greg Bowler

When using continue within switch statements, special care has to be taken to ensure the loops are continued as expected. This release removes ambiguity by specifying the continue nesting argument.

From https://www.php.net/manual/en/control-structures.continue.php :

Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed). If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

DomTemplate: Bindable objects

Published on by Greg Bowler

With this release, any data type can be used as the value to a bind function. This allows StdClass data objects, or any class with public properties to be used as the value to bind to the document.

Sync: Pass pattern on CLI

Published on by Greg Bowler

This small release makes it possible to pass in a glob pattern to the sync command to only sync files that match the provided pattern.

sync source_dir dest_dir --pattern '**/*.js'