|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Zenify |
|
5
|
|
|
* Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Zenify\DoctrineMigrations\Configuration; |
|
9
|
|
|
|
|
10
|
|
|
use Doctrine\DBAL\Connection; |
|
11
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration as BaseConfiguration; |
|
12
|
|
|
use Doctrine\DBAL\Migrations\OutputWriter; |
|
13
|
|
|
use Nette\DI\Container; |
|
14
|
|
|
use Zenify\DoctrineMigrations\Exception\Configuration\MigrationClassNotFoundException; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
final class Configuration extends BaseConfiguration |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(Container $container, Connection $connection, OutputWriter $outputWriter = NULL) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->container = $container; |
|
|
|
|
|
|
23
|
|
|
parent::__construct($connection, $outputWriter); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getMigrationsToExecute($direction, $to) |
|
31
|
|
|
{ |
|
32
|
|
|
$versions = parent::getMigrationsToExecute($direction, $to); |
|
33
|
|
|
foreach ($versions as $version) { |
|
34
|
|
|
$this->container->callInjects($version->getMigration()); |
|
35
|
|
|
} |
|
36
|
|
|
return $versions; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getVersion($version) |
|
44
|
|
|
{ |
|
45
|
|
|
$version = parent::getVersion($version); |
|
46
|
|
|
$this->container->callInjects($version->getMigration()); |
|
47
|
|
|
return $version; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setMigrationsDirectory($directory) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->createDirectoryIfNotExists($directory); |
|
57
|
|
|
parent::setMigrationsDirectory($directory); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $directory |
|
63
|
|
|
*/ |
|
64
|
|
|
private function createDirectoryIfNotExists($directory) |
|
65
|
|
|
{ |
|
66
|
|
|
if ( ! file_exists($directory)) { |
|
67
|
|
|
mkdir($directory, 0755, TRUE); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: