1 | <?php |
||
12 | class OracleEloquent extends Model |
||
13 | { |
||
14 | /** |
||
15 | * List of binary (blob) columns. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $binaries = []; |
||
20 | |||
21 | /** |
||
22 | * List of binary fields for storage. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $binaryFields = []; |
||
27 | |||
28 | /** |
||
29 | * Sequence name variable |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $sequence = null; |
||
34 | |||
35 | /** |
||
36 | * Get model's sequence name |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getSequenceName() |
||
48 | |||
49 | /** |
||
50 | * Set sequence name. |
||
51 | * |
||
52 | * @param string $name |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function setSequenceName($name) |
||
56 | { |
||
57 | $this->sequence = $name; |
||
58 | |||
59 | return $this; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Update the model in the database. |
||
64 | * |
||
65 | * @param array $attributes |
||
66 | * @param array $options |
||
67 | * @return bool|int |
||
68 | */ |
||
69 | public function update(array $attributes = [], array $options = []) |
||
70 | { |
||
71 | if (! $this->exists) { |
||
72 | // If dirty attributes contains binary field |
||
73 | // extract binary fields to new array |
||
74 | if ($this->extractBinaries($dirty)) { |
||
75 | return $this->newQuery()->updateLob($attributes, $this->binaryFields, $this->getKeyName()); |
||
76 | } |
||
77 | |||
78 | return $this->newQuery()->update($attributes); |
||
79 | } |
||
80 | |||
81 | return $this->fill($attributes)->save($options); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Extract binary fields from given attributes. |
||
86 | * |
||
87 | * @param array $attributes |
||
88 | * @return array |
||
89 | */ |
||
90 | protected function extractBinaries(&$attributes) |
||
91 | { |
||
92 | // If attributes contains binary field |
||
93 | // extract binary fields to new array |
||
94 | $binaries = []; |
||
95 | if ($this->checkBinary($attributes) && $this->getConnection() instanceof Oci8Connection) { |
||
96 | foreach ($attributes as $key => $value) { |
||
97 | if (in_array($key, $this->binaries)) { |
||
98 | $binaries[$key] = $value; |
||
99 | unset($attributes[$key]); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | |||
104 | return $this->binaryFields = $binaries; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Check if attributes contains binary field. |
||
109 | * |
||
110 | * @param array $attributes |
||
111 | * @return boolean |
||
112 | */ |
||
113 | protected function checkBinary(array $attributes) |
||
114 | { |
||
115 | foreach ($attributes as $key => $value) { |
||
116 | // if attribute is in binary field list |
||
117 | if (in_array($key, $this->binaries)) { |
||
118 | return true; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | return false; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Get the table qualified key name. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getQualifiedKeyName() |
||
131 | { |
||
132 | $pos = strpos($this->getTable(), '@'); |
||
133 | |||
134 | if ($pos === false) { |
||
135 | return $this->getTable() . '.' . $this->getKeyName(); |
||
136 | } else { |
||
137 | $table = substr($this->getTable(), 0, $pos); |
||
138 | $dbLink = substr($this->getTable(), $pos); |
||
139 | |||
140 | return $table . '.' . $this->getKeyName() . $dbLink; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Get a new query builder instance for the connection. |
||
146 | * |
||
147 | * @return \Illuminate\Database\Query\Builder|\Yajra\Oci8\Query\OracleBuilder |
||
148 | */ |
||
149 | 15 | protected function newBaseQueryBuilder() |
|
150 | { |
||
151 | |||
152 | 15 | $conn = $this->getConnection(); |
|
153 | 15 | $grammar = $conn->getQueryGrammar(); |
|
154 | |||
155 | 15 | if ($grammar instanceof OracleGrammar) { |
|
156 | 3 | return new QueryBuilder($conn, $grammar, $conn->getPostProcessor()); |
|
157 | } |
||
158 | |||
159 | 12 | return new IlluminateQueryBuilder($conn, $grammar, $conn->getPostProcessor()); |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * Perform a model update operation. |
||
164 | * |
||
165 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
166 | * @param array $options |
||
167 | * @return boolean |
||
168 | */ |
||
169 | protected function performUpdate(Builder $query, array $options = []) |
||
204 | |||
205 | /** |
||
206 | * Update model with binary (blob) fields. |
||
207 | * |
||
208 | * @param Builder $query |
||
209 | * @param array $dirty |
||
210 | * @param array $options |
||
211 | */ |
||
212 | protected function updateBinary(Builder $query, $dirty, $options = []) |
||
220 | |||
221 | /** |
||
222 | * Perform a model insert operation. |
||
223 | * |
||
224 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
225 | * @param array $options |
||
226 | * @return bool |
||
227 | */ |
||
228 | protected function performInsert(Builder $query, array $options = []) |
||
274 | |||
275 | /** |
||
276 | * Insert the given attributes and set the ID on the model. |
||
277 | * |
||
278 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
279 | * @param array $attributes |
||
280 | * @return int|void |
||
281 | */ |
||
282 | protected function insertAndSetId(Builder $query, $attributes) |
||
292 | } |
||
293 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.