|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Xervice\Database\Business\Model\Model; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Finder\Finder; |
|
8
|
|
|
use Xervice\Database\Business\Model\Provider\PropelCommandProviderInterface; |
|
9
|
|
|
|
|
10
|
|
|
class BuildModel implements BuildModelInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Xervice\Database\Business\Model\Provider\PropelCommandProviderInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
private $propelCommandProvider; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
private $schemaPaths; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $schemaTarget; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $schemaPattern; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* BuildModel constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Xervice\Database\Business\Model\Provider\PropelCommandProviderInterface $propelCommandProvider |
|
36
|
|
|
* @param array $schemaPaths |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function __construct( |
|
39
|
|
|
PropelCommandProviderInterface $propelCommandProvider, |
|
40
|
|
|
array $schemaPaths, |
|
41
|
|
|
string $schemaTarget, |
|
42
|
|
|
string $schemaPattern |
|
43
|
|
|
) { |
|
44
|
1 |
|
$this->propelCommandProvider = $propelCommandProvider; |
|
45
|
1 |
|
$this->schemaPaths = $schemaPaths; |
|
46
|
1 |
|
$this->schemaTarget = $schemaTarget; |
|
47
|
1 |
|
$this->schemaPattern = $schemaPattern; |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function buildModel(): array |
|
54
|
|
|
{ |
|
55
|
1 |
|
if (!is_dir($this->schemaTarget)) { |
|
56
|
1 |
|
if (!mkdir($this->schemaTarget, 0777) && !is_dir($this->schemaTarget)) { |
|
57
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->schemaTarget)); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
foreach ($this->schemaPaths as $schemaPath) { |
|
62
|
1 |
|
$finder = new Finder(); |
|
63
|
1 |
|
$finder->files()->name('*' . $this->schemaPattern)->in($schemaPath); |
|
64
|
1 |
|
foreach ($finder as $schemaFile) { |
|
65
|
1 |
|
$targetFilename = str_replace( |
|
66
|
1 |
|
$this->schemaPattern, |
|
67
|
1 |
|
'.schema.xml', |
|
68
|
1 |
|
basename((string)$schemaFile->getRealPath()) |
|
69
|
|
|
); |
|
70
|
1 |
|
copy((string)$schemaFile->getRealPath(), $this->schemaTarget . '/' . $targetFilename); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
return $this->propelCommandProvider->execute('model:build'); |
|
75
|
|
|
} |
|
76
|
|
|
} |