Skip to content

Commit

Permalink
Added DateTime Strategy, refactored hydrator definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jguittard committed Jun 26, 2015
1 parent 338d565 commit 2e1e074
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getHydratorConfig()
{
return [
'invokables' => [
'Zoho\Subscriptions\Hydrator\CustomerHydrator' => 'Zoho\Subscriptions\Hydrator\CustomerHydrator',
'Zoho\Subscriptions\Hydrator\Customer' => 'Zoho\Subscriptions\Hydrator\CustomerHydrator',
]
];
}
Expand Down
30 changes: 7 additions & 23 deletions src/Factory/ResourceAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
$zohoConfig = $config['zoho'];
$resourceConfig = $config['zoho']['resources'][$requestedName];

/*$opensslCapath = ini_get('openssl.capath');
if (!empty($opensslCapath)) {
$clientConfig = ['sslcapath' => $opensslCapath];
} else {
$clientConfig = ['sslcapath' => $zohoConfig['ssl_config']['sslcapath']];
}
$httpClient = new Client(null, $clientConfig);
$httpClient->setHeaders(array(
'Content-Type' => 'application/json;charset=UTF-8',
'X-com-zoho-subscriptions-organizationid' => $zohoConfig['organization_id'],
'Authorization' => 'Zoho-authtoken ' . $zohoConfig['auth_token'],
));
$resource = new Resource($httpClient);*/
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
Expand All @@ -130,14 +114,14 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
$inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']);
$resource->setInputFilter($inputFilter);

$hydrator = new ClassMethods(true);
$hydratorManager = $serviceLocator->get('HydratorManager');

$hydratorName = str_replace('Entity', 'Hydrator', $entityClass);

if (isset($resourceConfig['strategies']) && is_array($resourceConfig['strategies'])) {
foreach ($resourceConfig['strategies'] as $field => $strategy) {
if ($serviceLocator->has($strategy)) {
$hydrator->addStrategy($field, $serviceLocator->get($strategy));
}
}
if ($hydratorManager->hast($hydratorName)) {
$hydrator = $hydratorManager->get($hydratorName);
} else {
$hydrator = new ClassMethods();
}

$resource->setHydrator($hydrator);
Expand Down
4 changes: 4 additions & 0 deletions src/Hydrator/CustomerHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Zoho\Subscriptions\Hydrator;

use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
use Zend\Stdlib\Hydrator\Strategy\DateTimeFormatterStrategy;
use Zoho\Subscriptions\Hydrator\Strategy\AddressStrategy;

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

$addressStrategy = new AddressStrategy();
$datetimeStrategy = new DateTimeFormatterStrategy(\DateTime::ISO8601);
$this->addStrategy('billing_address', $addressStrategy);
$this->addStrategy('shipping_address', $addressStrategy);
$this->addStrategy('created_time', $datetimeStrategy);
$this->addStrategy('updated_time', $datetimeStrategy);
}
}

0 comments on commit 2e1e074

Please sign in to comment.