There are two newish PHP projects that both aim to feel a lot like Hibernate for PHP. Outlet ORM and Repose PHP ORM.
Outlet is older and more mature, Repose is newer with slightly different design goals (mainly that it does not rely on having getters and setters to retrieve objects, at the cost of loading more of the object graph at the same time).
Both have similar usage and neither currently require the model classes to extend any base classes or inherit any interfaces.
Example Outlet code.
PHP Code:
<?php
$outlet = Outlet::getInstance();
$client = new Client;
$client->Name = 'Test Client';
$project = new Project;
$project->Name = 'Cool Project';
$project->setClient( $client );
$bug = new Bug;
$bug->Title = "Button doesn't work";
$project->addBug( $bug );
// inserts the project
// and all of the related entities
// in one transaction
$outlet->save( $project );
?>
Example Repose code.
PHP Code:
$session = MyProjectReposeUtil::getSession();
$userBeau = new sample_User('beau');
$userJosh = new sample_User('josh');
$project = new sample_Project('Sample Project', $userBeau);
$bug = new sample_Bug(
$project,
'Something is broken',
'Click example.com to test!',
$userJosh, // Reporter
$userBeau // Owner
);
$session->save($bug);
2) Language "deficits" of PHP. One of the main things needed for "transparent persistence" is a transparent way to get data in and out of the domain objects. Java ORM solutions mostly use reflection, in PHP its only now, with 5.3 ALPHA, possible to get/set private/protected properties through reflection.
Repose has a workaround for dealing with protected properties and has planned support for private properties with PHP >= 5.3. The hope is that people using PHP < 5.3 will continue to be able to use protected properties and anyone who has access to PHP >= 5.3 will be able to use private properties if they need to.
I'll have to take a look at Doctrine 2.
Bookmarks