1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Migrations\Tools\Console\Helper; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
23
|
|
|
use Symfony\Component\Console\Helper\Helper; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ConfigurationHelper |
27
|
|
|
* @package Doctrine\DBAL\Migrations\Tools\Console\Helper |
28
|
|
|
* @internal |
29
|
|
|
*/ |
30
|
|
|
class MigrationDirectoryHelper extends Helper |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Configuration |
35
|
|
|
*/ |
36
|
|
|
private $configuration; |
37
|
|
|
|
38
|
14 |
|
public function __construct(Configuration $configuration = null) |
39
|
|
|
{ |
40
|
14 |
|
$this->configuration = $configuration; |
41
|
14 |
|
} |
42
|
|
|
|
43
|
13 |
|
public function getMigrationDirectory() |
44
|
|
|
{ |
45
|
13 |
|
$dir = $this->configuration->getMigrationsDirectory(); |
46
|
13 |
|
$dir = $dir ? $dir : getcwd(); |
47
|
13 |
|
$dir = rtrim($dir, '/'); |
48
|
|
|
|
49
|
13 |
|
if (!file_exists($dir)) { |
50
|
1 |
|
throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir)); |
51
|
|
|
} |
52
|
|
|
|
53
|
12 |
|
if ($this->configuration->areMigrationsOrganizedByYear()) { |
54
|
3 |
|
$dir .= $this->appendDir(date('Y')); |
55
|
3 |
|
} |
56
|
|
|
|
57
|
12 |
|
if ($this->configuration->areMigrationsOrganizedByYearAndMonth()) { |
58
|
2 |
|
$dir .= $this->appendDir(date('m')); |
59
|
2 |
|
} |
60
|
12 |
|
$this->createDirIfNotExists($dir); |
61
|
|
|
|
62
|
12 |
|
return $dir; |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
private function appendDir($dir) |
66
|
|
|
{ |
67
|
3 |
|
return DIRECTORY_SEPARATOR . $dir; |
68
|
|
|
} |
69
|
|
|
|
70
|
12 |
|
private function createDirIfNotExists($dir) |
71
|
|
|
{ |
72
|
12 |
|
if (!file_exists($dir)) { |
73
|
3 |
|
mkdir($dir, 0755, true); |
74
|
3 |
|
} |
75
|
12 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the canonical name of this helper. |
79
|
|
|
* |
80
|
|
|
* @return string The canonical name |
81
|
|
|
* |
82
|
|
|
* @api |
83
|
|
|
*/ |
84
|
|
|
public function getName() |
85
|
|
|
{ |
86
|
|
|
return 'MigrationDirectory'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|