-
Find Mongo Document By ID Using The PHP Library
09 June 2016
Read moreMy new job as a Developer Advocate with IBM means I get to play with databases for a living (this is the most awesome thing ever invented, seriously). On my travels, I spent some time with MongoDB which is a document database - but I ran into an issue with fetching a record by ID so here's the code I eventually arrived at, so I can refer to it later and if anyone else needs it hopefully they will find it too.
-
Simple Access Control for CakePHP3
11 April 2016
Read moreThe newest version of CakePHP doesn't ship with built in ACL, which means you need to write your own. Personally I think this is a smart move, having looked at the one-size-fits-all solutions for previous versions of the framework and knowing that every system has different requirements, this version has good hooks and documentation on how to add something that works for your application. I thought I'd share what worked for mine.
-
Change Form Input Type in CakePHP3
16 March 2016
Read moreI've been having my first experiences with generated code, generating a new admin backend using CakePHP3 (yes CakePHP is still around, it's alive and doing rather well in fact!). So far it's going great and producing a much more complete solution than I'd have managed for myself on this timescale.
One thing is bothering me though: it guesses form input types from the database column types, which mostly works well but sometimes it picks something that doesn't reflect the way that the user will store information in this field. It's actually pretty easy to change the forms that get generated though, so here's an example.
-
PHP 7.0 (and 5.6) on Ubuntu
11 February 2016
Read morePHP 7 is released but for those of us who don't usually compile our own PHP, it can be a long wait for our preferred distro to release the packages we want. For Ubuntu, I'm using a PPA which allows both PHP 5.6 and PHP 7.0 to be installed, including things like extensions, at the same time. It was very easy to set up (I'm running Ubuntu 15.10 but this process should also work on older versions back to at least 14.04 which is the previous LTS) so here's a quick walkthrough of what I did.
-
Handling Composer "lock file out of date" Warning
22 January 2016
Read moreComposer is dependency management for PHP, and it consists of two main files:
composer.json where you specify your dependencies
composer.lock where composer itself records exactly which precise version of every library and every dependency of every library it picked, so all installs will be identical
Crucially, the composer.lock also includes a hash of the current composer.json when it updates, so you can always tell if you've added a requirement to the composer.json file and forgotten to install it.
-
PHP Web Services: 2nd Edition
20 January 2016
Read moreI'm delighted to announce that the second edition of PHP Web Services is published! This isn't an entirely new book but in my own biased opinion it is a much better job of this topic than I did the first time around :) Following from the feedback we got on the …
-
Upgrade To Better Passwords in PHP
11 January 2016
Read moreThe password features in PHP aren't exactly new, but I see lots of applications from "before" which aren't being migrated to better practices. I have some strategies for doing these migrations so I thought I'd share my main approach, plus a similar-but-different one I saw in the wild (OK it was in CakePHP, so not too wild!).
-
OAuth2 with PHP's built in Streams Functions
07 January 2016
Read moreMost of the time when I work with APIs from PHP, I use Guzzle - it's awesome and modern and elegant. However some of my work is with legacy platforms and I recently had a situation where we needed to integrate with a API using OAuth2, and launch that integration before …
-
Relying on A Dev-Master Dependency in Composer
22 December 2015
Read moreI recently tweeted this:
If your project installation instructions recommend requiring dev-master in composer, I may need to reconsider my choice of package
— Lorna Mitchell (@lornajane) December 2, 2015
-
Insert Data with Phinx
18 December 2015
Read moreDatabase patching is a wicked hard problem, one that's got a bit easier in my world lately as I've been using Phinx on a few projects. I like Phinx because it avoids the numbered-patches problem by using date stamps as part of its patch naming and it is pretty smart about creating the correct forward and backward changesets from a single change() description.
One thing I didn't immediately find was how to insert data.
-
Generating a File List for Phan
27 November 2015
Read morePhan is the PHP Analyzer for PHP 7 code. I've been using it, partly out of curiosity, and partly to look at what the implications of upgrading my various projects will be. The simplest usage instructions are:
phan -f filelist.txt
I generated my filelist.txt files with …
-
PHP: Calling Methods on Non-Objects
19 October 2015
Read morePHP has subtly changed the wording of this error between various versions of the language, which can trip up your log aggregators when you upgrade so I thought I'd give a quick rundown of the changes around the "call to member function on non-object" error in PHP, up to and including PHP 7 which has an entirely new error handling approach.