PHPNews

Generating training handouts for printing

When training, I like to provide my attendees with a printed copy of the slides with space next to each one to write notes. This handout has 4 slides to a page, along with a title page and I use pdfjam to create it. Pdfjam is a wonderful command line tool for manipulating PDFs and fits the bill perfectly for …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday December 6, 2017


Implementing CORS in Zend Expressive

On a recent project, I needed to implement CORS support for my Expressive API. The easiest way to do this is to use Mike Tuupola 's PSR-7 CORS Middleware . As this is a standard Slim-Style PSR-7 middleware implementation, we need to wrap it for Expressive, so we make a factory: App/Factory/CorsMiddlewareFacto…

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 15, 2017


Customising Whoops in Expressive

I find the Whoops error handler page in Expressive quite hard to read and particularly dislike that the error message displayed in the top left is hidden if it's more than a few words long. To fix this, I discovered that you can provide a custom CSS file to the PrettyPrintHandler and then override to your heart's …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 8, 2017


Using Docker to create a MySQL server

When working on test code on my computer, I usually use the built-in PHP server ( php -S ) which works nicely. Every so often, I need access to MySQL and I use Docker to temporarily create a MySQL server for me. This is how I do it. The magic command is: $ docker run --name mysql \ -e MYSQL_USER=rob -e …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday November 1, 2017


OuputBuffer Middleware for Expressive

When developing an Expressive application, if you use var_dump() , echo , print_r() , etc when you get this error: Fatal error: Uncaught RuntimeException: Output has been emitted previously; cannot emit response in /www/dev/rka/example-app/vendor/zendframework/zend-diactoros/src/Response/SapiEmitterTrait.php…

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 25, 2017


Displaying errors in Expressive with Twig

If you're not using the Whoops error handler with Expressive and are using the Twig renderer, then you are given no information about the problem that occurred, even in debug mode. To fix this, I changed error.html.twig to this: {% extends '@layout/default.html.twig' %} {% block title %}{{ status }} {{ …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 18, 2017


"Software architecture is failing" by Alex Hudson

Alex Hudson 's article, "Software architecture is failing" is a really interesting article and resonates with me as I come across this a lot. I recommend reading it. I'm very much in the camp of designing for the business requirements first and my biggest successes are the apps which solve my clients' problems. To …

Continue reading »

Written by Rob Allen - - Aggregated on Monday October 16, 2017


Pretty print curl -i

My favourite tool for working with APIs is curl and in particular, I like using the -I switch to view the status line and headers too: This generates an output that looks like this: $ curl -i https://api.joind.in HTTP/1.1 200 OK Date: Wed, 04 Oct 2017 09:51:46 GMT Server: Apache X-Powered-By: PHP/5.6.4 Acce…

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 11, 2017


Converting a Composer dependency to git for editing

I'm adding a new feature to ZF's Problem-Details component and it's easiest to do this within the context of the application I'm developing. The component lives in vendor/zendframework/zend-problem-details and was installed using composer require so doesn't have its own git repository as the distribution zip …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday October 4, 2017


Custom URLs for a Cloud Foundry application

Now that I have my application deployed to Cloud Foundry , I need it to work with my own domain, such as bookshelf.akrabat.com rather than slim-bookshelf.eu-gb.mybluemix.net . We can do this via the command line which is useful. To do this we need to create a domain and then we can create a route . Create …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday September 27, 2017


CORS and OpenWhisk web actions

By default, OpenWhisk will handle the relevant responses for CORS . Specifically, it will respond to an OPTIONS request with these headers: Access-Control-Allow-Origin: * Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH Access-Control-Allow-Headers: Authorization, Content-Type …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday September 20, 2017


CLI credentials for a Cloud Foundry database

If you need access to your Cloud Foundry database from the command line the easiest way to get a set of credentials is to create a service key . This is done using the command cf create-service-key {service-name} {key-name} . You can call the key anything, so to connect to my database that I created previously: …

Continue reading »

Written by Rob Allen - - Aggregated on Monday September 11, 2017


Using PostgreSQL with PHP in Cloud Foundry

Having successfully deployed a PHP application to Cloud Foundry , I needed a PostgreSQL database for persistent storage. I found Lorna Mitchell's Connecting PHP to MySQL on Bluemix helpful and this article expands on that information. I want to create a cloud-based PostgreSQL database and connect it to …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday September 6, 2017


Deploying a PHP application to Cloud Foundry

I recently had a requirement to deploy a Slim application somewhere. As I already have a Bluemix account, it seemed sensible to deploy it to their Application Runtimes service which is an installation of the Open Source Cloud Foundry project. This turned out to be quite easy, but there are a number of steps …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday August 30, 2017


Adding a user to your Bluemix space

I'm at the stage where I need to give another developer access to my IBM Cloud Functions actions. I'm not really an infrastructure person and I found the user management pages on the Bluemix console incomprehensible, so used the command line. This is how I did it so that I don't have to work it all out again. Add …

Continue reading »

Written by Rob Allen - - Aggregated on Friday August 25, 2017


Getting started with Serverless PHP

I've been interested in Apache OpenWhisk for a little while now and recently submitted a new feature to add PHP support to the project. As OpenWhisk is a serverless environment, most users do not run their own copy and instead use a commercial provider with IBMs Bluemix available now along with Adobes I/O …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday August 23, 2017


Logging in to Bluemix via wsk

To set up the authentication for the OpenWhisk cli tool wsk you do this: $ wsk property set --apihost {host} --auth {key} > /dev/null $ wsk property unset --namespace > /dev/null The host and key are provided to from your OpenWhisk supplier. For Bluemix OpenWhisk , you can find it by logging …

Continue reading »

Written by Rob Allen - - Aggregated on Wednesday August 9, 2017


Creating an OpenWhisk Alexa skill

In a previous post , I looked at the mechanics of how to create an Alexa skill to tell me which colour bin I needed to put out next. I'll now look at how I chose to implement it in OpenWhisk , using Swift. An Alexa skill consists of a number of intents and you register a single end point to handle them all. As …

Continue reading »

Written by Rob Allen - - Aggregated on Monday July 24, 2017


Getting started writing an Alexa Skill

We now have 4 Amazon Echo devices in the house, and, inspired by a demo LornaJane gave me at DPC , I have decided to write some skills for it. This article covers what I learnt in order to get my first Swift skill working. Our bins are collected by the council every other week; one week it's the green recycling …

Continue reading »

Written by Rob Allen - - Aggregated on Monday July 17, 2017