Pragmatism in the real world

Globally overriding validation messages for ZF2 forms

One thing that I always do when creating a Zend Framework 2 form is override the validation messages for a number of validators – EmailAddress in particular. I recently decided that I should probably sort this one out once and be done with it. Turns out that it's quite easy assuming that you use the FormElementManger to instantiate your forms. All that I need to do is create my own validator classes that extend the… continue reading.

Creating a ZF2 form from config

I have a requirement to create a Zend\Form from a dynamically created array which means that I can't use the FormAbstractServiceFactory and so will use Zend\Form\Factory directly. If you need to override any form elements, validators or add new ones, then you'll need the correct plugin managers for the factory. The way to set this up is like this: $factory = new Factory(); $formElements = $this->serviceLocator->get('FormElementManager'); $factory->setFormElementManager($formElements); $inputFilters = $this->serviceLocator->get('InputFilterManager'); $factory->getInputFilterFactory()->setInputFilterManager($inputFilters); Your $factory is now… continue reading.

View status of all Vagrant environments

I've just upgraded to Vagrant version 1.6, and vagrant global-status is possibly my favourite new feature. This command lists all currently up Vagrant environments wherever they may be on your computer: $ vagrant global-status id name provider state directory ————————————————————————————– dbc7770 joindin virtualbox running /Users/rob/www/thirdparty/joindin-vm 0683c7a default virtualbox running /Users/rob/www/thirdparty/joindin-zs7 The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date. To interact with… continue reading.

Prefixing every key in a hash ref in Perl

I needed to prepend some text to every element in a Perl hash ref, so I came up with: $hashref->{"prefix_$_"} = delete($hashref->{$_}) foreach (keys %$hashref); which prefixes each key of $hashref with "prefix_". After talking it over with Cliff, he was concerned with modifying the list in place while simultaneously iterating over it and suggested this solution: %$hashref = map { +"prefix_$_" => $hashref->{$_} } keys %$hashref; One interesting thing about this solution is the… continue reading.

Z-Ray for Zend Server 7

I see that Zend Server 7 has now been released. I've been running the beta for all my development work for a while now and the main reason is the new Z-Ray feature. Z-Ray is a bar that is injected into the bottom of your page showing lots of useful information. This is what it looks like in its closed state when run on my development version of joind.in: At a glance, I can see… continue reading.

Privilege

If ever there was a word to make someone defensive, it's privilege. You are brought face to face with the fact that someone else doesn't have the same experiences in life as you and that their experiences somehow make their life harder than yours. I am one of the most privileged people I know. I am a well-educated European white man. I was raised in a loving, stable home. I have a loving, stable relationship… continue reading.

Missing mime-info database for use with File::MimeInfo

A requirement I have on a current project means that I need to determine the mime type of a file I load from disk. One way to do this is to use the File::MimeInfo::Magic CPAN module like this: use File::MimeInfo::Magic; my $mime_type = mimetype($path_to_file); However, on OS X, an error was raised: WARNING: You don't seem to have a mime-info database. The shared-mime-info package is available from http://freedesktop.org/ . The easiest way to solve this… continue reading.

Speaking at DPC & OSCON

Two conferences are coming up that I'm speaking at: The Dutch PHP Conference takes place in Amsterdam and this year is between June 26th and 28. I'm giving a tutorial with Matthew Weier O'Phinney on Apigility which will provide you with a full day's teaching on creating web APIs with Apigility. I'm also giving a talk called Creating Models discussing the options available when creating the model layer of a typical MVC PHP application. DPC… continue reading.

Styling a Chosen select to fit Bootstrap 3 better

One project that I'm currently working on is an internal business application that's using stock Bootstrap 3. I needed a searchable select box and Chosen fitted the bill, so I'm using that. However, the default styles for the Chosen select box differ slightly from Bootstrap. The most noticeable being the height of the control.

Perl syntax highlighting in Sublime Text 3

I'm currently writing a project in Perl for a client and have discovered that the default Perl syntax highlighting in Sublime Text is terrible. Fortunately, the community has stepped up and Blaise Roth has created the ModerlPerl package. Install via Package Control. To get all Perl files to open with the new syntax highlighter, use View > Syntax > Open all with current extension as… and select ModernPerl from the sub-menu.