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 getQuery() |
|
|
|||
60 | { |
||
61 | 8 | if (!$this->query) { |
|
62 | 8 | $this->query = new QueryParameters(); |
|
63 | } |
||
64 | |||
65 | 8 | return $this->query; |
|
66 | } |
||
67 | |||
68 | 8 | public function getOptions() |
|
69 | { |
||
70 | 8 | return $this->options; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Gets an instance of the related model accessed through this class. |
||
75 | * |
||
76 | * @return RecordWrapper |
||
77 | * @throws exceptions\NibiiException |
||
78 | */ |
||
79 | 8 | public function getModelInstance() |
|
80 | { |
||
81 | 8 | if (!$this->setup) { |
|
82 | 8 | $this->runSetup(); |
|
83 | 8 | $this->setup = true; |
|
84 | } |
||
85 | |||
86 | 8 | return ORMContext::getInstance()->getModelFactory()->createModel($this->options['model'], $this->type); |
|
87 | } |
||
88 | |||
89 | 24 | public function setup($name, $schema, $table, $primaryKey) |
|
90 | { |
||
91 | 24 | $this->setupName = $name; |
|
92 | 24 | $this->setupTable = $table; |
|
93 | 24 | $this->setupPrimaryKey = $primaryKey; |
|
94 | 24 | $this->setupSchema = $schema; |
|
95 | 24 | } |
|
96 | |||
97 | public function getInvalidFields() |
||
98 | { |
||
99 | return $this->invalidFields; |
||
100 | } |
||
101 | |||
102 | abstract public function preSave(&$wrapper, $value); |
||
103 | |||
104 | abstract public function postSave(&$wrapper); |
||
105 | |||
106 | abstract public function prepareQuery($data); |
||
107 | |||
108 | abstract public function runSetup(); |
||
109 | } |
||
110 |
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.