Skip to content

Commit 2e1e074

Browse files
committed
Added DateTime Strategy, refactored hydrator definition
1 parent 338d565 commit 2e1e074

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getHydratorConfig()
5353
{
5454
return [
5555
'invokables' => [
56-
'Zoho\Subscriptions\Hydrator\CustomerHydrator' => 'Zoho\Subscriptions\Hydrator\CustomerHydrator',
56+
'Zoho\Subscriptions\Hydrator\Customer' => 'Zoho\Subscriptions\Hydrator\CustomerHydrator',
5757
]
5858
];
5959
}

src/Factory/ResourceAbstractFactory.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
9696
$zohoConfig = $config['zoho'];
9797
$resourceConfig = $config['zoho']['resources'][$requestedName];
9898

99-
/*$opensslCapath = ini_get('openssl.capath');
100-
101-
if (!empty($opensslCapath)) {
102-
$clientConfig = ['sslcapath' => $opensslCapath];
103-
} else {
104-
$clientConfig = ['sslcapath' => $zohoConfig['ssl_config']['sslcapath']];
105-
}
106-
107-
$httpClient = new Client(null, $clientConfig);
108-
$httpClient->setHeaders(array(
109-
'Content-Type' => 'application/json;charset=UTF-8',
110-
'X-com-zoho-subscriptions-organizationid' => $zohoConfig['organization_id'],
111-
'Authorization' => 'Zoho-authtoken ' . $zohoConfig['auth_token'],
112-
));
113-
114-
$resource = new Resource($httpClient);*/
11599
$curl = curl_init();
116100
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
117101
curl_setopt($curl, CURLOPT_HTTPHEADER, [
@@ -130,14 +114,14 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
130114
$inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']);
131115
$resource->setInputFilter($inputFilter);
132116

133-
$hydrator = new ClassMethods(true);
117+
$hydratorManager = $serviceLocator->get('HydratorManager');
118+
119+
$hydratorName = str_replace('Entity', 'Hydrator', $entityClass);
134120

135-
if (isset($resourceConfig['strategies']) && is_array($resourceConfig['strategies'])) {
136-
foreach ($resourceConfig['strategies'] as $field => $strategy) {
137-
if ($serviceLocator->has($strategy)) {
138-
$hydrator->addStrategy($field, $serviceLocator->get($strategy));
139-
}
140-
}
121+
if ($hydratorManager->hast($hydratorName)) {
122+
$hydrator = $hydratorManager->get($hydratorName);
123+
} else {
124+
$hydrator = new ClassMethods();
141125
}
142126

143127
$resource->setHydrator($hydrator);

src/Hydrator/CustomerHydrator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Zoho\Subscriptions\Hydrator;
44

55
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
6+
use Zend\Stdlib\Hydrator\Strategy\DateTimeFormatterStrategy;
67
use Zoho\Subscriptions\Hydrator\Strategy\AddressStrategy;
78

89
class CustomerHydrator extends ClassMethodsHydrator
@@ -12,7 +13,10 @@ public function __construct()
1213
parent::__construct();
1314

1415
$addressStrategy = new AddressStrategy();
16+
$datetimeStrategy = new DateTimeFormatterStrategy(\DateTime::ISO8601);
1517
$this->addStrategy('billing_address', $addressStrategy);
1618
$this->addStrategy('shipping_address', $addressStrategy);
19+
$this->addStrategy('created_time', $datetimeStrategy);
20+
$this->addStrategy('updated_time', $datetimeStrategy);
1721
}
1822
}

0 commit comments

Comments
 (0)