This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
DoctrineHydrator.php
78 lines (68 loc) · 1.59 KB
/
DoctrineHydrator.php
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
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Phpro\DoctrineHydrationModule\Hydrator;
use Zend\Hydrator\HydratorInterface;
/**
* Class DoctrineHydrator.
*/
class DoctrineHydrator implements HydratorInterface
{
/**
* @var HydratorInterface
*/
protected $extractService;
/**
* @var HydratorInterface
*/
protected $hydrateService;
/**
* @param $extractService
* @param $hydrateService
*/
public function __construct($extractService, $hydrateService)
{
$this->extractService = $extractService;
$this->hydrateService = $hydrateService;
}
/**
* @return \Zend\Hydrator\HydratorInterface
*/
public function getExtractService()
{
return $this->extractService;
}
/**
* @return \Zend\Hydrator\HydratorInterface
*/
public function getHydrateService()
{
return $this->hydrateService;
}
/**
* Extract values from an object.
*
* @param object $object
*
* @return array
*/
public function extract($object)
{
return $this->extractService->extract($object);
}
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param object $object
*
* @return object
*/
public function hydrate(array $data, $object)
{
// Zend hydrator:
if ($this->hydrateService instanceof HydratorInterface) {
return $this->hydrateService->hydrate($data, $object);
}
// Doctrine hydrator: (parameters switched)
return $this->hydrateService->hydrate($object, $data);
}
}