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