Pragmatism in the real world

Turn warnings into exceptions

As I keep looking this up in other projects that I've written, I'm putting it here so I can find it more easily. There are a number of built-in PHP functions that generate a notice or warning that you can't turn off when something goes wrong, such as parse_ini_file and file_get_contents. One common solution to this is to suppress using the @ operator: $result = @file_get_contents($url); if (false === $result) { // inspect error_get_last() to… continue reading.

A Slim3 Skeleton

Warning Slim 3 is currently under active development. Expect BC breaks! I'm creating a number of projects in Slim 3 (which is currently under development) at the moment in order test things out and found that I was setting them up in essentially the same way. To save me having to do this each time, I've now created a skeleton project that is set up with the directory structure that I like and also includes… continue reading.

Role models

Wikipedia defines a role model like this: A role model is a person whose behavior, example, or success is or can be emulated by others All my life, I have identified people that I perceive to be a little better than I am in some facet of life that I want to get better at and I emulate them. I've been doing this all my life. They have been my role models. My first recollection… continue reading.

Styling rst2pdf tables

I currently use rst2pdf to create presentations slide decks from reStructured Text files. I like rST a lot as it's more expressive than Markdown and allows for extension. Tables in rST are marked up like this: +———–+———–+———–+ | Heading 1 | Heading 2 | Heading 3 | +===========+===========+===========+ | a | b | c | | | | | | aa | | | +———–+———–+———–+ | d | e | f | +———–+———–+———–+ | g… continue reading.

ZF2 validator message keys

In Zend Framework 2, if you define your input filter via configuration, then you can override validation messages using a format along the lines of: <validators> <notEmpty> <messages> <isEmpty>Please provide your telephone number</isEmpty> </messages> </notEmpty> </validators> Setting the message is easy enough, once you have the correct key name. This is a list of all the keys for the standard validators: Validator Key name Default message Alnum alnumInvalid Invalid type given. String, integer or float… continue reading.

Using Zend\Config with a Slim app

Sometimes you need more configuration flexibility for your application than a single array. In these situations, I use the Zend\Config component which I install via composer: composer require "zendframework/zend-config" This will install the Zend\Config component, along with its dependency Zend\Stdlib. Let's look at a couple of common situations. Multiple files It can be useful to to split your settings files out for administrative or environment-specific reasons. To set up within a Slim application, you do… continue reading.

installing XHGui via Ansible

I'm still using Ansible to provision Vagrant VMs. This is how I added the XHGui profiler to my standard setup. Theres a number steps we need to do: Install Composer Install the uprofiler PHP extension Install XHGui Set up for profiling Set up host for XHGui website Install Composer Installing Composer requires these tasks: – name: Install Composer shell: curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin creates=/usr/local/bin/composer – name: Rename composer.phar to composer shell: mv… continue reading.

Logging errors in Slim 3

Slim Framework 3 is being actively developed at the moment and has a number of changes in it, including the use of the Pimple DI container and an overhaul of pretty much everything else! In this post, I'm going to look at error handling. The default error handler in Slim 3 is Slim\Handlers\Error. It's fairly simple and renders the error quite nicely, setting the HTTP status to 500. I want to log these errors via… continue reading.

Building and testing the upcoming PHP7

The GoPHP7-ext project aims to ensure that all the known PHP extensions out there work with the upcoming PHP 7. This is non-trivial as some significant changes have occurred in the core PHP engine (related to performance) that mean that extensions need to be updated. In order to help out (and prepare my own PHP code for PHP 7!), I needed the latest version of PHP7 working in a vagrant VM. Fortunately Rasmus has created… continue reading.

WordCamp London, 2015

One of my recent goals has been to attend different conferences from the PHP-community-centric ones that I usually attend. I want to expose myself to different ideas, mindsets and communities. To this end, I attended WordCamp London last weekend and had a blast. Everyone I spoke to was enthusiastic, friendly and welcoming which made for a very pleasant weekend and the selection of talks meant that I managed to learn about WordPress too! The first… continue reading.