Pragmatism in the real world

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.

Setup Doctrine Migrations to update MySQL timestamp on update

One project I'm working on uses MySQL exclusively and is also using Doctrine Migrations. I wanted to set up a column called updated that was automatically set to the timestamp of the last time the row was changed. This is done in SQL like this: CREATE TABLE foo ( id INT AUTO_INCREMENT NOT NULL, bar VARCHAR(100) NOT NULL, updated timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY(id) ); It's not quite obvious how to do… continue reading.

Shorter directory text in Bash prompt

Rather helpfully, David Goodwin left a comment about how he shortens the space taken up by the directory section of his terminal's PS1 prompt by using a Bash script to remove the middle portion. This is a really good idea, so I ported it into my PS1 set up which resulted in some rearranging and thought I'd share here as I modified for OS X and I don't want to lose it! The relevant portion… continue reading.