[thor] Fwd: RE: Horde Customisation and additions

Chuck Hagenbuch chuck at horde.org
Thu Jul 21 14:02:06 PDT 2005


Quoting Carlos Pedrinaci <cpedrinaci at yahoo.es>:

> I was wondering about what this RDO stuff was.
> Actually I had a look at the code and it seemed to be the kind of stuff
> I *really* like but I wasn't sure about your intentions and... well..
> given that you wrote once "don't ask and wait until its done".. I was
> waiting :)
>
> So.. now I have a nice excuse for asking :)

Yup, I brought it up first. And people have been almost shockingly good 
about not asking, so... :)

RDO stands for Rampage Data Objects. Rampage is the name I thought up 
to replace Catalyst, which is what I wanted to call a set of php5 
components for Horde, but someone already took Catalyst.

The Data Objects part is pretty similar to things like DB_DataObject 
and Propel, but with a horde-ish slant and of course my own opinions:

- API does not include direct SQL anywhere. Idea is to allow backends 
like LDAP, XML files, etc.

- Doesn't require writing XML to describe your whole database or doing 
other heavy java-ish things

The reason to write RDO for Horde is that, looking at Horde 
applications, one of the things we do over and over again for every 
Horde app is data access code. Write the Driver class, write the 
Driver_sql, maybe a few others. For a while I thought we could use 
DataTree to avoid that, but DataTree is kind of awkward to use and it 
slows down tremendously. RDO should be much faster, and hopefully more 
intuitive to use, too.

Here's some working code:

require_once 'Horde/Rampage.php'; // load php5 autoloader

class User extends RDO {}

class UserMapper extends RDO_Mapper {

  protected $container = 'users';

  public function getStorage() {
    return RDO_Storage::singleton('pgsql', array(connection params));
  }

}

$um = new UserMapper();
$count = $um->count(); // count # rows in users table

if (!$um->exists(1)) {
  // does the user with primary key (automatically determined from the db)
  // exist?
}

// look for alice and create her if not found
$alice = $um->find(RDO::FIND_FIRST, array('name' => 'Alice'));
if (!$alice) {
  $alice = $um->create(array('name' => 'Alice', ...));
  var_dump($alice->getFields()); // $alice is a User object now
}

// change Alice
$alice->name = 'Alicia';
$alice->save();

// list all users
foreach ($um->find(RDO::FIND_ALL) as $user) {
  echo $user->name . "\n";
}


All of that currently works - the above code plus a "users" table with 
a primary key is all you need.

-chuck

-- 
"But she goes not abroad in search of monsters to destroy." - John 
Quincy Adams


More information about the thor mailing list