Speaking at ZendCon
It appears the schedule for ZendCon is at least partly up. I'd been reserving this announcement mostly out of a personal sense of superstitution, but since it seems to be official now, so I'll go ahead and pipe up: I'm speaking at ZendCon.
Out of four proposals, one managed to make it onto the conference schedule, and that was Pick Your Protocol: Creating Web Services with Zend Framework. It won't be my first time at ZendCon, but it will be my first time there as a speaker. I'm looking forward to being among their ranks as well as meeting friends new and old.
See you all in September!
Output Filters in Zend_View
A feature of Zend Framework MVC that isn't currently very well documented is output filters. They're mentioned in passing in the Zend_View documentation, but not reviewed in detail anywhere in the Reference Guide as of version 1.5.2. I was curious enough about how to implement markup minification that I decided to trace through the Zend_View source code in attempt to discern how output filters actually worked. As it turns out, it's actually pretty simple.
First, you need to get a reference to the current Zend_View instance. If you're using the Zend_Layout MVC integration, you can get this by calling $this->_helper->layout->getLayoutInstance within your Zend_Controller_Action class to get the current Zend_Layout instance and then getView on that to get your Zend_View instance. Otherwise, the Zend_View instance is available via the view property of Zend_Controller_Action instance.
Next, call addFilterPath or setFilterPath on your Zend_View instance from your Zend_Controller_Action class. Pass in a path to the directory to contain your output filter classes and a naming prefix that all of your output filter classes will use. I'm not sure why the class prefix defaults to "Zend_View_Filter_" since no such classes exist. In my opinion, it would have made more sense to derive the prefix based on the provided directory path. Anyway, create the directory you've specified if it doesn't already exist and create a new class file within that directory. In my case, I named the directory Vendor/View/Filter, the file Minify.php, and the class contained in the file Vendor_View_Filter_Minify.
Within this class, you must implement at least one method, filter. This method should accept a single parameter, which will be a string containing the view ouput to be filtered, and should return the filtered version of that string. Optionally, if your filter requires access to the related Zend_View instance, you can also declare a setView method that accepts the Zend_View instance as its only parameter and it will automatically be passed in when your output filter class is instantiated. Within setView, you can store the Zend_View instance in an instance property of the output filter class so it can be referred to later in the filter method.
Once you've finished your output filter class, you need to explicitly add it to the output filters in use from your Zend_Controller_Action class. You can use addFilter or setFilter for this. Pass in the name of your output filter class without the class prefix. In my case, I passed in "Minify." At this point, the filter should be used when rendering your page. I poked around in the DOM and Tidy PHP extension documentation, but couldn't find a feature for markup minification, so I ended up using the PCRE extension to do the job. Below is the final source code for my output filter class.
Vendor/View/Filter/Minify.php
class Vendor_View_Filter_Minify
{
public function filter($string)
{
return preg_replace(
array('/>\s+/', '/\s+</', '/[\x0A\x0D]+/'),
array('>', '<', ' '),
$string
);
}
}
Vendor/Controller.php
class Vendor_Controller extends Zend_Controller_Action
{
public init()
{
$this->_helper->layout->getLayoutInstance()->getView()
->addFilterPath('Vendor/View/Filter', 'Vendor_View_Filter_')
->addFilter('Minify');
}
}
Zend Framework and Remember The Milk
I've posted a few times on Twitter related to my latest project and a few people have already asked me about it, so I figured it was worth a blog post.
My first project for the Zend Framework was Zend_Service_Simpy, a service module providing a lightweight wrapper around the API for the Simpy social bookmarking service.
My latest project is another service module for the Zend Framework. This time, though, it's for the Remember The Milk API. RTM is basically a TODO list on serious steroids. It's the Swiss Army Knife of task management. It allows you to manage multiple lists of tasks. You can add them easily from a variety of mediums, tag them, prioritize them, set deadlines for them, have them repeat, get reminders for them, tie them to physical real world locations, and share them. RTM offers great support for integration with Google applications including Google Calendar, iGoogle, and Gmail (plus offline access powered by Google Gears). They're also very big into supporting mobile devices, including those running on Windows Mobile as well as the iPhone.
If you like, you can check out my original proposal for this module. I can already say that the API will end up changing a little, though, but it's good enough to give you a general idea of what the capabilities of the finished service module will be. I only actively started implementation recently and things are progressing at a fairly rapid pace. I still have unit tests and documentation to handle, but hopefully there's a shot at seeing it moved to core within the next two releases of the framework.