Doctrine (PHP)
Encyclopedia
See also DataEase
DataEase
DataEase is an RDBMS, and is considered a rapid application development tool for developing relationally-organized, data-intensive software applications for personal computers. DataEase was created in the early 1980s by software developers Arun Gupta and Joseph Busch. The first version of the...

, whose query language is also called DQL.
Doctrine is an object-relational mapper
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

 (ORM) for PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

 that provides persistence
Persistence (computer science)
Persistence in computer science refers to the characteristic of state that outlives the process that created it. Without this capability, state would only exist in RAM, and would be lost when this RAM loses power, such as a computer shutdown....

 for PHP objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...

. It sits on top of a database abstraction layer. One of Doctrine's key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL).

Usage demonstration

Doctrine 1.x follows the active record pattern
Active record pattern
In software engineering, the active record pattern is an architectural pattern found in software that stores its data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture...

 for working with data, where a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...

 corresponds with a database table
Table (database)
In relational databases and flat file databases, a table is a set of data elements that is organized using a model of vertical columns and horizontal rows. A table has a specified number of columns, but can have any number of rows...

. For instance, if a programmer wanted to create a new "User" object in a database, he/she would no longer need to write SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

 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.

In Doctrine 2.x, the latest release of Doctrine, the entities no longer have to extend a base Active Record class. Instead you just persist them by passing them to the so called Entity Manager:

$user = new User;
$user->name = "john";
$user->password = "doe";
$em->persist($user);
echo "The user with id $user->id has been saved.";

Features

One 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
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 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
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

) SQL dialect called DQL (Doctrine Query Language) inspired by Hibernate's
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 HQL. Alternately, the QueryBuilder class (Doctrine_Query in Doctrine 1.x) allows one to construct queries through a fluent interface
Fluent interface
In software engineering, a fluent interface is an implementation of an object oriented API that aims to provide for more readable code....

. 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
Join (SQL)
An SQL join clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as is. A JOIN is a means for combining fields from two tables by using values common to each. ANSI standard SQL specifies four types of JOINs: INNER, OUTER, LEFT, and RIGHT...

 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
    Tree structure
    A tree structure is a way of representing the hierarchical nature of a structure in a graphical form. It is named a "tree structure" because the classic representation resembles a tree, even though the chart is generally upside down compared to an actual tree, with the "root" at the top and the...

    ) 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
    Memcached
    In computing, memcached is a general-purpose distributed memory caching system that was originally developed by Danga Interactive for LiveJournal, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the...

    , SQLite
    SQLite
    SQLite is an ACID-compliant embedded relational database management system contained in a relatively small C programming library. The source code for SQLite is in the public domain and implements most of the SQL standard...

     or APC;
  • ACID
    ACID
    In computer science, ACID is a set of properties that guarantee database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction...

     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.

History

Doctrine was started by Konsta Vesterinen, also known as zYne-. The project's initial commit was made on April 13, 2006 to the svn repository. 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
Google Summer of Code
The Google Summer of Code is an annual program, first held from May to August 2005, in which Google awards stipends to hundreds of students who successfully complete a requested free or open-source software coding project during the summer...

 project.

Doctrine 1.0.0 was released on September 1, 2008.

The first stable version of Doctrine 2.0 was released on December 22, 2010, after 2.5 years of dedicated development starting in early 2008.

Influences

Doctrine has been influenced by dozens of projects and many different people. The largest influences have been the Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 ORM Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 and ActiveRecord from Ruby on Rails
Ruby on Rails
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

. Both of these ORM solutions have implemented a fully featured solution in the Java and Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

 languages. The purpose of the Doctrine project is to build an equally powerful solution for the PHP language.

Community

  • There is an active IRC channel where users and developers of Doctrine commonly associate. The channel is on the freenode
    Freenode
    freenode, formerly known as Open Projects Network, is an IRC network used to discuss peer-directed projects. Their servers are all accessible from the domain name [irc://chat.freenode.net chat.freenode.net], which load balances connections by using the actual servers in rotation...

     network (irc.freenode.net); the channel name is #doctrine. irc://irc.freenode.net/#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

See also

  • Propel (PHP)
    Propel (PHP)
    Propel is a free, open-source object-relational mapping toolkit written in PHP. It is also an integral part of the PHP framework Symfony and was the default ORM up to, and including version 1.2.- History :...

  • List of object-relational mapping software
  • Symfony
    Symfony
    Symfony is a web application framework written in PHP which follows the model-view-controller paradigm. Released under the MIT license, Symfony is free software...

    , a web application framework
    Web application framework
    A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development...

    which uses Doctrine by default

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK