We've been working hard on a development branch of Zoop code-named Lunar, which is slated to become Zoop Framework 2.0. Lunar maintains most of the concepts and ideals of the current framework, but adds a whole lot more awesome.
The Zoop Framework was the first object-oriented MVC framework for PHP. It's been around since 2001, and was starting to show its age. The 2.0 branch of Zoop targets the latest versions of PHP—Lunar currently requires 5.2+. We have made an effort to maintain API compatibility where possible, so Zoop 1.x applications should run under Zoop 2.0, with a few adjustments.
We are quite stoked about everything that is going on, so I figured I would share a bit with you.
My personal favorite improvement is the ...
Faster Deployment the First Time, Every Time
Whether you're a Zoop newb, or a framework veteran, the new-and-improved skeleton app is worth checking out. The file structure is simplified and more intuitive. Thanks to some changes in Zoop's core dependencies, a barebones app works out of the box. Check out this brand new Zoop Lunar screencast ...
Going from barebones to full-featured is pretty simple too, thanks to Lunar's ...
Crazy Simple Configuration
I'll be honest with you, Zoop configuration could be a bit confusing. The Lunar branch now uses a cleaned up index.php to include components, combined with a super-slick YAML-based config library. Now your app configuration is conveniently located in one place, and it's easier than ever to figure out.
It's all about options. Zoop Lunar has removed a ton of hard-coded configuration, so you can tweak things to you heart's content... But we make sure to ship it with a sane set of defaults so you don't have to.
zoop:
gui:
# optionally, do a css reset and set base styles (thanks yui!)
use_css_reset: 0
use_css_base: 0
# define page regions and default templates
regions: [ header, sidebar, content, footer ]
primary_region: content
# wrap each region in a div with the region name as id?
add_region_divs: 1(This snippet is part of the config for the ...)
New and Improved View
The Gui layer has received a much needed update. It's easier than ever to theme and style Zoop. And despite all these improvements—or in some cases because of them—Lunar's Gui performs faster than any previous version of Zoop!
One of the most noticeable changes is the simplification of app templates. It is no longer necessary to build full templates for every zone, or to link header or sidebar templates in Smarty, thanks to the concept of regions.
Regions in Gui map to primary content areas of your site. Lunar ships with four: header, sidebar, content, and footer. Adding more—or removing them—is a cinch, and it can be done at runtime or app-wide in your config.
$gui->addRegion('right-sidebar'); $gui->removeRegion('content');
Regions are assigned default templates by your application, but these templates can be changed on a per-zone or per-page basis:
$gui->assignHeaderTemplate('shared/header.tpl');
There are even shortcuts for setting content in your regions. I wouldn't use this for the sidebar or main content regions, but you have to admit it is sweet:
$gui->assignFooter('Copyright © 2009 Example.org');
Adding CSS and JavaScript resources is now just as simple. You can do it in a Gui plugin, a zone or page or included library... Gui will make sure your files or Inline JavaScript make it on the page:
$gui->add_css('public/resources/css/style.css'); $gui->add_js('public/resources/js/custom.js'); $gui->add_jquery(); $gui->add_jquery('$("h1").eq(0).addClass("heading");');
And to set this bad boy loose, all you need is this (taken from the skeleton app):
function pageIndex() { global $gui; $gui->generate($this->canonicalizeTemplate('welcome.tpl')); }
Too simple? Wait until you see Lunar's ...
Next Generation Webforms
Zoop's automatic form generation bumps it up a notch in Lunar. The third generation forms component—confusingly named Formz—does more for you than ever before: CSRF protection, form validation, record relation management, and easy customization. And if you combine Formz with a Doctrine model, you pretty much don't have to do anything.
Just a few highlights:
// Create a Formz object based on the Users table of the database. $form = new Formz('users'); // Hide the password on the list view. $form->field('password')->setListshow(false); // Change the display label on this field (on list, read, or update pages) $form->field('username')->setDisplayLabel('User Name'); // Make the password field use the password field confirmation GuiControl $form->field('password')->setDisplayType('BetterPassword'); // Add an aggregate field. This is mostly useful for condensed list views. $form->addAggregateField('full_name', '%last_name%, %first_name%') ->after('username') // before() and after() methods make it easy to order your fields. ->setFormshow(false); // Hide it on form views (so it only shows on lists). // Add a fake field... It'll show up in the form, but won't actually mean anything. $form->addField('fake') ->setDisplayType('text') ->setDisplayLabel('This field does nothing.'); $form->guiAssign();
Then all you have to do is insert the form into a template for display:
{formz form=$users}
And Lunar harnesses the power of Formz to ...
Keep CRUD Real (Simple)
We found we spend quite a bit of time working on four basic content operations: Create, Read, Update and Destroy. So we built a CRUD-specific base controller to make this as seamless as possible. We even added a fifth option: List. Leveraging the power of Formz, CrudZone takes the hassle out of basic CRUD operations. At it's simplest form, CrudZone is almost magical. Check this out:
class zone_foo extends CrudZone { $tableName = 'users'; }
Yep. That's it. That's all it takes to build a user table CRUD controller. Sweet, huh? Of course you're not limited to that. You can customize the form output and configuration to your heart's content. Keep an eye out for a screencast highlighting the CrudZone and some of it's capabilities.
And speaking of upcoming blog posts, Steve says he's going to write one about ...
Zoop's Magical New Controller
Lunar has the makings of an API baked right into the controller. Content can be delivered in a number of formats simply by asking for it. It currently supports html, xml, json, csv, pdf, and xls, to name a few. When combined with CrudZone, this can make your site into a turnkey REST API.
With this powerful new controller, requesting data in an alternate format is as simple as this:
http://example.com/users/index http://example.com/users/index.json http://example.com/users/index.rss http://example.com/users/index.pdf http://example.com/users/index.csv http://example.com/users/index.xls ...
Just because the options are there doesn't mean you need to allow them. You can decide, at the app, zone, or page level, which formats to publish and which to accept as input. It's totally up to you.
To make your life easier, Zoop's controller now supports more flexible zone and page parameters, formatted as key:value pairs:
http://example.com/products/brand:acme/type:slingshot/price:0:3000 http://exmaple.com/images/size:thumbnail/effect:sepia/original.jpg
These parameters are available to controller at the zone or page level. Notice the price range parameter? That's pretty slick.
The controller isn't the only component getting a facelift. There's also Lunar's much-improved ...
Flexible—And Powerful—Authentication
Zoop's authentication back, better than ever. The updated Auth component uses a pluggable driver system to allow several back-end options. It currently supports DB, Doctrine, or YAML backed authentication. It features User, Group and Role authentication, and easy permissions with a group-based ACL. Plus, it's trivial to hook this into Zones and CrudZones for a very powerful app authentication.
And it can be powered by ...
A Powerful ORM, If You Want It
Lunar now uses the Doctrine ORM. Formz, CrudZone and Auth are each optionally backed by the most solid PHP ORM on the market. But only if you need the features.
That's our guiding principle. We make things powerful, magical, and configurable. Plus we try to include ...
A Healthy Serving of the Little Things
It's all the little things that make Zoop great. Core dependencies have been minimized, letting you launch your app with as little hassle as possible.
Things like how the all new FileUtils knows whether it can write that file or create that directory before it tries, allowing it to present a pretty message rather than spewing errors all over the place.
Things like environment checking when you first deploy your app, making sure temp and cache directories are set up.
Things like cleaning up POST and GET for you, and giving you easy ways to filter and validate user input.
Things like giving you a sweet preview version of Lunar to try! For free! All you have to do is click below ...
So Try it Out!
I've rolled a snapshot of Lunar for you to play with. Please note that this is a pre-alpha release. It's not feature complete. It's shouldn't be considered stable. So please don't build any mission critical apps on it yet, k?
Get Lunar. Have fun :)
Wait. "Pre-alpha"?
Yep. We're calling this version of Lunar a "pre-alpha". This means that most of the major features are in place and solid. We feel it's reached a point in its development that people can start building on it, can start using it and loving it. But it's definitely still under active development. We're adding features and tuning performance. In particular, here are a few things we're still working on:
- We're removing PHP 4 compatibility. We're sorry if this comes as a shock, but it's time to move on. Lunar requires PHP 5.2+
- On a related note, we're still cleaning out some stale code from older PHP versions. We'll keep refactoring and cleaning house, but we don't expect to see API changes as a result. Just faster, cleaner, more future-proof code.
- We have basic unit test support via Simpletest, but our test coverage is far from complete. We will continue adding testing between now and launch.
- While the new Gui resources (JavaScript and CSS file inclusion) are amazing, we're not done yet. We're adding aggregation, compression and caching across the board, allowing your pages to load faster than ever.
- The database backend (for Formz, etc) needs a good overhaul. It works, but it's got some dead weight that can be pruned. More testing needs to be done with other databases: We use MySQL and SQLite a lot, but need to do some testing on PostgreSQL, MSSQL, and more.
- There are some really amazing things happening with the controllers. They can now present content in a gazillion different formats (html, json, xml, csv, xls, pdf...), but we're still working on accepting input via all the new formats.
We're going to continue slipping in new features and capabilities in the coming months. Who knows, we might even add your favorite feature. Thanks for taking it out for a spin. Thanks for letting us know where the friction points are, and how it to make our favorite framework better.