Pragmatism in the real world

Step-debugging linked composer dependencies with PhpStorm

One project I'm working on has multiple separate parts in different git repositories that are brought into the main project using linked composer directories. I needed to get step debugging working in PhpStorm and this is the approach I took.

Recursive PHP lint

There are many scripts that recursively execute php -l on a set of files or directories. This is mine: #!/usr/bin/env bash set -o nounset # Recursively call `php -l` over the specified directories/files if [ -z "$1" ] ; then printf 'Usage: %s …\n' "$(basename "$0")" exit 1 fi ERROR=false SAVEIFS=$IFS IFS=$'\n' while test $# -gt 0; do CURRENT=${1%/} shift if [ ! -f $CURRENT ] && [ ! -d $CURRENT ] ; then echo… continue reading.

Validating default PHP session ID values

I recently needed to validate the value created by PHP for its session ID. After a bit of research, I realised that there are two interesting php.ini config settings that relate to this value: session.sid_length is the number of characters in the ID session.sid_bits_per_character controls the set of characters used. From the manual: The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ","). Therefore, to validate the session… continue reading.

Routing in Slim 4

Routing in Slim 4 works pretty much exactly the same as in Slim 3. They are used to map a URL that the browser requests to a specific handler that executes the code for that particular page or API endpoint. You can also attach middleware that will only be run when that route is matched. The route in the slim4-starter looks like this: $app->get('/[{name}]', HomePageHandler::class); It is made up of the method, the pattern and… continue reading.

Changing an SQL Server primary key in Doctrine Migrations

I recently came across a rather weird quirk when trying to change a primary key in Sql Server using Doctrine Migrations: you need to use two migrations to get it to work. This is incredibly minor and I'm only writing it up as it confused me for a while so I thought that I'd document so that I'll find this article if I run across it again in the future! This is the migration: final… continue reading.

Testing migrating to Laminas

Zend Framework is renaming to Laminas and all the source code is moving to a new GitHub organisation. Implicitly this means a new PHP top level namespace. As you can imagine, this implies that a lot of our code will need to change, so Matthew, Michał and the team have been writing migration tooling to make this easier. It's now time to test it and they need all the help they can get on real-world… continue reading.

Embedding Notist slides

This site uses WordPress under the hood as I find the flexibility that a good CMS provides quite useful. For the talks section, I use a custom post type so that I can set additional properties on the post and customise the display. With my usual lack of imagination, my custom post type is called talk. When Notist was released, I've been uploading the PDFs for my presentations there so that I have a nicely… continue reading.

Custom error rendering in Slim 4

One of the nice things about Slim 4 is that it's easier to customise the HTML generated on error without having to worry about the rest of the error handling mechanism. This is because we have separated error rendering from error handling. Slim's default ErrorHandler maintains a list of renderers, one for each content-type and will delegate the creation of the error payload (HTML, JSON, XML, etc) to the renderer. Out of the Box, the… continue reading.

Dependency Injection in Slim 4

In contrast with Slim 2 and Slim 3, Slim 4 does not ship with a DI container, but instead, supports any PSR-11 compatibly DI container that you provide. This is part of Slim 4's commitment to interoperability via the PHP-FIG standards. The easiest way to add a container to your Slim application is to call AppFactory::setContainer() before you call AppFactory::create(). The setContainer() method expects any PSR-11 container. Register the container with Slim Let's look at… continue reading.

Running Slim 4 in a subdirectory

If you want to run Slim 4 in a subdirectory of your website, then you have a few things you need to do. Let's consider the situation: Your main website is in the directory /var/www/html and is accessed at https://example.com/. You want your new Slim 4 app to be in the directory /var/www/html/myapp and to be accessed at https://example.com/myapp. Your Slim 4 index.php file is stored in /var/www/html/myapp. There are two things you need to… continue reading.