|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Marek\Toggable\Hydrator; |
|
4
|
|
|
|
|
5
|
|
|
use Marek\Toggable\Hydrator\Strategy\BlogPostStrategy; |
|
6
|
|
|
use Marek\Toggable\Hydrator\Strategy\DateStrategy; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class BaseHydrator |
|
10
|
|
|
* @package Marek\Toggable\Hydrator |
|
11
|
|
|
*/ |
|
12
|
|
|
abstract class BaseHydrator implements HydratorInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var HydratorInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $hydrator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DataHydrator constructor. |
|
21
|
|
|
*/ |
|
22
|
62 |
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
62 |
|
$this->hydrator = new ObjectProperty(); |
|
25
|
62 |
|
$this->hydrator->addStrategy('at', new DateStrategy()); |
|
26
|
62 |
|
$this->hydrator->addStrategy('created_at', new DateStrategy()); |
|
27
|
62 |
|
$this->hydrator->addStrategy('deleted_at', new DateStrategy()); |
|
28
|
62 |
|
$this->hydrator->addStrategy('updated_at', new DateStrategy()); |
|
29
|
62 |
|
$this->hydrator->addStrategy('server_deleted_at', new DateStrategy()); |
|
30
|
62 |
|
$this->hydrator->addStrategy('start', new DateStrategy()); |
|
31
|
62 |
|
$this->hydrator->addStrategy('stop', new DateStrategy()); |
|
32
|
62 |
|
$this->hydrator->addStrategy('vat_validated_at', new DateStrategy()); |
|
33
|
62 |
|
$this->hydrator->addStrategy('vat_invalid_accepted_at', new DateStrategy()); |
|
34
|
62 |
|
$this->hydrator->addStrategy('new_blog_post', new BlogPostStrategy()); |
|
35
|
62 |
|
$this->hydrator->addStrategy('last_blog_entry', new BlogPostStrategy()); |
|
36
|
62 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
12 |
|
public function hydrate(array $data, $object) |
|
42
|
|
|
{ |
|
43
|
12 |
|
return $this->hydrator->hydrate($data, $object); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
12 |
|
public function extract($object) |
|
50
|
|
|
{ |
|
51
|
12 |
|
return $this->hydrator->extract($object); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|