I had a problem writing to the cache directory in my vagrant project due to file permissions. Fortunately Jeremy Kendall has already solved this problem in his Vagrant Synced Folders Permissions article.
I’ve been thinking recently about using immutable objects for some of my model-layer entities. That is, an object that cannot be changed once it is created.
Immutable objects have a number of benefits including the fact that they are much easier to understand, simple to use and very easy to test. The main motivation for me is that an immutable object is very predictable as it’s state doesn’t change. This means that any calculated properties can be done once on creation. This is interesting as one application that I’m currently working on has a lot of calculated properties and it’s a source of bugs when one property changes and all the dependent calculations aren’t always done.
I was having a discussion on IRC about use statements and whether they improved code readability or not.
Consider this hypothetical code:
$cache = new \User\Service\Cache(); $mapper = new \User\Mapper\User($cache) $form = new \User\Form\Registration($mapper); $form->process($request->getPost());
use User\Service\Cache; use User\Mapper\User; use User\Form\Registration; // other code $cache = new Cache(); $db = new User($cache) $form = new Registration($mapper); $form->process($request->getPost());
The first snippet is completely unambiguous at the expense of verbosity. Those longer class names make it a little hard to quickly parse what it going on. The second is clearly less cluttered, but is at the expense of ambiguity. Exactly what class is User? I would have to go to the top of the file to find out. Should I use aliases? If so, how should I name them?
On the 26th January, I fell off a skateboard, dislocating & fracturing my left elbow. A trip to A&E that Sunday resulted in hospital admittance on Monday and surgery on Tuesday.
This was the first time I’ve been admitted to hospital for an overnight stay and I found the whole process fascinating, but not something I ever want to repeat. I also can’t say enough good things about the staff at Worcester Royal Hospital. Everyone I interacted with was friendly, helpful and competent.
Once you have the basic installation, you need to put it in development mode:cd path/to/install php public/index.php development enable # put the skeleton in development mode
As 2013 finishes, I continue my tradition of showing off some photos that recap my year. Last year I discovered that I didn’t take many photos at all, so this year I’ve published at least one photo every day! A lot of them were rubbish, but a good number are shots that I’m very pleased with. Continue reading
One feature I found out about recently is that you can install packages globally rather than locally into your project. I think that this is most useful for development tools, such as PHPUnit which are then available everywhere.
A few days ago, techPortal published my tutorial Create a RESTful API with Apigility.
Apigility was announced at ZendCon US in October 2013 and I think that it looks like a useful tool for creating APIs. I particularly like that versioning is built in from the start and that it handles content negotiation.
If you want to learn about Apigility, then have a read. The source code is available on GitHub.
With OS X 10.9 Mavericks, Apple chose to ship PHP 5.4.17. This is how to set it up from a clean install of Mavericks.
Note: If you don’t want to use the built-in PHP or want to use version 5.5, then these are some alternatives:
- PHP 5.3/5.4/5.5 for OS X 10.6/10.7/10.8/10.9 as binary package by Liip
- Zend Server (Free Edition)
- Homebrew has PHP.
Let’s go! Continue reading