|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Darkilliant\ImportBundle\Step; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
6
|
|
|
use Darkilliant\ImportBundle\Loader\ObjectLoader; |
|
7
|
|
|
use Darkilliant\ImportBundle\TargetResolver\DoctrineTargetResolver; |
|
8
|
|
|
use Darkilliant\ProcessBundle\State\ProcessState; |
|
9
|
|
|
use Darkilliant\ProcessBundle\Step\AbstractConfigurableStep; |
|
10
|
|
|
|
|
11
|
|
|
class LoadObjectStep extends AbstractConfigurableStep |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var ObjectLoader */ |
|
14
|
|
|
private $loader; |
|
15
|
|
|
|
|
16
|
|
|
/** @var DoctrineTargetResolver */ |
|
17
|
|
|
private $resolver; |
|
18
|
|
|
|
|
19
|
4 |
|
public function __construct(ObjectLoader $loader, DoctrineTargetResolver $resolver) |
|
20
|
|
|
{ |
|
21
|
4 |
|
$this->loader = $loader; |
|
22
|
4 |
|
$this->resolver = $resolver; |
|
23
|
4 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function configureOptionResolver(OptionsResolver $resolver): OptionsResolver |
|
26
|
|
|
{ |
|
27
|
|
|
$resolver |
|
28
|
1 |
|
->setRequired(['target_mapping', 'target_resolver']); |
|
29
|
|
|
|
|
30
|
1 |
|
return parent::configureOptionResolver($resolver); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param ProcessState $state |
|
35
|
|
|
* |
|
36
|
|
|
* @throws \Exception |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function execute(ProcessState $state) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$object = $this->loader->load( |
|
41
|
1 |
|
$this->resolver->resolve( |
|
42
|
1 |
|
$state->getOptions()['target_resolver'] |
|
43
|
|
|
), |
|
44
|
1 |
|
$state->getData(), |
|
45
|
1 |
|
$state->getOptions()['target_mapping'] |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
1 |
|
$state->setContext('class', get_class($object)); |
|
49
|
1 |
|
$state->setContext('id', $object->getId()); |
|
50
|
|
|
|
|
51
|
1 |
|
$state->info('create object'); |
|
52
|
|
|
|
|
53
|
1 |
|
$state->setData($object); |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function describe(ProcessState $state) |
|
57
|
|
|
{ |
|
58
|
1 |
|
$state->info('create object {class} with array data', [ |
|
59
|
1 |
|
'class' => $state->getOptions()['target_resolver']['entityClass'] ?? '', |
|
60
|
|
|
]); |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
public static function isDeprecated(): bool |
|
64
|
|
|
{ |
|
65
|
1 |
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|