PHP.GT

Latest releases

Database: Type safe fetching

Published on by Greg Bowler

This release introduces the ability to fetch single columns from the database in a type-safe way. If your query only selects one column, you can fetch it using the newly introduced type-safe functions:

  • fetchBool / fetchAllBool
  • fetchString / fetchAllString
  • fetchInt / fetchAllInt
  • fetchFloat / fetchAllFloat
  • fetchDateTime / fetchAllDateTime

Along with the above, the type-safe Row function getDateTime allows the returning of nullable fields, which removes an unintended strict rule introduced in the last release.

Http: Case-insensitive headers

Published on by Greg Bowler

This minor release brings case-insensitivity to all use of headers. This only makes a difference when working with headers set from the $_SERVER["HTTP_*"] variables, which include uppercase, underscore-separated values.

DomTemplate: Multiple parameter placeholders

Published on by Greg Bowler

This release is a bugfix that resolves an issue when multiple placeholders were present within the same attribute, using {curlyBrace} syntax.

The issue that has been resolved affected links with multiple paramters bound at once, for example, <a href="/user?id={userId}&type={userType}">Example</a>

Dom: Element improvements and debugging

Published on by Greg Bowler

Unit test coverage on the Element class is now improved to 100%, thanks to @Jelmergu.

The Element class has been improved to take advantage of the new CssXPath updates, along with fixing getter/setter for the value attribute, and a check for the property map constant which improves working with non-html documents such as XML.

DomTemplate: Implicit binding using bindData function

Published on by Greg Bowler

When passing data to the bindData function of Bindable Elements, it has always been required for the data to be a key-value pair structure, or an object that implements BindDataMapper/Getter.

Now it is possible to pass any string-like value into bindData, and DomTemplate will attempt to perform implicit binding (binding to the DOM without using a named key).

DomTemplate: Minor improvements

Published on by Greg Bowler

  • Document fragments are used when binding lists for efficiency.
  • Return type of BindDataMapper can be any iterable object.
  • BindDataGetter allows functions to be prefixed with “bind” rather than “get”.
  • Various PHPDoc comments have been overridden so allow IDEs to understand that DomTemplate versions of Nodes, Elements, Documents, etc. are being returned.
  • A few small code refactorings which do not affect functionality.

DomTemplate: Consolodate bindList and bindNestedList

Published on by Greg Bowler

Functionality of these two functions is too similar to justify having two separate functions. This release is backwards compatible - simply wrapping the functionality of bindNestedList into bindList, and bindNestedList is now currently deprecated. The function will be removed in v2 release, with all functionality handled within the bindList function.

DomTemplate: Boolean attribute binding

Published on by Greg Bowler

For attributes that don’t have a value, like disabled, selected, checked, etc. a new bind rule is added in this release, meaning the attribute will be added if a boolean condition is met.

The attribute value is marked with a preceding question mark. For example: <input type="checkbox" data-bind:checked="?isChecked" />

Small but powerful when working with large repeating datasets.

Have fun and stay productive!

Database: Row type safety

Published on by Greg Bowler

The Row object is the most basic object your application will deal with when working with the database. A collection of getter functions has been added to Row in this release, which allow working with type-safe data from the database, without introducing any backwards breaking changes.

The functions are simple, but powerful:

  • getInt
  • getString
  • getFloat
  • getBool
  • getDateTime

They are pretty self-explanatory and available right away.

Have fun and stay productive!

Installer: CPU efficiency

Published on by Greg Bowler

Running any long-running WebEngine commands is done within an infinite loop to allow the sub-processes to output their content to the terminal. This was a hog on the CPU, and required a microsleep between loop iterations. Simple fix with no backwards-breaking changes.

Dom: Improved Element value getter/setter

Published on by Greg Bowler

The value property of Elements is made more consistent in this release. Certain element types behave differently when getting or setting the value property - some access the value attribute directly, others affect the state of their children.

CssXPath: August 2019 bugfixes

Published on by Greg Bowler

This release contains a number of bugfixes:

  • Bugfix for selecting children of attribute selector. The bug meant that the selector context was reset to the documentElement when in a deeper query than selecting attribute values.
  • Update DOM dependency fixing issue with iterators in tests. Iterating over HTMLCollections is only one method of working with HTMLCollections. Asking for the current() item would use the iterator but it would throw a RunTime exception if the iterator wasn’t rewound.
  • Expose other attribute selector types. There are many types of attribute selector. Now these types are defined as constants in the Translator.
  • More descriptive variable names.

Dom: PSR-7 Interoperability

Published on by Greg Bowler

The PSR-7 StreamInterface has been implemented on the Document/HTMLDocument classes to improve interoperability when used within other frameworks. There is no new functionality due to this, so only a minor version increment is necessary.

Along with the interface implementation, a couple of bugfixes are released here too:

  • Rewind HTMLCollection iterators before use, to avoid throwing a RunetimeException when used outside of a foreach.
  • Don’t format the HTML output at document render. There will be some efficiency gains here on large document trees.

Dom: August 2019 bugfixes

Published on by Greg Bowler

No new features in this release, just a selection of bugfixes and improvements.

  1. Fix problem where attribute value contains comma - it’s possible to use a CSS selector that contains a comma in the actual selector. Previously the CSS to XPath translator was splitting queries based on the comma character with no context as to where the comma appeared in the string. This improvement checks to see if the comma is within a quoted string, and if so, treats it as part of a selector.
  2. Test innerHTML does not encode JSON with HTML encoding - Harden tests around unicode support with the innerHTML property.
  3. Default value getter/setter property - The value property of Elements should behave differently if the element can represent a value, such as input, option, etc. This change improves the use of shorthand value property, rather than having to use getAttribute/setAttribute.

CssXPath: Regular expression splitting multiple queries

Published on by Greg Bowler

Multiple CSS selectors can be present within the same query like this: div>a, div>li>a, and a simple explode() was being called to split the strings. However, this caused an issue when one selector was looking for an attribute selector whose value contained a comma.

To solve this, a regular expression has been used to split only commas that are not surrounded by quotes.

DomTemplate: Efficiency improvement

Published on by Greg Bowler

This release changes the internal mechanism for binding lists to the DOM. Rather than appending Elements to the DOM tree in-place, a list is built up in a separate DocumentFragment, and once complete, the fragment is appended to the ParentNode, greatly improving page render speeds on complex documents with many nodes.

Another efficiency improvement is the addition of data-bindparameter` attribute, which now must be added to any Element that will have its parameters bound inline, using curly braces. This is a small backwards breaking change, hence the minor version increment, as before any parameters containing curly braces would be automatically bound.

Dom: Efficiency improvements

Published on by Greg Bowler

This release is minor in footprint, but potentially major in efficiency increase. This is only noticable on large trees, but when you have thousands of Nodes in a Document, you can cut the page render time in half.

Main improvements lie in the iteration of NodeList objects. There is also improvement to the distinction between a NodeList and HTMLCollection (HTMLCollection objects can only contain Elements, not Nodes).

Dom: Bugfix

Published on by Greg Bowler

This release fixes an issue when getting the value attribute of a select element.

DomTemplate: DataBindMapper and DataBindGetter interfaces

Published on by Greg Bowler

The introduction of the two new interfaces DataBindMapper and DataBindGetter allow the developer to state that a class can be used in the DomTemplate bind functions, without having to expose the data as public properties.

DataBindMapper defines a function, dataBindMap which must return an associative array, and will be called in the bind process.

DataBindGetter does not define any functions, but instead indicates to DomTemplate that the class should have its get* functions called for any keys that are bound. For example, binding a key of id will try to call the getId function on the class.

Sync: Bin script exposed

Published on by Greg Bowler

For easy use of the sync functionality, installing this repo via composer will now link the sync bin script into the vendor/bin/ directory. The autoloader has been simplified too along with a few bumps in dependencies.

DomTemplate: Less strict types

Published on by Greg Bowler

With a small bump of dependencies, this release contains only one minor change: the ability to pass bound keys and values as null. When a null value is bound, it is treated as an empty string.

Cookie: Cookie::__toString

Published on by Greg Bowler

A simple release, but one that includes a missing feature: the ability to pass Cookie objects into functions that typehint string parameters.

Also:

  • Faster unit test execution
  • No development dependencies (cleaner tree, faster install)