Pragmatism in the real world

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.

Run Slim 2 from the command line

If you need to run a Slim Framework 2 application from the command line then you need a separate script from your web-facing index.php. Let's call it bin/run.php: bin/run.php: #!/usr/bin/env php <php chdir(dirname(__DIR__)); // set directory to root require 'vendor/autoload.php'; // composer autoload // convert all the command line arguments into a URL $argv = $GLOBALS['argv']; array_shift($GLOBALS['argv']); $pathInfo = '/' . implode('/', $argv); // Create our app instance $app = new Slim\Slim([ 'debug' => false,… continue reading.

Ally

One thing I've noticed as I try to learn how to become more aware of the diversity issues in my world is that it's really hard for someone to "get it" if they don't "live it". I think this occurs at all levels. For my position in society, I don't get how it feels to be a black man with the constant assumption that "I'm up to no good". Similarly, I lack that fundamental understanding… continue reading.

Convert PHP Warnings and notices into fatal errors

Xdebug version 2.3 was released last week and includes a feature improvement that I requested back in 2013! Issue 1004 asked for the ability to halt on warnings and notices and I'm delighted that Derick implemented the feature and that it's now in the general release version. It works really simply too. Turn on the feature by setting xdebug.halt_level either in your php.ini or via ini_set(): <?php ini_set('xdebug.halt_level', E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE); Now cause a warning: <?php echo… continue reading.

Git submodules cheat sheet

Note: run these from the top level of your repo. Clone a repo with submodules: $ git clone git@bitbucket.org:akrabat/dotvim.git .vim $ git submodule update –init View status of all submodules: $ git submodule status Update submodules after switching branches: $ git submodule update Add a submodule: $ git submodule add git://github.com/tpope/vim-sensible.git bundle/vim-sensible Update all submodules to latest remote version $ git submodule update –remote –merge $ git commit -m "Update submodules" Update a specific submodule… continue reading.