1 | <?php |
||
30 | class MigrationDirectoryHelper extends Helper |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * @var Configuration |
||
35 | */ |
||
36 | private $configuration; |
||
37 | |||
38 | 14 | public function __construct(Configuration $configuration = null) |
|
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 | } |
||
56 | |||
57 | 12 | if ($this->configuration->areMigrationsOrganizedByYearAndMonth()) { |
|
58 | 2 | $dir .= $this->appendDir(date('m')); |
|
59 | } |
||
60 | 12 | $this->createDirIfNotExists($dir); |
|
61 | |||
62 | 12 | return $dir; |
|
63 | } |
||
64 | |||
65 | 3 | private function appendDir($dir) |
|
69 | |||
70 | 12 | private function createDirIfNotExists($dir) |
|
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() |
||
88 | |||
89 | |||
90 | } |
||
91 |