Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // UnitOfWork + DataMapper pattern
- // Ideally clear DTO
- class Person
- {
- public $name;
- public $age;
- }
- // plus a mapper / or a config (xml / yml / php ) file
- class PersonMapper extends DataMap
- {
- // overriden properties, specifying how to map this item
- private $tableName = 'users';
- private $primaryKey = 'name';
- }
- class UnitOfWork
- {
- private $databaseConnection;
- public function Insert( object ) { getMappingDataFromPersonMapper }
- public function Update( object )
- public function Delete( object )
- public function LoadById( int $id )
- public function LoadByParams( array $arr )
- }
- //Usage:
- $Person = $UnitOfWork->LoadById(1);
- $Person->age++;
- $UnitOfWork->update($Person);
- //-------------------------------------------------------//
- //-------------------------------------------------------//
- //-------------------------------------------------------//
- // Active record pattern
- class ActivePerson extends ActiveRecordBase
- {
- public $name;
- public $age;
- // inherited members / objects
- private $tableName = 'users';
- private $primaryKey = 'name';
- public function save()
- public static function findByParams( arary $x = ['name' => 'Alex'] )
- public static function loadById( int $id )
- public function delete()
- }
- //usage
- $Person = ActivePerson::loadById(1);
- $Person->age++;
- $Person->save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement