1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
7
|
|
|
* form for use in connection with the web services and APIs provided by |
8
|
|
|
* Facebook. |
9
|
|
|
* |
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace FacebookAds\Object; |
26
|
|
|
|
27
|
|
|
use FacebookAds\Object\Fields\AdAccountFields; |
28
|
|
|
use FacebookAds\Object\Traits\CannotCreate; |
29
|
|
|
use FacebookAds\Object\Traits\CannotDelete; |
30
|
|
|
use FacebookAds\Object\Traits\FieldValidation; |
31
|
|
|
use FacebookAds\Http\RequestInterface; |
32
|
|
|
use FacebookAds\Cursor; |
33
|
|
|
|
34
|
|
|
class AdAccount extends AbstractCrudObject { |
35
|
|
|
use FieldValidation; |
36
|
|
|
use CannotCreate; |
37
|
|
|
use CannotDelete; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
protected function getEndpoint() { |
43
|
|
|
return 'adaccounts'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return AdAccountFields |
48
|
|
|
*/ |
49
|
|
|
public static function getFieldsEnum() { |
50
|
|
|
return AdAccountFields::getInstance(); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $fields |
55
|
|
|
* @param array $params |
56
|
|
|
* @return Cursor |
57
|
|
|
*/ |
58
|
|
|
public function getActivities( |
59
|
|
|
array $fields = array(), array $params = array()) { |
60
|
|
|
return $this->getManyByConnection( |
61
|
|
|
Activity::className(), $fields, $params, 'activities'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param array $fields |
66
|
|
|
* @param array $params |
67
|
|
|
* @return Cursor |
68
|
|
|
*/ |
69
|
|
|
public function getAdUsers(array $fields = array(), array $params = array()) { |
70
|
|
|
return $this->getManyByConnection(AdUser::className(), $fields, $params); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $fields |
75
|
|
|
* @param array $params |
76
|
|
|
* @return Cursor |
77
|
|
|
*/ |
78
|
|
|
public function getCampaigns( |
79
|
|
|
array $fields = array(), array $params = array()) { |
80
|
|
|
return $this->getManyByConnection( |
81
|
|
|
Campaign::className(), $fields, $params); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $fields |
86
|
|
|
* @param array $params |
87
|
|
|
* @return Cursor |
88
|
|
|
*/ |
89
|
|
|
public function getAdSets(array $fields = array(), array $params = array()) { |
90
|
|
|
return $this->getManyByConnection(AdSet::className(), $fields, $params); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param array $fields |
95
|
|
|
* @param array $params |
96
|
|
|
* @return Cursor |
97
|
|
|
*/ |
98
|
|
|
public function getAds( |
99
|
|
|
array $fields = array(), array $params = array()) { |
100
|
|
|
return $this->getManyByConnection(Ad::className(), $fields, $params); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param array $fields |
105
|
|
|
* @param array $params |
106
|
|
|
* @return Cursor |
107
|
|
|
*/ |
108
|
|
|
public function getAdCreatives( |
109
|
|
|
array $fields = array(), array $params = array()) { |
110
|
|
|
return $this->getManyByConnection( |
111
|
|
|
AdCreative::className(), $fields, $params); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param array $fields |
116
|
|
|
* @param array $params |
117
|
|
|
* @return Cursor |
118
|
|
|
*/ |
119
|
|
|
public function getAdImages( |
120
|
|
|
array $fields = array(), array $params = array()) { |
121
|
|
|
return $this->getManyByConnection(AdImage::className(), $fields, $params); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param array $fields |
126
|
|
|
* @param array $params |
127
|
|
|
* @return Cursor |
128
|
|
|
*/ |
129
|
|
|
public function getAdsPixels( |
130
|
|
|
array $fields = array(), array $params = array()) { |
131
|
|
|
return $this->getManyByConnection(AdsPixel::className(), $fields, $params); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param array $fields |
136
|
|
|
* @param array $params |
137
|
|
|
* @return Cursor |
138
|
|
|
*/ |
139
|
|
|
public function getAdVideos( |
140
|
|
|
array $fields = array(), array $params = array()) { |
141
|
|
|
return $this->getManyByConnection(AdVideo::className(), $fields, $params); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param array $fields |
146
|
|
|
* @param array $params |
147
|
|
|
* @return Cursor |
148
|
|
|
*/ |
149
|
|
|
public function getBroadCategoryTargeting( |
150
|
|
|
array $fields = array(), array $params = array()) { |
151
|
|
|
return $this->getManyByConnection( |
152
|
|
|
BroadCategoryTargeting::className(), |
153
|
|
|
$fields, |
154
|
|
|
$params, |
155
|
|
|
'broadtargetingcategories' |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param array $fields |
161
|
|
|
* @param array $params |
162
|
|
|
* @return Cursor |
163
|
|
|
*/ |
164
|
|
|
public function getCustomAudiences( |
165
|
|
|
array $fields = array(), array $params = array()) { |
166
|
|
|
return $this->getManyByConnection( |
167
|
|
|
CustomAudience::className(), $fields, $params); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param array $fields |
172
|
|
|
* @param array $params |
173
|
|
|
* @return Cursor |
174
|
|
|
*/ |
175
|
|
|
public function getConversionPixels( |
176
|
|
|
array $fields = array(), array $params = array()) { |
177
|
|
|
return $this->getManyByConnection( |
178
|
|
|
AdConversionPixel::className(), $fields, $params); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param array $fields |
183
|
|
|
* @param array $params |
184
|
|
|
* @return Cursor |
185
|
|
|
*/ |
186
|
|
|
public function getPartnerCategories( |
187
|
|
|
array $fields = array(), array $params = array()) { |
188
|
|
|
return $this->getManyByConnection( |
189
|
|
|
PartnerCategory::className(), $fields, $params); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param array $fields |
194
|
|
|
* @param array $params |
195
|
|
|
* @return Cursor |
196
|
|
|
*/ |
197
|
|
|
public function getRateCards( |
198
|
|
|
array $fields = array(), array $params = array()) { |
199
|
|
|
return $this->getManyByConnection( |
200
|
|
|
RateCard::className(), $fields, $params, 'ratecard'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param array $fields |
205
|
|
|
* @param array $params |
206
|
|
|
* @return ReachEstimate |
207
|
|
|
*/ |
208
|
|
|
public function getReachEstimate( |
209
|
|
|
array $fields = array(), array $params = array()) { |
210
|
|
|
|
211
|
|
|
return $this->getOneByConnection( |
212
|
|
|
ReachEstimate::className(), $fields, $params, 'reachestimate'); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param array $fields |
217
|
|
|
* @param array $params |
218
|
|
|
* @return Cursor |
219
|
|
|
*/ |
220
|
|
|
public function getReachFrequencyPredictions( |
221
|
|
|
array $fields = array(), array $params = array()) { |
222
|
|
|
return $this->getManyByConnection( |
223
|
|
|
ReachFrequencyPrediction::className(), $fields, $params); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @param array $fields |
228
|
|
|
* @param array $params |
229
|
|
|
* @return TargetingDescription |
230
|
|
|
*/ |
231
|
|
|
public function getTargetingDescription( |
232
|
|
|
array $fields = array(), array $params = array()) { |
233
|
|
|
return $this->getOneByConnection( |
234
|
|
|
TargetingDescription::className(), |
235
|
|
|
$fields, |
236
|
|
|
$params, |
237
|
|
|
'targetingsentencelines'); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param array $fields |
242
|
|
|
* @param array $params |
243
|
|
|
* @return Cursor |
244
|
|
|
*/ |
245
|
|
|
public function getTransactions( |
246
|
|
|
array $fields = array(), array $params = array()) { |
247
|
|
|
return $this->getManyByConnection( |
248
|
|
|
Transaction::className(), $fields, $params, 'transactions'); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param array $fields |
253
|
|
|
* @param array $params |
254
|
|
|
* @return Cursor |
255
|
|
|
*/ |
256
|
|
|
public function getAdPreviews( |
257
|
|
|
array $fields = array(), array $params = array()) { |
258
|
|
|
return $this->getManyByConnection( |
259
|
|
|
AdPreview::classname(), $fields, $params, 'generatepreviews'); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param array $fields |
264
|
|
|
* @param array $params |
265
|
|
|
* @return Cursor |
266
|
|
|
*/ |
267
|
|
|
public function getInsights( |
268
|
|
|
array $fields = array(), array $params = array()) { |
269
|
|
|
return $this->getManyByConnection( |
270
|
|
|
Insights::classname(), $fields, $params, 'insights'); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param array $fields |
275
|
|
|
* @param array $params |
276
|
|
|
* @return AsyncJobInsights |
277
|
|
|
*/ |
278
|
|
|
public function getInsightsAsync( |
279
|
|
|
array $fields = array(), array $params = array()) { |
280
|
|
|
return $this->createAsyncJob( |
281
|
|
|
AsyncJobInsights::className(), $fields, $params); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param array $fields |
286
|
|
|
* @param array $params |
287
|
|
|
* @return Cursor |
288
|
|
|
*/ |
289
|
|
|
public function getAgencies( |
290
|
|
|
array $fields = array(), array $params = array()) { |
291
|
|
|
return $this->getManyByConnection( |
292
|
|
|
Agency::className(), $fields, $params, 'agencies'); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @param int $business_id |
297
|
|
|
* @param array $permitted_roles |
298
|
|
|
*/ |
299
|
|
|
public function grantAgencyAcccess($business_id, $permitted_roles) { |
300
|
|
|
$params = array( |
301
|
|
|
'business' => $business_id, |
302
|
|
|
'permitted_roles' => $permitted_roles, |
303
|
|
|
); |
304
|
|
|
|
305
|
|
|
$this->getApi()->call( |
306
|
|
|
'/'.$this->assureId().'/agencies', |
307
|
|
|
RequestInterface::METHOD_POST, |
308
|
|
|
$params); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param int $business_id |
313
|
|
|
*/ |
314
|
|
|
public function revokeAgencyAccess($business_id) { |
315
|
|
|
$params = array( |
316
|
|
|
'business' => $business_id, |
317
|
|
|
); |
318
|
|
|
|
319
|
|
|
$this->getApi()->call( |
320
|
|
|
'/'.$this->assureId().'/agencies', |
321
|
|
|
RequestInterface::METHOD_DELETE, |
322
|
|
|
$params); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @param array $fields |
327
|
|
|
* @param array $params |
328
|
|
|
* @return Cursor |
329
|
|
|
*/ |
330
|
|
|
public function getMinimumBudgets( |
331
|
|
|
array $fields = array(), array $params = array()) { |
332
|
|
|
return $this->getManyByConnection( |
333
|
|
|
MinimumBudget::className(), $fields, $params, 'minimum_budgets'); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @param array $fields |
338
|
|
|
* @param array $params |
339
|
|
|
* @return Cursor |
340
|
|
|
*/ |
341
|
|
|
public function getAdPlacePageSets( |
342
|
|
|
array $fields = array(), array $params = array()) { |
343
|
|
|
return $this->getManyByConnection( |
344
|
|
|
AdPlacePageSet::className(), $fields, $params); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @param array $fields |
349
|
|
|
* @param array $params |
350
|
|
|
* @return Cursor |
351
|
|
|
*/ |
352
|
|
|
public function getAdLabels( |
353
|
|
|
array $fields = array(), array $params = array()) { |
354
|
|
|
return $this->getManyByConnection( |
355
|
|
|
AdLabel::className(), $fields, $params); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @param array $fields |
360
|
|
|
* @param array $params |
361
|
|
|
* @return Cursor |
362
|
|
|
*/ |
363
|
|
|
public function getCampaignsByLabel( |
364
|
|
|
array $fields = array(), array $params = array()) { |
365
|
|
|
return $this->getManyByConnection( |
366
|
|
|
Campaign::classname(), $fields, $params, 'campaignsbylabels'); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @param array $fields |
371
|
|
|
* @param array $params |
372
|
|
|
* @return Cursor |
373
|
|
|
*/ |
374
|
|
|
public function getAdSetsByLabel( |
375
|
|
|
array $fields = array(), array $params = array()) { |
376
|
|
|
return $this->getManyByConnection( |
377
|
|
|
AdSet::classname(), $fields, $params, 'adsetsbylabels'); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @param array $fields |
382
|
|
|
* @param array $params |
383
|
|
|
* @return Cursor |
384
|
|
|
*/ |
385
|
|
|
public function getAdsByLabel( |
386
|
|
|
array $fields = array(), array $params = array()) { |
387
|
|
|
return $this->getManyByConnection( |
388
|
|
|
Ad::classname(), $fields, $params, 'adsbylabels'); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @param array $fields |
393
|
|
|
* @param array $params |
394
|
|
|
* @return Cursor |
395
|
|
|
*/ |
396
|
|
|
public function getAdCreativesByLabel( |
397
|
|
|
array $fields = array(), array $params = array()) { |
398
|
|
|
return $this->getManyByConnection( |
399
|
|
|
AdCreative::classname(), $fields, $params, 'adcreativesbylabels'); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @param array $fields |
404
|
|
|
* @param array $params |
405
|
|
|
* @return Cursor |
406
|
|
|
*/ |
407
|
|
|
public function getCustomConversions ( |
408
|
|
|
array $fields = array(), array $params = array()) { |
409
|
|
|
return $this->getManyByConnection( |
410
|
|
|
CustomConversion::className(), $fields, $params); |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.