1 | <?php |
||
13 | class MigrationDirectoryHelper extends Helper |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var Configuration |
||
18 | */ |
||
19 | private $configuration; |
||
20 | |||
21 | 15 | public function __construct(Configuration $configuration = null) |
|
22 | { |
||
23 | 15 | $this->configuration = $configuration; |
|
24 | 15 | } |
|
25 | |||
26 | 14 | public function getMigrationDirectory() |
|
27 | { |
||
28 | 14 | $dir = $this->configuration->getMigrationsDirectory(); |
|
29 | 14 | $dir = $dir ? $dir : getcwd(); |
|
30 | 14 | $dir = rtrim($dir, '/'); |
|
31 | |||
32 | 14 | if ( ! file_exists($dir)) { |
|
33 | 1 | throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir)); |
|
34 | } |
||
35 | |||
36 | 13 | if ($this->configuration->areMigrationsOrganizedByYear()) { |
|
37 | 3 | $dir .= $this->appendDir(date('Y')); |
|
38 | } |
||
39 | |||
40 | 13 | if ($this->configuration->areMigrationsOrganizedByYearAndMonth()) { |
|
41 | 2 | $dir .= $this->appendDir(date('m')); |
|
42 | } |
||
43 | 13 | $this->createDirIfNotExists($dir); |
|
44 | |||
45 | 13 | return $dir; |
|
46 | } |
||
47 | |||
48 | 3 | private function appendDir($dir) |
|
52 | |||
53 | 13 | private function createDirIfNotExists($dir) |
|
59 | |||
60 | /** |
||
61 | * Returns the canonical name of this helper. |
||
62 | * |
||
63 | * @return string The canonical name |
||
64 | * |
||
65 | * @api |
||
66 | */ |
||
67 | public function getName() |
||
71 | } |
||
72 |