Pragmatism in the real world

Jerry-rigging pygments to support new PHP keywords

I use rst2pdf to create my presentations and noticed that the syntax highlighter wasn't highlighting instanceof. rst2pdf uses pygments for syntax highlighting, so I wondered what was going on. A short investigation led to me realise that the current stable version of pigments is 1.6 and they are working on 2.0. It seems that 2.0 has a number of changes to the PHP lexer, which aren't in 1.6. While I'm waiting, I modified my local… continue reading.

Context specific history at the bash prompt

One change I made recently to my .profile is this: # up & down map to history search once a command has been started. bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward' These two bind command change the way that the up and down arrow keys work once you start typing a command to only search the history for lines that start with what you've typed so far. This means that I type, say, git and then press ↑… continue reading.

Alias for the PHP built-in server

I keep forgetting the correct command line syntax for the PHP build-in server, so I've now made an alias for it in my .profile: alias phps='php -S 0.0.0.0:8888' Now I can simply type: phps public/index.php to start the built-in web server.

Setting up mailcatcher as a service in Debian/Ubuntu

I've recently been changing joind.in's Vagrant system to use Debian and one issue I came across was getting Mailcatcher to start on boot and integrate property with the service command. To do this, I created an init script which is based off the skeleton and then stored this in /etc/init.d and then ran update-rc.d mailcatcher defaults to set up the correct links in the various rc.d directories. This is the init script: /etc/init.d/mailcatcher: #! /bin/sh… continue reading.

Codes of conduct

As my mind turns towards the conferences that I'm attending this autumn, I came across Why you want a code of conduct & how we made one by Erin Kissane. I highly recommend that you read it and the links within it. The part that struck me most was the thoughts on a plan of action. It's all very well to have a code of conduct, but if the event's organisers haven't got a plan… continue reading.

Using ZF2 Forms with Twig

Following on from looking at how to integrate Zend Framework 2 forms into Slim Framework, let's look at the changes required if you also happen to want to use Twig. When it comes to rendering the form, we would want our template to look like this: <form method="POST" role="form"> <div class="form-group"> {{ formRow(form.get('email')) }} </div> {{ formElement(form.get('submit')) }} </form> The ZF2 view helpers, formRow and formElement now look like Twig functions, however we don't want… continue reading.

Sending attachments in multipart emails with Zend\Mail

I've written before about how to send an HTML email with a text alternative in Zend\Mail, but recently needed to send an attachment with my multipart email. With help from various sources on the Internet, this is how to do it. use Zend\Mail\Message; use Zend\Mime\Message as MimeMessage; use Zend\Mime\Part as MimePart; use Zend\Mime\Mime; use Zend\Mail\Transport\Sendmail; function sendEmail($to, $from, $subject, $html, $text, $attachments = null) { $message = new Message(); $message->addTo($to); $message->addFrom($from); $message->setSubject($subject); // HTML part… continue reading.

Throw an exception when simplexml_load_string fails

I keep having to look up how to stop the warning that are emitted when simplexml_load_string & simplexml_load_file fail, so this time I've written the world's simplest little class to take care of it for me from now on: <?php namespace Rka; use UnexpectedValueException; class Xml { /** * Load an XML String and convert any warnings to an exception * * @param string $string * @param string $class_name * @param int $options * @param… continue reading.

Redirecting in Slim 2 Middleware

I recently ran into a problem with calling redirect() in a Slim Framework 2 middleware class, so I thought I'd better document the solution so that I remember in future! The authentication middleware looks roughly like this: class Authentication extends \Slim\Middleware { public function call() { if (!$this->isLoggedIn()) { $app = \Slim\Slim::getInstance(); $app->redirect($app->urlFor('login')); } $this->next->call(); } // other methods… } The problem is that you can't call $app->redirect() in Middleware as redirect() is designed to… continue reading.

Integrating ZF2 forms into Slim

Let's say that you want to use Zend Framework 2's Form component outside of ZF2 itself. In this case, a Slim application. It turns out that Composer makes this quite easy, though there's quite a lot of code involved, so this is a long article. Start with a really simple Slim Application. index.php: require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->map('/', function () use ($app) { $app->render('home.php', array( 'form' => $form )); })->via('GET', 'POST'); $app->run(); templates/home.php:… continue reading.