ORM library for PHP

Further releases: Hormon has been actively developed last time, but there is no point in releasing further releases at the moment. Hormon is designed for PHP 5.3 and mainly thought to work with libraries like ZendFramework 2.0 and/or Symfony 2. As release dates of these libraries are still unknown Hormon will be held in current state for some time.

Release 0.0.2: Thought it was stated that there will be no more Hormon releases for some time, because of amount of changes that were introduced since last release, here comes 0.0.2. It includes many new features like caching engine, improved JOIN mechanism and meny more. For more information see release blog note.

Release 0.0.1: First Hormon package was released and there comes important thing to notice - it requires PHP 5.3 as it uses namespaces. Why, you ask? Hormon is still under development and it will take long time until it will enter production stage (however it's still keeps being very stable). As PHP goes forward, more and more projects will start to use PHP 5.3. We don't want to be outdated before we even start production releases.

Hormon for PHP 5.2: from since first public release 0.0.1 Hormon is prepared for PHP 5.3 taking much advantages mainly from namespaces support. However if you want to use it in your PHP 5.2 projects you still can download SVN revision 9 which was very stable and has all major Hormon features.

This is a temporary website. Kind of placeholder ;). The project has been just launched so we are not fully operative yet, but something should be here in <?php echo rand(); ?> days. On this site you can read brief explaination of why/how/what/wtf about Hormon. For services connected with this project you may visit different sections: download, donate, project.

What is ORM?

After Wikipedia: Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language.

In other words - ORM library mapps database data onto programming language environment and vice-versa. It gives you possibility to use your SQL (usualy) database as an object-oriented code without need to mess with SQL language itself; it takes care of relations and constraints; it optimizes queries to make to not make unncecesary work (in effect avoid unneded load). Main reason to use ORM library is, that it automates many actions related to database like generating schemas and classes code. Many of those tasks are very time-eating and simply boring when you do that manualu - coding plain getters and setters methods for each fields, building queries etc. - ORM library like Hormon takes configuration file which you provide and generate SQL schema and PHP code for everything you want to have in your database.

About the project

Hormon is thought to be a compact, yet fully featured ORM library for PHP. Main rule is to use as many PDO+PHP5 goods as it is only possible. There are few reasons to do so. First and main - things that are built in PHP5 and PDO extension are much faster and efficient then replacements in native PHP code. Secondly - code is smaller. And, at third - features included in further PDO/PHP5 releases will be available without problems and will require less work. Of course it is slightly different way then many other libraries, where everything, that can only be done is added into source code, but not in this case - as mentioned, Hormon is mainly focused on being compact and transparent.

Reinventing the wheel

Like you probably know, or maybe not, there are of course already planty of similar libraries for PHP5. However only two are really worth checking out - Propel and Doctrine - other libraries are usually just poor attempts abandoned after short time. So, if there are already two good libraries, why Hormon was created? I really don't like "re-inventing the wheel" (which means creating something that is known for a long time already) - I tried to use both of them many times. Unfortunately neither Propel, nor Doctrine matched my needs.

Doctrine represents way of coding completly disliked by me - too much magic. All those public fields, which are not fields; all those reflections even though data is available during build-time and something that I completly can't understand: DQL - if you build abstraction layer for SQL which you want to use in PHP, you want it to be PHP code, but in Doctrine you recive another language which is simplified query language (meant to be more intelligent). Ok, maybe those are clever ideas, but they didn't suit me.

Propel on the other hand was something that I really liked from API side. But there are many things that made me frustrated while using it. Both in build process and in runtime library there are many things that I wanted to fix, but after some time I realised, that it will be easier to create own library from scratch. As I said Propel way for API was fine for me, so from user (programmer) point of view it may look a bit familiar, but from within it looks completly different.

Of course currently Hormon provides only little piece of functionality available in mentioned libraries, but it will be under intensive development so I hope to implement a mature and solid library ready for use in complex projects.

…or it will come out that I'm an idiot and all this work will be useless :P.


At this moment Hormon provides basic ORM and DBAL functionality. However at this moment only MySQL is supported (adding drivers for different RDBMSes shoudln't be a problem, but will require time). It contains query generator classes which handle PDO parameters bindings (both input parameters and returning fields). Code generator supports YAML, XML, PHP, JSON and INI formats. It generates both SQL database schema and ORM classes. List classes implements IteratorAggregate class that delegates foreach() {…} iteration to native PDOStatement object (with bounded object relations). They also implements Countable interface wich maps to COUNT() query.

Fields can be defined as lazy (usefull for large fields like LOBs) to avoid loading them by default and left for lazy-initialization on-demand. Library also supports DateTime types which can be used directly in obejctive way. Both records and lists classes handles all data related against foreign tables - for instance, it is possible to execute JOIN queries both during single records loading and fetching entire list. Hormon can also easily handle joins on multiple tables, even multiple joins on same table still allowing operations on all joined tables like sorting or filtering. All changes in fields are noticed so for example during UPDATE query only changed fields are updated. Also if field has default value it is not saved before being set explicitly. There is also mechanism for easy iteration over dictionary tables so you can use foreach($table as $id => $label){…} construction.

Hormon also contains built-in cache interface which allows you to simple cache optimization - just mark tables that should be cacheable. Cache implementation can be easily handled by custom backend (library comes with example Zend_Framework cache backend). Both records and entire lists queries can be cached including custom and joined data, so once you have your data loaded and prepared you me save your database load.

To be done

First of all drivers for RDBMSes different then MySQL are a must - mainly PostgreSQL, Oracle, MSSQL, Firebird and SQLite. On the other hand, many functionality features are required:

It is also important to create additional reasources like (mainly) documentation, benchmarks (against Propel and Doctrine), create website, unit tests and so on.

It works!

Is it safe to use Hormon? Does it really work? Though the project has just been started, from what I personaly see it's ready for use in projects, in which it will fullfit requirements given to ORM/DBAL layer. Before releasing it I've been using Hormon in my works and it works great! Of course there has been some bugs on the begining, but since then everything that I found was fixed, so it should be really stable. Here is a list of projects that has been done using Hormon as DBAL/ORM library:

As you can see it deals great both with simple websites and bigger portals as well. I'm also using it in few projects that are currently under development and it still works great.

Join and help

Hormon was started by myself (Wrzasq). If you want to help developing this project, feel free to mail me, your help will be very usefull. I'm a busy man and won't have much time to work on this project - it will be mainly developed in way I will need it for my projects or when I will have some spare time. If you want to contribute with this project in any way please contact at mail below.

Contact: wrzasq@gmail.com.

Wrzasq.pl | iKancelaria | Chillout Development
Project Web Hosted by SourceForge.net