Skip to content

Releases: divengine/orm

Div PHP ORM 1.0.0

19 Sep 04:06
Compare
Choose a tag to compare

Just publish the first release.

Div PHP ORM 0.2.0

19 Sep 02:55
Compare
Choose a tag to compare

New method for build a PDO instances, orm::buildPDO($config, $connectGlobal);

This example build a PDO instance, and make a global connection:

<?php

use divengine\orm;

$pdo = orm::buildPDO([
    'type' => 'pgsql',
    'host' => 'localhost',
    'port' => 5432,
    'name' => 'mydb',
    'user' => 'me',
    'pass' => 'mysuperpass'
], true);

Div PHP ORM 0.1.0

10 Sep 03:58
Compare
Choose a tag to compare

First release, basic features

You can implement your model inheriting from divengine\orm. Look at the following example as it implements a hierarchy of classes (scheme, map, collection, entitlement) and all inherit from the same divengine\orm class.

<?php

use divengine\orm;

class PublicMap extends orm
{
    protected $__map_type = self::SCHEMA;
    protected $__map_schema = 'public';
    protected $__map_identity = 'id = :id';
}

class PersonMap extends PublicMap
{
    protected $__map_type = self::RECORD;
    protected $__map_name = 'person';
    protected $__map_class = Person::class;
}

class Person extends PersonMap {

    private $id = self::AUTOMATIC;
    private $name;

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getName() {
        return $this->name;
    }
   
    public function setName($name) {
        $this->name = $name;
    }
   
}

class PersonCollection extends PersonMap {
    protected $__map_type = self::TABLE;
}

Now look at an example of how to use your model:

<?php

use divengine\orm;

$pdo = new PDO();
orm::connectGlobal($pdo);

$person = new Person(['name' => 'Peter']);
// $person::connect($pdo); 
$person->insert();

$list = new PersonCollection();
$list->addItem($person);

$entity = $list->getFirstItem('id = ?', [100]);