PHP.GT

Latest releases

Http: CI improvements and PHP 8 compatibility

Published on by Greg Bowler

We’re one step closer to a CI environment fully hosted within Github Actions now, with PHPUnit and PHPStan tests being run within Actions. Codesniffer is planned soon too.

PHP 8 compatibility is made possible thanks to an updated dependency tree.

Fetch: JSON improvements

Published on by Greg Bowler

Type-safe functions have been added to the Json object, along with enhanced iterator functions. This release is being made ready for the work starting on v2, where PhpGt’s Async functions are integrated as opposed to React’s.

Dom: December 2020

Published on by Greg Bowler

A few minor updates to the CI process have been made, along with a new test and functionality fix to innerHTML thanks to @speich.

Database: PHP 8 compatibilty and Github Actions

Published on by Greg Bowler

Two small tweaks here:

Firstly, requiring phpgt/database will work in PHP 8 projects now thanks to the Composer requirements being changed from ^7.4 to >=7.4. This was breaking WebEngine being installed in PHP 8.

Secondly, we now have a working Github Actions CI workflow. More improvements will be coming over at https://github.com/php-actions soon to improve build times, too.

Have fun!

SqlBuilder: Main functionality implemented

Published on by Greg Bowler

The SqlBuilder repository gets a major step closer to being production-ready with this pre-release.

Implemented now are the InsertQuery, SelectQuery, UpdateQuery, DeleteQuery and ReplaceQuery classes, with all the functions ready for representing tables, conditions, limits, orders, etc.

Still to come before v1 is a refactoring to improve the query classes inheritance (some functionality is shared between different query types), compatibility testing with other database engines, and improvements to the return types of functions.

DomTemplate: September 2020

Published on by Greg Bowler

The following improvements have been made in this release:

  • Docblock improvements to resolve the issue of nested properties losing their DomTemplate extensions (for example $document->getElementById("test")->parentNode->nextElementSibling should still be Gt\DomTemplate\Element, but was sometimes indicating Gt\Dom\Element.
  • Dropped CircleCI for Github Actions - now everything is in once place (still to do: code quality scoring, currently handled by Scrutinizer)
  • Bind attributes are removed in bulk at the end of the page render, which slightly improves performance, but mainly catches the error where not all attributes were removed. _ bindNames implemented, allowing form elements to have their values bound by their names.

Dom: September 2020

Published on by Greg Bowler

  • Bugfix: When working with a textarea’s value attribute, getting and setting on the same request would not persist data.
  • Feature: Boolean attributes are implemented and tested: attributes like disabled, checked, etc. all correspond to their correct HTML attributes.
  • Tests: XML documents tested for querySelector and querySelectorAll functions.
  • Tests: Body and title elements are inferred by default when there is a minimal-style HTML document created.
  • Moved to using Github Actions for our CI.

Database: Port in connection string

Published on by Greg Bowler

If a non-standard port was used, it would need to be set manually before the connection was made. This release includes it in the connection string by default, so changing the database port can be maintained exclusively within the config.ini of the project.

Database: Null checking for typed fetches

Published on by Greg Bowler

This patch improves a bug when dealing with typed fetches, such as $row->fetchDateTime("fieldName"). If the field was not set on the row, the typed fetch could return a default value rather than null. This has been fixed and null values are preserved, no matter what type is being returned.

Http: Further organisation of Http exceptions

Published on by Greg Bowler

This minor release simply adds an extra layer of organisation to the various HTTP exceptions relating to HTTP response statuses. The different exception types are now organised into Redirect (3XX), Client (4XX) and Server (5XX) namespaces.

DomTemplate: Bind keys of key-value-pairs to templates using unnamed bind parameters

Published on by Greg Bowler

Along with a dependency bump, this release brings the ability to bind the key of a key-value-pair data structure (such as an associative array) to a template element, with unnamed bind parameters.

Using the _key bind parameter will bind whatever the key is in a key-value-pair iterator. Nice for passing around associative arrays.

An example:

<ul>
  <li data-template> 
    Name: <span data-bind:text="_key">Person Name</span>, 
    Age: <span data-bind:text>0</span>
  </li>
</ul>

Http: Http status code exceptions

Published on by Greg Bowler

This release includes many exception classes: one for every HTTP status code. This will allow applications that utilise this repository as a dependency to throw and catch individual status codes by name, improving the execution model.

Installer: "Run" server on other ports and hostnames

Published on by Greg Bowler

The serve command has always had the ability to bind to a custom port and hostname with the -p|--port and -b|--bind arguments, and with this minor release, these two arguments have now been exposed on the run command.

To run your project on port 8765:

gt run -p 8765

Have fun!

Csrf: HTMLDocumentProtector returns token once generated

Published on by Greg Bowler

This library doesn’t get many releases because of it’s simplicity, but today we’re releasing a simple change as an improvement that WebEngine will take advantage of straight away.

The protectAndInject function of the HTMLDocumentProtector now returns the token it generates, which will be used to send the token as a response header in the WebEngine’s dispatcher.

The purpose of this change is simply to make client-side development slightly easier when dealing with CSRF tokens, specifically when making POST requests, such as when uploading a file using the browser’s fetch API.

Session: Destroy corrupt sessions

Published on by Greg Bowler

In the improbable (but possible) event that a session is corrupted (think load balanced app after being upgraded to new release), this release destroys the session and silently starts a new one.

With this release comes some improvements to the unit tests, see the commit history for more information.

Http: UriInterface compatibility for REQUEST_URI

Published on by Greg Bowler

The $_SERVER["REQUEST_URI"] value is now mapped with greater compatibility to Server::getRequestUri() by breaking down each parsed part of the URI, meaning you can now get access to the scheme, host, port, path and query string parts individually.

Session: SessionContainer and SessionArrayWrapper

Published on by Greg Bowler

One new class and an interface is provided in this release.

The SessionContainer interface defines extremely simple functionality: get, set, contains and remove functions. This interface is applied to the Session class and the contained SessionStore class.

Why introduce such a simple interface? This is so that other PHP.Gt applications built using WebEngine will be able to be build in a way that their components become inter-operable with other projects that do not use the PHP.Gt/Session functionality.

This is why the SessionArrayWrapper class has been introduced, which too also implements the SessionContainer interface. This class takes an array in the constructor and stores it internally by reference, which means projects that use the $_SESSION superglobal can now make use of PHP.Gt features, and vice-versa.

Cron: February update

Published on by Greg Bowler

Nothing exciting here, just an update to the dependencies and some tests for switching CI to Github Actions.

Database: Consistent collations

Published on by Greg Bowler

This minor release ensures that all MySQL connections are made in the same collation as the migrations are made in. This was only ever causing errors when working with variables in queries, and could be overcome in code, but has been fixed for convenience at the point that the connection is made.

DomTemplate: More improvements to handling empty data

Published on by Greg Bowler

There are two improvements to how empty datasets are treated in this release:

  1. When template elements are extracted from the document, but then are never bound to, the template parent elements have their innerHTML set to an empty string. A major benefit to this is that :empty is more reliable for using in CSS to display a message such as “This list has no entries yet”.
  2. Binding nested data where inner leaves are “empty” are treated in the same way when using bindNestedList as with bindList.

Have fun!

Build: Direct process execution

Published on by Greg Bowler

Since PHP 7.4, processes are no longer executed in a new subshell, which improves the mechanism of dealing with long-running processes. This release adopts this new change, through the use of PhpGt/Daemon.

DomTemplate: Binding an empty dataset respects :empty selector

Published on by Greg Bowler

If an element has no children, and bindList() is called, passing in an empty dataset, the element has its innerHTML set to an empty string to clear up any hanging text fragments. This means that now, CSS’s :empty pseudo-selector can be used to display an element differently when it has been bound with an empty dataset.

Dom: Optimised innerHTML

Published on by Greg Bowler

This release is very minor in scope, but has knock-on effects to DomTemplate, specifically PhpGt/DomTemplate#124

The changes in this release mean that setting an innerHTML of an empty string is much more efficient, and this can now be done on DocumentFragments too. Before, this would cause an exception, due to there not being a parent element.

Changes in DomTemplate are incoming so that binding an empty dataset to an list element will set the innerHTML to an empty string, which means that the :empty CSS selector will now be valid for empty lists.