1 | <?php |
||
14 | class EntriesRepository |
||
15 | { |
||
16 | use Traits\EntryType; |
||
17 | |||
18 | /** |
||
19 | * Truncate all tables extending a ContentfulModel. |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | public function truncateRelatedTables() |
||
44 | |||
45 | /** |
||
46 | * Map Contentful entry payload to an Eloquent one. |
||
47 | * |
||
48 | * @param array $entry |
||
49 | * @return void |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | public function toContentfulModel(array $entry, Collection $locales) |
||
72 | |||
73 | /** |
||
74 | * Delete entry and relationships. |
||
75 | * |
||
76 | * @param array $entry |
||
77 | * @return void |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | public function delete(array $entry) |
||
87 | |||
88 | // -------------------------------------------------------------------------------- |
||
89 | // -------------------------------------------------------------------------------- |
||
90 | // -------------------------------------------------------------------------------- |
||
91 | |||
92 | /** |
||
93 | * Return entry content-type. |
||
94 | * |
||
95 | * @param array $entry |
||
96 | * @return string |
||
97 | */ |
||
98 | private function entryContentType(array $entry): string |
||
102 | |||
103 | /** |
||
104 | * Return entry content-type mapper class instance. |
||
105 | * |
||
106 | * @param array $entry |
||
107 | * @return \Distilleries\Contentful\Models\Base\ContentfulMapper |
||
108 | * @throws \Exception |
||
109 | */ |
||
110 | private function entryMapper(array $entry): ContentfulMapper |
||
121 | |||
122 | /** |
||
123 | * Return entry content-type model class instance. |
||
124 | * |
||
125 | * @param array $entry |
||
126 | * @return \Distilleries\Contentful\Models\Base\ContentfulModel |
||
127 | * @throws \Exception |
||
128 | */ |
||
129 | private function entryModel(array $entry): ContentfulModel |
||
140 | |||
141 | // -------------------------------------------------------------------------------- |
||
142 | // -------------------------------------------------------------------------------- |
||
143 | // -------------------------------------------------------------------------------- |
||
144 | |||
145 | /** |
||
146 | * Handle mapped relationships to fill `entry_relationships` pivot table. |
||
147 | * |
||
148 | * @param string $locale |
||
149 | * @param string $sourceId |
||
150 | * @param string $sourceType |
||
151 | * @param array $relationships |
||
152 | * @return void |
||
153 | * @throws \Exception |
||
154 | */ |
||
155 | private function handleRelationships(string $locale, string $sourceId, string $sourceType, array $relationships = []) |
||
185 | |||
186 | /** |
||
187 | * Delete entry relationships for given Contentful entry. |
||
188 | * |
||
189 | * @param array $entry |
||
190 | * @return void |
||
191 | */ |
||
192 | private function deleteRelationships(array $entry) |
||
199 | |||
200 | // -------------------------------------------------------------------------------- |
||
201 | // -------------------------------------------------------------------------------- |
||
202 | // -------------------------------------------------------------------------------- |
||
203 | |||
204 | /** |
||
205 | * Return inserted / updated model instance for given parameters. |
||
206 | * |
||
207 | * @param array $entry |
||
208 | * @param array $data |
||
209 | * @return \Distilleries\Contentful\Models\Base\ContentfulModel|null |
||
210 | * @throws \Exception |
||
211 | */ |
||
212 | private function upsertLocale(array $entry, array $data): ?ContentfulModel |
||
233 | |||
234 | /** |
||
235 | * Override Eloquent entry with all fillable data. |
||
236 | * |
||
237 | * @param \Distilleries\Contentful\Models\Base\ContentfulModel $model |
||
238 | * @param array $data |
||
239 | * @return void |
||
240 | */ |
||
241 | private function overridePayloadAndExtraFillables(ContentfulModel $model, array $data) |
||
257 | |||
258 | /** |
||
259 | * Return Eloquent QueryBuilder to target given entry. |
||
260 | * |
||
261 | * @param \Distilleries\Contentful\Models\Base\ContentfulModel $model |
||
262 | * @param array $data |
||
263 | * @return \Illuminate\Database\Eloquent\Builder |
||
264 | */ |
||
265 | private function instanceQueryBuilder(ContentfulModel $model, array $data): Builder |
||
271 | } |
||
272 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.