Doctrine (PHP)
From Wikipedia, the free encyclopedia
Doctrine | |
---|---|
Latest release | 0.10.4 / 28 March 2008 |
Written in | PHP |
OS | Cross-platform |
Genre | Object-relational mapping framework |
License | GNU Lesser General Public License |
Website | phpdoctrine.org |
Doctrine or phpDoctrine is an object-relational mapper (ORM) for PHP 5.2.3+ that sits on top of a database abstraction layer. It allows easy access to all types of databases, such as MySQL, through the use of PHP objects.
Contents |
[edit] Usage demonstration
Doctrine follows the active record pattern for working with data, where a class corresponds with a database table. For instance, if a programmer wanted to create a new "User" object in a database, he/she would no longer need to write SQL queries, but instead could use the following PHP code:
$user = new User(); $user->name = "john"; $user->password = "doe"; $user->save(); echo "The user with id $user->id has been saved.";
Object-related functionality can be added to the objects themselves, instead of being spread around the application. This can improve the ease of maintenance of the software project.
[edit] Features
A praised feature of Doctrine is the low level of configuration that is needed to start a project. Doctrine can generate object classes from an existing database, and the programmer can then specify relations and add custom functionality to the generated classes. There is no need to generate or maintain complex XML database schemas, as seen in many other frameworks.
Another key feature of Doctrine is the ability to optionally write database queries in an OO (object oriented) SQL dialect called DQL (Doctrine Query Language) inspired by Hibernate's HQL. Alternately, the Doctrine_Query class allows one to construct queries through a fluent interface. These interfaces provide developers with powerful alternatives to SQL which maintain flexibility and still allow for switching of database back-ends, without requiring any code duplication.
Writing queries explicitly however is not always necessary, as Doctrine performs joins and fetches related objects automatically. Small projects can be easily constructed without writing queries.
Other notable features of Doctrine are:
- support for hierarchical (tree-structured) data;
- support for hooks (methods which can validate or modify database input and output) and event listeners to structure business-related logic;
- column aggregation inheritance (similar objects can be stored in one database table, with one type-column specifying the subtype of the particular object - the correct subclass is always returned when a query is done);
- a caching framework, making use of several backends such as memcached, SQLite or APC;
- ACID transactions;
- model behaviors (sluggable, timestampable, nested set, internationalization, audit log, search index);
- database migrations;
- a "compile" function to combine many PHP files of the framework into one, to avoid the performance hit usually incurred by including the many PHP files of a framework.
[edit] History
Doctrine was started by Konsta Vesterinen, also known as zYne-. It was April 13th 2006 when the first commit was made in the svn repository[1]. As the project became more mature, the adoption began to pick up. Before long, the community was active and development was receiving regular contributions, among others from the Google Summer of Code project.
Fast development meant Doctrine went through a large number of architectural changes; however the interface of version 0.10 is deemed stable for production use. Development is currently focused on refactorings for the 1.0 release.
[edit] Influences
Doctrine has been influenced by dozens of projects and many different people. The largest influences have been the Java ORM Hibernate and ActiveRecord from Ruby on Rails. Both of these ORM solutions are very good products and have implemented a fully featured solution in the Java and Ruby languages. The purpose of the Doctrine project is to build an equally powerful solution for the PHP language.
[edit] Community
- There is an active IRC channel where users and developers of Doctrine hang out. The channel is on the Freenode network (irc.freenode.net); the channel name is #doctrine.
- User mailing list: http://groups.google.com/group/doctrine-user
- Development mailing list: http://groups.google.com/group/doctrine-dev
- Commit log mailing list: http://groups.google.com/group/doctrine-svn
[edit] See also
- List of object-relational mapping software
- Symfony, a web application framework which optionally uses Doctrine
[edit] External links
- Doctrine homepage: http://www.phpdoctrine.org/
- Documentation: http://www.phpdoctrine.org/documentation
- "My First Project" tutorial: http://trac.phpdoctrine.org/wiki/MyFirstProject
- Trac: http://trac.phpdoctrine.org/
- About: http://www.phpdoctrine.org/about
- Download: http://www.phpdoctrine.org/download
- Community: http://www.phpdoctrine.org/community
- Blog: http://www.phpdoctrine.org/blog