|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RDV\Bundle\MigrationBundle\Tools; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
6
|
|
|
use Doctrine\DBAL\Schema\Visitor\AbstractVisitor; |
|
7
|
|
|
|
|
8
|
|
|
class SchemaDumper extends AbstractVisitor |
|
9
|
|
|
{ |
|
10
|
|
|
const SCHEMA_TEMPLATE = 'RdvMigrationBundle::schema-template.php.twig'; |
|
11
|
|
|
const DEFAULT_CLASS_NAME = 'AllMigration'; |
|
12
|
|
|
const DEFAULT_VERSION = 'v1_0'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var Schema |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $schema; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Twig_Environment |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $twig; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param \Twig_Environment $twig |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(\Twig_Environment $twig) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->twig = $twig; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function acceptSchema(Schema $schema) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->schema = $schema; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param array|null $allowedTables |
|
42
|
|
|
* @param string|null $namespace |
|
43
|
|
|
* @param string $className |
|
44
|
|
|
* @param string $version |
|
45
|
|
|
* @param array|null $extendedOptions |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function dump( |
|
49
|
|
|
array $allowedTables = null, |
|
50
|
|
|
$namespace = null, |
|
51
|
|
|
$className = self::DEFAULT_CLASS_NAME, |
|
52
|
|
|
$version = self::DEFAULT_VERSION, |
|
53
|
|
|
array $extendedOptions = null |
|
54
|
|
|
) { |
|
55
|
|
|
$content = $this->twig->render( |
|
56
|
|
|
self::SCHEMA_TEMPLATE, |
|
57
|
|
|
[ |
|
58
|
|
|
'schema' => $this->schema, |
|
59
|
|
|
'allowedTables' => $allowedTables, |
|
60
|
|
|
'namespace' => $this->getMigrationNamespace($namespace), |
|
61
|
|
|
'className' => $className, |
|
62
|
|
|
'version' => $version, |
|
63
|
|
|
'extendedOptions' => $extendedOptions |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return $content; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function getMigrationNamespace($namespace) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($namespace) { |
|
73
|
|
|
$namespace = str_replace('\\Entity', '', $namespace); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $namespace; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|