DB_Table goes “beta” in new 0.22.0 release

I just released DB_Table 0.22.0 beta. This is the first new release since July 7, and the first beta release. It has been pretty well tested against MySQL and PostgreSQL, but should work with Oracle, MS-SQL, and SQLite as well. I’d be very happy if MS-SQL or Oracle users could provide feedback on how well DB_Table works on those systems; please email me if you would like to provide a report.

The ideas behind DB_Table are simple: embed your column definitions and baseline queries within the PHP class. Then you can call select(‘myQuery’) and get your results, or call insert($myColumns) to insert a new row, and so on. Becuase the class knows the column definitions, it can validate the new data before even connecting to the database; you can extend the validation method to cover all kinds of data. This also lets you automatically create a form based on the column definitions with HTML_QuickForm. DB_Table automates table creation; if a table does not exist in the database when you call a DB_Table object, DB_Table can create it right then, along with indexes — all because the column definitions are embedded in the class.

DB_Table also provides a poor-man’s version of data type abstraction. This element is somewhat controversial. We all know that different database systems keep date and time data in different formats, and it becomes an … interesting … task to create portable SQL statements that will work properly against those different systems. Metabase and its cousin MDB do this by providing translation functions to convert the native RDBMS format to a common format on retrieval and insert/update, but they are not exactly fully automated.

The DB_Table abstraction method (such as it is) instead forces the database to store the date and time as fixed-length strings in ISO-standard format. While this is going to give most database administrators a case of the screaming rants, it is a very workable solution for low- and mid-range applications where portability, not 100% optimization and efficiency among multiple systems, is the paramount concern. This is particularly good for those of us who write applications intended for distribution and need to know for sure that the app will work on a wide range of databases (with minimal effort). For example, YaWiki uses DB_Table to great effect.

You can read the full DB_Table documentation here.

Savant: Revoking the 2.3.0 release

I am revoking the Savant 2.3.0 release from yesterday. The file will still be available, but I can no longer vouch that it will work everywhere for everyone, and I cannot promise that the new function provided therein (“calling of plugins as native methods”) will be in a future Savant 2.x release. I recommend reverting to 2.2.0, particularly for PHP5 users.

For 2.3.0, the only major change was that you could call plugins as native Savant functions through the magic of overload() and __call(). The use of __call() turned out to be unwise, as it exposed a serious compatibility issue between PHP4 and PHP5.

I’m a big believer in reporting failure as well as success; it’s important to let others learn from your mistakes. It’s embarrassing, but necessary. This is one of those times, I’m afraid. The use of __call() turned out to be a serious problem. Yes, overload() is marked as EXPERIMENTAL in the PHP4 documentation, and brother, do they mean it.

Read on for more information about how __call() bit me in the ass, and why aiming for simultaneous compatibility on PHP4 and PHP5 can be unexpectedly difficult when trying to do “neat stuff.”

Continue reading

Savant version 2.3.0 now available

I just released Savant version 2.3.0.

Normally, if you want to use a template plugin, you call the plugin() method like so:

<?php $this->plugin('myPlug', $arg1, $arg2); ?>

Through the magic of the overload() function in PHP and the __call() magic method, you can call plugins as if they were native Savant2 methods.

<?php $this->myPlug($arg1, $arg2); ?>

This should make for a little less typing and a little easier reading. For example, to generate a form with Savant2 using the ‘form’ plugin, you can now do something like this:

<?php
//
// start the form
$this->form('start');
//
// add a text field and label
$this->form('text', 'myTextField', 'default value',
    'Text field label:');
//
// add save and reset buttons as a group
$this->form('group', 'start', 'Group label:');
$this->form('submit', 'op', 'Save');
$this->form('reset', 'op', 'Reset');
$this->form('group', 'end');
//
// end the form
$this->form('end');
?>

(Indicentally, the ‘form’ plugin is pretty powerful; it support all standard field elements, handles layout, and generates valid XHTML with divs, labels, fieldsets, and tables. Check out the documentation for the ‘form’ plugin here.)

Savant is an object-oriented template system for PHP. Savant does not compile templates; instead, you write your templates as regular PHP scripts, so there’s no new markup to learn. As such, Savant is a simple, elegant, and powerful alternative to Smarty.

UPDATE: (19:24 central time) There appears to be a problem with PHP5 and the __call() method in Savant 2.3.0. Users of PHP will want to test before using 2.3.0. I am working on a patch so that __call() works in Savant2 for both PHP4 and PHP5 transparently, and will blog about the solution at that time. Thanks for your patience.

Yawp 1.0.4 Released, and Yawp2

With this release, sessions can be configured to not auto-start by adding a [Yawp] group ‘session_start = false’ directive and commenting out the [Auth] group, per request by David Glenn. Download the new version from phpyawp.com.

Also, I’m beginning work on Yawp2, which should be infinitely more configurable using a plugin architecture (suggested via proof-of-concept code from Ian Eure). Instead of being limited to the standard Yawp object set (Auth, Benchmark_Timer, Cache_Lite, DB, Log, and Var_Dump) you will be able to plug in any PEAR object and lazy-load it on first call, as well as autoload objects at Yawp::start() time (the current behavior). There will be support for convenience methods through the core Yawp object so that you can use method calls to a plugin without having to load the plugin yourself.

The idea behind Yawp is that you always need a certain set of single objects in your app: a database connection, a cache, authentication, a logger, and so on. Yawp instantiates, aggregates, and encapsulates those objects away from the global space so you can concentrate on the “real” part of your program. Does that mean Yawp is an example of aspect-oriented programming?

Savant 2.2.0 released

I just released Savant2 version 2.2.0; you can get it from phpsavant.com. Here are two of the changes:

* There is a new error handling class for PHP5 exceptions. When you call setError(‘exception’), Savant2 will throw a Savant2_Exception whenever there is an error (with the error code and message, of course). This is in addition to setError(‘pear’) for PEAR_Error support, and setError(‘stack’) for PEAR_ErrorStack support.

* By default, Savant does not compile templates. However, there are some cases where you don’t want to provide your template designers with full PHP access; as such Savant2 has had support for external compilers. As an example, I have included a new Savant2_Compiler_basic class to show how to create a simple compiler for Savant2.

You can see the updated documentation here.

Savant is a lightweight object-oriented template system for PHP; I bill is as “the simple, elegant, and powerful alternative to Smarty.”

Savant 2.1.0 Documentation Now Online

The documentation for the 2-month-old Savant2 is now online here; the old version 1 docs are still available here. Be sure to check out the upgrade notes.

Savant2 sports a powerful new form plugin that lets you build forms using only Savant2 plugin calls. In a way, it is a template-logic version of HTML_QuickForm as far as layout and presentation are concerned (but it doesn’t do anything with validation or processing, c.f. my earlier comments on forms).

The Savant site is powered by YaWiki 0.17.2, a custom stylesheet, and a custom header template (in Savant2 of course :-). Soon I’ll release an update to YaWiki that will allow much finer control over the Text_Wiki processing engine using groups in the Yawp config file.

If you have not heard of Savant, it’s not because I haven’t evangelized it at every opportunity; I bill it as “the simple and elegant alternative to Smarty.” But just in case you haven’t heard yet … đŸ˜‰

Savant is a powerful but lightweight object-oriented template system for PHP.

Unlike other template systems, Savant by default does not compile your templates into PHP; instead, it uses PHP itself as its template language so you don’t need to learn a new markup system.

Savant has an object-oriented system of template plugins and output filters so you can add to its behavior quickly and easily.

Savant has an extensible error handling system. While Savant uses its own minimalist error class out-of-the-box, it supports PEAR_Error and PEAR_ErrorStack. You can also add your own error classes to support your favorite framework error system. Error-handling hooks are provided in the standard Savant class.

Even though Savant does not come with one, you can write your own markup compiler and hook it into Savant. This means you can invent any markup system you like; as long as your compiler turns it into a PHP script, Savant will be able to use it. As with the error handler, you don’t need to extend Savant itself to do this; compiler hooks are provided in the standard Savant class.

Savant is streams-aware and can use any stream as a template source.

Be sure to visit the Savant website for more information, including download and installation instructions, tutorials, and reference materials.