minond / model
Object models
v1.2.0
2014-03-28 01:45 UTC
Requires
- php: >=5.4.0
- minond/utilitatis: 1.*
This package is not auto-updated.
Last update: 2024-12-16 15:10:26 UTC
README
Models that are simple to create and use. Light weight but easily extensible.
Getters and setters will be simulated using the magic call method:
use Efficio\Dataset\Model; class User extends Model { protected $first_name; protected $last_name; protected $full_name; }
$me = new User; // methods $me->setFirstName('Marcos'); $me->setLastName('Minond'); // or properties $me->first_name = 'Marcos'; $me->last_name = 'Marcos';
Both getter and setter methods may be overwritten:
use Efficio\Dataset\Model; class User extends Model { protected $first_name; protected $last_name; protected $full_name; public function getFullName() { return implode(' ', [ $this->first_name, $this->last_name ]); } }
$me = new User; $me->first_name = 'Marcos'; $me->last_name = 'Marcos'; echo $me->full_name; // outputs 'Marcos Minond'
Traits are used to specify how models are stored:
use Efficio\Dataset\Model; use Efficio\Dataset\Storage\Model\DatabaseStorage; class User extends Model { use DatabaseStorage; protected $first_name; // ... }
Current storage traits are:
Efficio\Dataset\Storage\Model\DatabaseStorage
- store in a database using PDO.Efficio\Dataset\Storage\Model\FileStorage
- store in flat files.Efficio\Dataset\Storage\Model\NullStorage
- no storage.Efficio\Dataset\Storage\Model\SessionStorage
- stored in the$_SESSION
array
Since storage information is defined in the model level any sort of custom storage may be used.
Configuring storage methods
DatabaseStorage
// User uses DatabaseStorage trait User::setConnection(new PDO('sqlite::memory:'));
FileStorage
// User uses FileStorage trait User::setDirectory('./cache/models/');