Pragmatism in the real world

Using Composer with shared hosting

I can't use Composer because I'm using shared hosting and don't have SSH I've seen this sentiment a few times now, so this seems like a good time to point out that you do not need SSH access to your server in order to use Composer. In fact, I don't run Composer on a live server (regardless of whether it's using shared hosting) and it's not on my list of things to do in the… continue reading.

Running Phan against Slim 3

Having installed Phan, I decided to use it against the upcoming Slim 3 codebase. Phan needs a list of files to scan, and the place I started was with Lorna's article on Generating a file list for Phan. I started by removing all the developer dependencies: $ composer update –no-dev and then built the file list for the vendor and Slim directories. I started by using Lorna's grep statement, but that found too many non-PHP… continue reading.

Installing Phan on OS X

I use Homebrew for my local PHP installation on OS X and am currently running PHP 7.0.0 RC8. Phan is a static analyser for PHP 7 which was written by Rasmus and then rewritten by Andrew Morrison. As it benefits from PHP 7's abstract syntax tree it can find all kinds of subtle errors, so I wanted to install it locally to have a play with it. I started by trying to install Phan into… continue reading.

Writing PSR-7 middleware

Within Slim 3's Request object, there's a method called getIp() which is determines the client's IP address. However it's rather simplistic and potentially risky as it checks the X-Forwarded-For header with no ability to ignore this header or whitelist whether we trust the final proxy in the chain. Determining the client's IP address is an ideal use-case for middleware as we can inspect the headers in the request and then set an attribute so that… continue reading.

Render an array based on accept header

I'm currently working on an API using Slim 3 and needed a generic way to render arrays to XML, JSON or HTML based on the Request's Accept header. This is just good practice. The Accept header is used by a client to specify the media types that it accepts. Therefore if our client would like XML, I'd like to give it XML. Similarly for JSON. I also like to support an HTML rendering on my… continue reading.

The beginner's guide to rebasing your PR

You've successfully created a PR and it's in the queue to be merged. A maintainer looks at the code and asks you to rebase your PR so that they can merge it. Say what? The maintainer means that there have been other code changes on the project since you branched which means that your branch cannot be merged without conflicts and they would like to you to sort this out. These are the steps you… continue reading.

The beginner's guide to contributing to a GitHub project

This is a guide to contributing to an open source project that uses GitHub. It's mostly based on how I've seen Zend Framework, Slim Framework and joind.in operate. However, this is a general guide so check your project's README for specifics. TL;DR Skip to the summary. Step 1: Set up a working copy on your computer Firstly you need a local fork of the the project, so go ahead and press the "fork" button in… continue reading.

Simple Ansible file for Z-Ray preview

Recently, Zend made available a Z-Ray Technology Preview which takes the Z-Ray feature of Zend Server and makes it stand-alone. This is very interesting as it means that I can run it with the PHP 5.6 on Ubuntu 14.04 LTS Vagrant set up that I prefer. I decided to create an Ansible playbook to install Z-Ray into my VM. The Z-Ray instructions are clear enough, so it was simply a case of converting them to… continue reading.

Improved error handling in Slim 3 RC1

From RC1 of Slim 3, we have improved our error handling. We've always had error handling for HTML so that when an exception occurs, you get a nice error page that looks like this: However, if you're writing an API that sends and expects JSON, then it still sends back HTML: At least we set the right Content-Type and status code! However, this isn't really good enough. We should send back JSON if the client… continue reading.

random_bytes() in PHP 5.6 and 5.5

Last week, I needed some random data and using the power of the PHP manual, came across random_bytes which does exactly what I need. However, it's PHP7 only. As I target both Linux and Windows, I needed to do a bit more work to get it working which was fine, but a minor nuisance given that I know that there's a better way in PHP7. Talking on the #joind.in IRC channel a few days later,… continue reading.