Rev 29 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
27 | PointedEar | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Abstract model class |
||
5 | * |
||
6 | * Provides basic setters and getters for protected/private properties |
||
7 | * and a constructor to initialize properties using setters and getters. |
||
8 | * |
||
9 | * @author Thomas Lahn |
||
10 | */ |
||
11 | abstract class Model extends AbstractModel |
||
12 | { |
||
13 | /* ORM */ |
||
14 | const persistentPrimaryKey = 'id'; |
||
15 | |||
16 | /** |
||
17 | * @var Adapter |
||
18 | */ |
||
19 | protected static $persistentAdapter; |
||
20 | |||
21 | /** |
||
22 | * Creates a new model object |
||
23 | * |
||
24 | * @param array $data Initialization data (optional) |
||
25 | * @param array $mapping Mapping for initialization data (optional) |
||
26 | */ |
||
27 | public function __construct(array $data = null, array $mapping = null) |
||
28 | { |
||
29 | $this->setAdapter(); |
||
30 | |||
31 | parent::__construct($data, $mapping); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Finds the record for the model object in a database, and fills the object |
||
36 | * with missing data |
||
37 | * @see Adapter::find(Model) |
||
38 | */ |
||
39 | public function find() |
||
40 | { |
||
41 | $class = get_class($this); |
||
42 | return $class::$persistentAdapter->find($this); |
||
43 | } |
||
44 | } |