Zend Framework Webcast
02 Dec 2005I just finished listening to the Zend Framework Webcast, hosted by php|architect. The recording will be available soon, and I'll update this post to provide a link as soon as it is.
The core focus of the framework is Extreme Simplicity. In order to achieve this, it must be very easy to use. This doesn't just mean that it must be simple to write code - it also needs to be useful in existing PHP environments without the need for external libraries or custom modifications. In many cases, this means that features must be implemented in pure PHP, so that they're available everywhere. For example, the search component is a pure PHP implementation of Lucene, and the front controller doesn't rely on a sophisticated collection of mod_rewrite rules.
Another goal of the framework is to allow developers to use only what they need. If you just want to use the framework's nice search component, you can. You can pick and choose from among the framework's features without having to choose its way of doing everything.
However, this is a real framework and not just a collection of components. The framework will provide components that can be used separately, but it also provides the glue to bring them all together. In addition, the framework will be distributed in its entirety, so there's no need to worry about installing invidual components or resolving dependencies.
The following figure provides an overview of the framework (click on the image for a larger view):
Three components were demonstrated with use cases - ZActiveRecord, ZMail, and ZSearch.
ZActiveRecord, which is an implementation of Martin Fowler's Active Record pattern, provides a nice data interface. Results are returned as a ZActiveRecordCollection object, which implements the Iterator and ArrayAccess interfaces, so result sets behave like ordinary PHP arrays:
class Person extends ZActiveRecord {}
$people = Person::findAll(array('nameFirst' => 'Daniel'));
foreach ($people as $person)
{
echo $person->nameFirst . "\n";
}
For small queries, there are various find() methods provided, such as findFirst():
class Person extends ZActiveRecord {}
$zeev = Person::findFirst(array('nameFirst' => 'Zeev'),
'nameLast' => 'Suraski'));
For more complicated queries, you can use findBySql(), which allows you to provide your own SQL query. This is better than having a complicated query builder.
ZMail was demonstrated with a simple example (I've modified the email addresses out of courtesy):
$mail = new ZMail();
$mail->setFrom('daniel@example.org', 'Daniel Kushner');
$mail->addTo('paul@example.org', 'Paul M. Jones');
$mail->addTo('matthew@example.org', 'Matthew Weier O\'Phinney');
$mail->setSubject('ZMail Demo');
$mail->setBodyText('Hi All, here is some text.');
$mail->setBodyHtml('<blink>HTML</blink>');
$mail->send();
ZSearch is arguably one of the coolest features of the Zend Framework. It provides both a simple API and a more sophisticated query builder. For simple queries, just use the find() method:
$index = ZSearch::open('/tmp/index');
$hits = $index->find('zend');
foreach ($hits as $hit)
{
echo $hit->getDocument()->getFieldValue('title') . "\n";
}
The find() method also supports Google-like queries:
$index = ZSearch::open('/tmp/index');
$hits = $index->find('zend php -java');
foreach ($hits as $hit)
{
echo $hit->getDocument()->getFieldValue('title') . "\n";
}
As you can see, most of the objects implement the Iterator and ArrayAccess interfaces, so working with them is very easy. The idea is that the framework takes care of all of the complexity, so that the code you write is extremely simple. In a way, the Zend Framework makes PHP development as easy as SimpleXML makes XML.