1 | <?php |
||
11 | class Hydrator |
||
12 | { |
||
13 | const RESOURCE_NAMESPACE = 'WyriHaximus\Travis\Resource\\'; |
||
14 | |||
15 | protected $options; |
||
16 | protected $transport; |
||
17 | protected $hydrators = []; |
||
18 | |||
19 | 48 | public function __construct(Client $transport, array $options) |
|
24 | |||
25 | 48 | public function hydrateFQCN($class, $json): ResourceInterface |
|
29 | |||
30 | 1 | public function hydrate($class, $json): ResourceInterface |
|
31 | { |
||
32 | 1 | $fullClassName = self::RESOURCE_NAMESPACE . $this->options['resource_namespace'] . '\\' . $class; |
|
33 | 1 | return $this->hydrateFQCN($fullClassName, $json); |
|
34 | } |
||
35 | |||
36 | 1 | public function extractFQCN($class, $object): array |
|
40 | |||
41 | public function extract($class, $object): array |
||
46 | |||
47 | 1 | public function buildAsyncFromSync($resource, $object): RepositoryInterface |
|
57 | |||
58 | 48 | protected function getHydrator($class): HydratorInterface |
|
59 | { |
||
60 | 48 | if (isset($this->hydrators[$class])) { |
|
61 | return $this->hydrators[$class]; |
||
62 | } |
||
63 | |||
64 | 48 | $config = new Configuration($class); |
|
65 | 48 | if (isset($this->options['resource_hydrator_cache_dir'])) { |
|
66 | 1 | $config->setGeneratedClassesTargetDir($this->options['resource_hydrator_cache_dir']); |
|
67 | } |
||
68 | 48 | $hydrator = $config->createFactory()->getHydratorClass(); |
|
69 | 48 | $this->hydrators[$class] = new $hydrator; |
|
70 | |||
71 | 48 | return $this->hydrators[$class]; |
|
72 | } |
||
73 | |||
74 | 48 | protected function createObject($class): ResourceInterface |
|
80 | } |
||
81 |