1 | <?php |
||
32 | abstract class Relationship |
||
33 | { |
||
34 | /** |
||
35 | * Constant for the belongs-to or one-to many relation ship. |
||
36 | */ |
||
37 | const BELONGS_TO = 'BelongsTo'; |
||
38 | |||
39 | const HAS_MANY = 'HasMany'; |
||
40 | const MANY_HAVE_MANY = 'ManyHaveMany'; |
||
41 | |||
42 | protected $options = []; |
||
43 | protected $type; |
||
44 | protected $setupName; |
||
45 | protected $setupTable; |
||
46 | protected $setupSchema; |
||
47 | protected $setupPrimaryKey; |
||
48 | |||
49 | private $setup = false; |
||
50 | private $query; |
||
51 | protected $queryPrepared = false; |
||
52 | protected $invalidFields = []; |
||
53 | |||
54 | 24 | public function setOptions($options) |
|
55 | { |
||
56 | 24 | $this->options = $options; |
|
57 | 24 | } |
|
58 | |||
59 | 8 | public function createQuery() |
|
|
|||
60 | { |
||
61 | 8 | if (!$this->query) { |
|
62 | 8 | $this->query = new QueryParameters(); |
|
63 | } |
||
64 | 8 | return $this->query; |
|
65 | } |
||
66 | |||
67 | 8 | public function getOptions() |
|
71 | |||
72 | 8 | private function initialize() |
|
73 | { |
||
79 | |||
80 | /** |
||
81 | * Gets an instance of the related model accessed through this class. |
||
82 | * |
||
83 | * @return RecordWrapper |
||
84 | * @throws exceptions\NibiiException |
||
85 | */ |
||
86 | 8 | public function getModelInstance() |
|
91 | |||
92 | 24 | public function setup($name, $schema, $table, $primaryKey) |
|
99 | |||
100 | public function getInvalidFields() |
||
104 | |||
105 | 8 | public function prepareQuery($data) |
|
110 | |||
111 | abstract public function preSave(&$wrapper, $value); |
||
112 | |||
113 | abstract public function postSave(&$wrapper); |
||
114 | |||
115 | abstract protected function doPrepareQuery($data); |
||
116 | |||
117 | /** |
||
118 | * @todo Cleanup this method. |
||
119 | * There should be a get Parameters method instead which returns the values |
||
120 | * that are passed to setup. Initialize should be the main wrapper arround |
||
121 | * this. |
||
122 | * |
||
123 | */ |
||
124 | abstract public function runSetup(); |
||
125 | } |
||
126 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.