Developing software in the Real World

Stand-alone usage of Zend-InputFilter

Any data that you receive needs to be checked and validated. There are number of ways to do this including PHP's filter_var, but I prefer Zend-InputFilter. This is how to use it as a stand-alone component. Installation Firstly, we install it using Composer: $ composer require zendframework/zend-inputfilter $ composer require zendframework/zend-servicemanager You don't have to have ServiceManager, but it makes working with InputFilter much easier, so it's worth installing. Create the InputFilter The easiest way… continue reading.

Rendering problem details in Slim

As I've already noted, in the project I'm currently building, I'm rendering errors in my Slim Framework API using RFC 7807: Problem Details for HTTP APIs via Larry Garfield's ApiProblem component and rka-content-type-renderer. One place where we need to integrate this approach into Slim is in the error handlers. Let's look at NotFound. To ensure that we return a response in the right format, we need to implement our own NotFound handler: src/App/Handler/NotFound.php: <?php namespace… continue reading.

Rendering ApiProblem with PSR-7

In the API I'm currently building, I'm rendering errors using RFC 7807: Problem Details for HTTP APIs. As this is a Slim Framework project, it uses PSR-7, so I updated rka-content-type-renderer to support problem. RFC 7807 defines a standard for sending details of an error in an HTTP response message. It supports both XML and JSON formats. From the RFC, an example response is: HTTP/1.1 403 Forbidden Content-Type: application/problem+json Content-Language: en { "type": "", "title":… continue reading.

A note on framework performance

A question came up recently wondering why Slim Framework was around 5 times slower than plain PHP. All frameworks are by definition slower than no-code as there's more going on. i.e. an index.php of: <?php header('Content-Type: application/json'); echo json_encode(['result' => 1]); is going to be much faster than a Slim application with this code: use \Slim\App; include 'vendor/autoload.php'; $config = include 'Config/Container.php'; $app = new App($config); $app->get('/do-it', function($request, $response){ return $response->withJson(['result' => 1]); }); $app->run();… continue reading.

Homestead per-project crib sheet

I wanted a drop-dead simple way to try and replicate a problem someone was having on the Slim forums. I couldn't reproduce with php -S which is my go-to for this sort of thing, so I thought I'd try Homestead. I had recently listend to a Voices of the Elephpant episode with Taylor Otwell & Joe Ferguson where Joe mentioned that Homestead worked on a per-project basis too. I didn't know this, so tried it… continue reading.

Using CharlesProxy's root SSL with home-brew curl

Once I installed Homebrew's curl for HTTP/2 usage, I discovered that I couldn't automatically proxy SSL through Charles Proxy any more. $ export HTTPS_PROXY=https://localhost:8888 $ curl curl: (60) SSL certificate problem: self signed certificate in certificate chain More details here: curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the… continue reading.

Using HTTP/2 with PHP 7 on Mac

if you want to use HTTP/2 with PHP on OS X, you need a version of curl compiled with HTTP/2 support. You can then link your PHP's curl extension to this version. The easiest way to do this is to use Homebrew:

At the time of writing, this will install PHP 7.0.10 with Curl 7.50.1:

Using Curl on the command line If you want to use your shiny new curl from the command… continue reading.

Passing on the baton

Lorna Mitchell has posted Needs Help: For the last 6 years I've been a maintainer of this project, following a year or two of being a contributor. Over the last few months, myself and my comaintainer Rob Allen have been mostly inactive due to other commitments, and we have agreed it's time to step aside and let others take up the baton. I'm proud of my contributions to as a contributor and maintainer.… continue reading.

Checklist for releasing Slim

Release process for Slim so that I don't forget any steps; based on a check list created by Asgrim. I should probably automate some of this! Preparation: Ensure all merged PRs have been associated to the tag we're about to release.Find them via this search: [is:pr is:closed no:milestone is:merged]. Close the milestone on GitHub. Create a new milestone for the next patch release. Ensure that you have the latest master & that your index is… continue reading.

Standalone Doctrine Migrations redux

Since, I last wrote about using the Doctrine project's Migrations tool independently of Doctrine's ORM, it's now stable and much easier to get going with. Installation and configuration As with all good PHP tools, we simply use Composer:

This will install the tool and a script is placed into vendor/bin/doctrine-migrations. To configure, we need to add two files to the root of our project: migrations.yml:

This file sets up the default configuration for… continue reading.