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