Pragmatism in the real world

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.

Routing to a controller with Slim 2

In a couple of projects that I've written using Slim Framework 2, I've found it beneficial to organise my code into controllers with injected dependencies; probably because that's how I'm used to working with ZF2. To make this easier, I've written an extension to the main Slim class and packaged it into rka-slim-controller which will dynamically instantiate controllers for you for each route. Defining routes is exactly the same as normal for a Slim controller,… continue reading.

Sending test emails from PHP

I've written before about redirecting email while developing using a trap mail script on my development system. Other people also like MailCatcher. I've recently switched to using a simple PHP script that creates a elm file on disk that can be opened by Apple's Mail client. This solution is much faster as there is no SMTP processing involved. Adam Royle came up with this solution in his article Setup a testing mail server using PHP… continue reading.

Customising Bootstrap 3

I'm sure everyone already knows this, but it turns out that you can customise Bootstrap 3 without having to understand Less. Part of the reason that I didn't realise this is that I run my web browser windows quite small and regularly don't see the main menu of getbootstrap.com as it's hidden being the "three dashes" button. However, there's an option called Customize on it. This page gives you a massive form where you can… continue reading.

Dependency injection in Slim framework 2

Slim framework comes with a Dependency Injection container called Set. The basics The DIC is accessed via the container property of $app. To set, you use the set() method: $app->container->set('foobar', function() { return new Foo\Bar(); } ); If you need a given resource to be shared, then use the singleton method: $app->container->singleton('foobar', function() { return new Foo\Bar(); } ); And then to retrieve from the container, there are multiple ways to do it: $fooBar =… continue reading.