Idiorm is a PHP ORM that eschews complexity and deliberately remains lightweight with support for PHP5.2+. It consists of one file and primarily one class that can easily be configured in a few lines of code. There are no models to create, no convoluted configuration formats and there is no database introspection just a simple PDO connection string.
However, having said this, Idiorm is very powerful and it makes most of the queries PHP applications require pain free. Some of these features include fluent query building, multiple connection support and result sets for easy record manipulation.
Paris sits on top of Idiorm to provide a simplified active record implementation based upon the same minimalist philosophy. To configure Paris you just add simple models so that you can exploit the full power of Idiorm’s fluent query API, table/object associates (one-to-one, one-to-many, etc.) and filter methods to encompass common queries.
Some simple examples
Fetching and updating a record is easy with Idiorm:
<?php
$user = ORM::for_table('user')
->where_equal('username', 'j4mie')
->find_one();
$user->first_name = 'Jamie';
$user->save();
$tweets = ORM::for_table('tweet')
->select('tweet.*')
->join('user', array(
'user.id', '=', 'tweet.user_id'
))
->where_equal('user.username', 'j4mie')
->find_many();
foreach ($tweets as $tweet) {
echo $tweet->text;
}
Whereas Paris makes it easier to think of records and associations as objects:
<?php
class User extends Model {
public function tweets() {
return $this->has_many('Tweet');
}
}
class Tweet extends Model {}
$user = Model::factory('User')
->where_equal('username', 'j4mie')
->find_one();
$user->first_name = 'Jamie';
$user->save();
$tweets = $user->tweets()->find_many();
foreach ($tweets as $tweet) {
echo $tweet->text;
}
These examples show a very simple use case worked in both the Idiorm ORM way and using the Paris Active Record method. Of course the documentation for each project is a good place to start and find out more information on each projects capabilities.
A potted history
Both projects were written by Jamie Matthews; a friend and former colleague, but in recent times his focus has shifted to Python. This left Idiorm and Paris in an unmaintained state until, first, Durham Hale and then myself took up maintenance duties on the libraries.
This has led to a number of new features recently making their way into Idiorm and some long standing bugs being quashed. In this release quite a few changes have taken place including:
- Multiple connections
- Result set implementation
- Tests refactored to use PHPUnit and configured with Travis-CI for continuous integration
- Documentation revisited and now built with Sphinx on Read the Docs at idiorm.rtfd.org
- Support for Firebird and PostgreSQL on top of the existing MySQL and SQLite
- Installation via Packagist/Composer for Idiorm
- And much more besides in the changelog
These updates have been complemented by some similar changes in Paris:
- Documentation on Read the Docs at paris.rtfd.org
- Installation via Packagist/Composer for Paris
- With more minor updates maintained in the changelog
The future
The present aim with both Idiorm and Paris is to maintain the current code base and add suitable new features as and when they become required or useful. There have been a number of suggestions for possible improvements that would break backwards compatibility such as:
- Changing the code to utilise late static bindings and thereby drop PHP5.2 support
- Updating the classes, tests and documentation to meet the PSR-1 FIG standard
Neither of these two are holding the current project back or would significantly contribute to it use. They are proposals that would make the libraries inaccessible to a large number of users on cheap shared hosting environments or working on legacy projects.
It is likely that, at some point, Idiorm and Paris will make the move to only support PHP5.3+, but without a compelling reason there is no point in breaking backwards compatibility. I have previously addressed this in a pull request so for the full arguments please head over there.
If you have an suggestions or better yet pull requests then please lodge an issue on github for the relevant project. Some people disagree with this and others agree, but I would like to hear your opinion.
Project updates
If you like Idiorm and Paris then please follow me on Twitter and github for updates. You might also like some of my other projects such as Navigator, php_ssdeep and PHP at Job Queue Wrapper.