-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathArrayObjectFactory.php
More file actions
67 lines (60 loc) · 2.58 KB
/
Copy pathArrayObjectFactory.php
File metadata and controls
67 lines (60 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Tpay\OpenApi\Factory;
use InvalidArgumentException;
use Tpay\OpenApi\Model\Objects\Accounts\Address as AccountAddress;
use Tpay\OpenApi\Model\Objects\Accounts\Person;
use Tpay\OpenApi\Model\Objects\Accounts\PointOfSale as AccountPointOfSale;
use Tpay\OpenApi\Model\Objects\Merchant\Address as MerchantAddress;
use Tpay\OpenApi\Model\Objects\Merchant\ContactPerson;
use Tpay\OpenApi\Model\Objects\Merchant\PointOfSale as MerchantPointOfSale;
use Tpay\OpenApi\Model\Objects\Objects;
use Tpay\OpenApi\Model\Objects\Recurring\RetryInterval;
use Tpay\OpenApi\Model\Objects\Recurring\Schedule;
use Tpay\OpenApi\Model\Objects\RequestBody\Account;
use Tpay\OpenApi\Model\Objects\RequestBody\Merchant;
class ArrayObjectFactory
{
public function create($fieldName, $parentObject)
{
if (!$parentObject instanceof Objects) {
throw new InvalidArgumentException(sprintf(
'Parent object must extend %s, got %s',
Objects::class,
is_object($parentObject) ? get_class($parentObject) : gettype($parentObject)
));
}
if ($parentObject instanceof Merchant) {
switch ($fieldName) {
case 'address':
return new MerchantAddress();
case 'website':
return new MerchantPointOfSale();
case 'contactPerson':
return new ContactPerson();
default:
throw new InvalidArgumentException(sprintf('Unsupported field "%s" in %s', $fieldName, $parentObject->getName()));
}
}
if ($parentObject instanceof Account) {
switch ($fieldName) {
case 'address':
return new AccountAddress();
case 'website':
return new AccountPointOfSale();
case 'person':
return new Person();
default:
throw new InvalidArgumentException(sprintf('Unsupported field "%s" in %s', $fieldName, $parentObject->getName()));
}
}
if ($parentObject instanceof Schedule) {
switch ($fieldName) {
case 'retryIntervals':
return new RetryInterval();
default:
throw new InvalidArgumentException(sprintf('Unsupported field "%s" in %s', $fieldName, $parentObject->getName()));
}
}
throw new InvalidArgumentException(sprintf('Field %s as array is not supported in %s object', $fieldName, $parentObject->getName()));
}
}