1 | <?php |
||
26 | final class VarReplace implements ActionInterface, VarAwareInterface |
||
27 | { |
||
28 | use VarAwareTrait; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | 2 | public function execute() |
|
34 | { |
||
35 | try { |
||
36 | /** @var Finder $finder */ |
||
37 | 2 | $finder = Finder::create() |
|
38 | 2 | ->in($this->vars['skeleton']) |
|
39 | 2 | ->ignoreDotFiles(false); |
|
40 | 2 | $keys = $this->vars->keys(); |
|
41 | |||
42 | 2 | $keys->each(function ($variable) use ($finder) { |
|
43 | 2 | $finder->contains(sprintf(':%s:', $variable)); |
|
44 | 2 | }); |
|
45 | |||
46 | 2 | $variables = $keys->map(function ($item) { |
|
47 | 2 | return sprintf(':%s:', $item); |
|
48 | 2 | })->toArray(); |
|
49 | |||
50 | 2 | foreach ($finder as $file) { |
|
51 | 2 | $newContent = str_replace( |
|
52 | 2 | $variables, |
|
53 | 2 | $this->vars->values()->toArray(), |
|
54 | 2 | $file->getContents() |
|
55 | ); |
||
56 | 2 | file_put_contents($file->getPathname(), $newContent); |
|
57 | } |
||
58 | } catch (\Exception $e) { |
||
59 | throw new RuntimeException($e->getMessage(), $e->getCode(), $e); |
||
60 | } |
||
61 | 2 | } |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 4 | public function getPriority(): int |
|
70 | } |
||
71 |