Porte: Object Relational Mapping (ORM) in PHP
Porte has been designed to save time and to simplify the development of relational database applications written in PHP.
Tired of writing repetitive SQL to interact between your objects and the database, Porte will greatly simplify your life. Porte can retrieve, search and save objects without a single line of SQL. Porte deliver a natural and easy to use framework.
A design goal of Porte was to avoid any external configuration (being XML or others). In its simplest form, a record is a PHP object which class extends "PorteRecord" and which contain its definition in an array called "meta_fields". Getter and setter methods as well as a lot more of goodies will be automatically derived from there.
To some extends, Porte is inspired by Martin Fowler concept of Active Records.
September 24th, 2008: Porte 0.2.1 released
- Documentation: New API section
- Table: New delete method; filter in count method
- Iterator: Rename PorteList to PorteIterator
- Position: New method "setPosition" (int, "first" or "last)
- Record: Lazy loading of records; all dynamic methods using model method mechanism
- Types: Type "date" renamed "timestamp"; new type "year", "date", "time"; boolean stored as tinyint
- GIS: Related code moved to new plugin
- Dojo Store: Add label support; object properties encoded as json
- Utils: Auto creation of database of not exists
- Model: New option "extended" to method getProperties
What does it give you?
- Property access: get, set, add, delete
- One-to-many associations
- Many-to-many associations (with or without a join table)
- Parent-child associations
- Table operations: exists, add, drop
- Table migrations: add and delete fields based on $meta_field configuration
- MySQL support
- Sql injection safe
- Events notification
- Validation framework
- Cross-databases operations in a same connection
- More than 300 tests which worth many lines of documentation
Quick exemple
Create a new group, associate it with a new user and save both
Command: "php samples/home/quick_exemple.php"
class Group extends PorteRecord{
public $meta_fields = array(
'name'=>array('size'=>50),
'users'=>array(
'has_many'=>true,
),
);
}
class User extends PorteRecord{
public $meta_table = array(
'name'=>'Users',
'primary_key'=>'id',
'encoding'=>'utf8',
);
public $meta_fields = array(
'id'=>array('int'=>11),
'username'=>array('size'=>50),
'password'=>array('size'=>50),
'groups'=>array(
'has_many'=>true,
),
);
}
PorteConfig::$database = 'porte';
PorteConfig::$connection = new PorteConnection();
$group = new Group();
$group->table->update(array('drop'));
$group->setName('my group');
$user = new User();
$user->table->update(array('drop'))
->setUsername('my username')
->setPassword('my password')
->addGroup($group)
->save();
echo 'User id is '.$user->getId()."\r\n";
echo 'Group id is '.$group->getId()."\r\n";
// User id is: 1
// Group id is: 1