Rev 51 | Rev 53 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 51 | Rev 52 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | <?php
|
1 | <?php
|
| 2 | 2 | ||
| 3 | require_once __DIR__ . '/AbstractModel.php'; |
3 | namespace PointedEars\PHPX; |
| 4 | 4 | ||
| 5 | /**
|
5 | /**
|
| 6 | * Abstract model class for Object-Relational Mapping
|
6 | * Abstract model class for Object-Relational Mapping
|
| 7 | *
|
7 | *
|
| 8 | * Provides simple mapping of a model object to records of
|
8 | * Provides simple mapping of a model object to records of
|
| 9 | * a table of a relational database.
|
9 | * a table of a relational database.
|
| 10 | *
|
10 | *
|
| 11 | * @author Thomas Lahn
|
11 | * @author Thomas Lahn
|
| 12 | */
|
12 | */
|
| 13 | abstract class Model extends AbstractModel |
13 | abstract class Model extends \PointedEars\PHPX\AbstractModel |
| 14 | {
|
14 | {
|
| 15 | /**
|
15 | /**
|
| 16 | * The <code>Table</code> for instances of this model
|
16 | * The <code>Table</code> for instances of this model
|
| 17 | *
|
17 | *
|
| 18 | * @type Table|string
|
18 | * @type Table|string
|
| Line 67... | Line 67... | ||
| 67 | $this->_persistentTable = $value; |
67 | $this->_persistentTable = $value; |
| 68 | }
|
68 | }
|
| 69 | else
|
69 | else
|
| 70 | {
|
70 | {
|
| 71 | $table = new $value(); |
71 | $table = new $value(); |
| 72 | if (!($table instanceof Table)) |
72 | if (!($table instanceof Db\Table)) |
| 73 | {
|
73 | {
|
| 74 | throw new \InvalidArgumentException( |
74 | throw new \InvalidArgumentException( |
| 75 | 'Expected Table instance or string for table name, saw '
|
75 | 'Parameter does not specify a subclass of \\PointedEars\\PHPX\\Table: '
|
| 76 | . (\get_class($value) || \gettype($value)) |
76 | . $value |
| 77 | ); |
77 | ); |
| 78 | }
|
78 | }
|
| 79 | 79 | ||
| 80 | $this->_persistentTable = $table; |
80 | $this->_persistentTable = $table; |
| 81 | }
|
81 | }
|
| Line 123... | Line 123... | ||
| 123 | * if there is no data for this object
|
123 | * if there is no data for this object
|
| 124 | */
|
124 | */
|
| 125 | public function find () |
125 | public function find () |
| 126 | {
|
126 | {
|
| 127 | $result = $this->persistentTable->find( |
127 | $result = $this->persistentTable->find( |
| 128 | $this->{$this->__persistentId}); |
128 | $this->{$this->_persistentId}); |
| 129 | if ($result) |
129 | if ($result) |
| 130 | {
|
130 | {
|
| 131 | return $this->map($result); |
131 | return $this->map($result); |
| 132 | }
|
132 | }
|
| 133 | 133 | ||