Skip to content

Commit 44150a7

Browse files
committed
Template by set
1 parent b1489a8 commit 44150a7

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,13 @@ $container['phpmig.sets'] = function ($container) {
391391
return array(
392392
'cms' => array(
393393
'adapter' => new Adapter\File\Flat('modules/migrationLogs/cms_migrations.log'),
394-
'migrations_path' => 'migrations/cms'
394+
'migrations_path' => 'migrations/cms',
395+
'migrations_template_path' => 'PhpmigCmsTemplate.php'
395396
),
396397
'blog' => array(
397398
'adapter' => new Adapter\File\Flat('modules/migrationLogs/blog_migrations.log'),
398-
'migrations_path' => 'migrations/blog'
399+
'migrations_path' => 'migrations/blog',
400+
'migrations_template_path' => 'PhpmigBlogTemplate.php',
399401
)
400402
);
401403
};

src/Phpmig/Console/Command/GenerateCommand.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ protected function configure()
3434
parent::configure();
3535

3636
$this->setName('generate')
37-
->addArgument('name', InputArgument::REQUIRED, 'The name for the migration')
38-
->addArgument('path', InputArgument::OPTIONAL, 'The directory in which to put the migration ( optional if phpmig.migrations_path is setted )')
39-
->setDescription('Generate a new migration')
40-
->setHelp(<<<EOT
37+
->addArgument('name', InputArgument::REQUIRED, 'The name for the migration')
38+
->addArgument('path', InputArgument::OPTIONAL,
39+
'The directory in which to put the migration ( optional if phpmig.migrations_path is setted )')
40+
->setDescription('Generate a new migration')
41+
->setHelp(<<<EOT
4142
The <info>generate</info> command creates a new migration with the name and path specified
4243
4344
<info>phpmig generate Dave ./migrations</info>
4445
4546
EOT
46-
);
47+
);
4748
}
4849

4950
/**
@@ -55,18 +56,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
5556

5657
$path = $input->getArgument('path');
5758
$set = $input->getOption('set');
58-
if( null === $path ){
59-
if (isset($this->container['phpmig.migrations_path'])) {
59+
if (null === $path) {
60+
if (true === isset($this->container['phpmig.migrations_path'])) {
6061
$path = $this->container['phpmig.migrations_path'];
6162
}
62-
if (isset($this->container['phpmig.sets']) && isset($this->container['phpmig.sets'][$set]['migrations_path'])) {
63+
if (true === isset($this->container['phpmig.sets'][$set]['migrations_path'])) {
6364
$path = $this->container['phpmig.sets'][$set]['migrations_path'];
6465
}
6566
}
6667
$locator = new FileLocator(array());
67-
$path = $locator->locate($path, getcwd(), $first = true);
68+
$path = $locator->locate($path, getcwd(), $first = true);
6869

69-
if (!is_writeable($path)) {
70+
if (!is_writable($path)) {
7071
throw new \InvalidArgumentException(sprintf(
7172
'The directory "%s" is not writeable',
7273
$path
@@ -77,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7778

7879
$migrationName = $this->transMigName($input->getArgument('name'));
7980

80-
$basename = date('YmdHis') . '_' . $migrationName . '.php';
81+
$basename = date('YmdHis') . '_' . $migrationName . '.php';
8182

8283
$path = $path . DIRECTORY_SEPARATOR . $basename;
8384

@@ -90,8 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
9091

9192
$className = $this->migrationToClassName($migrationName);
9293

93-
if (isset($this->container['phpmig.migrations_template_path'])) {
94-
$migrationsTemplatePath = $this->container['phpmig.migrations_template_path'];
94+
if (isset($this->container['phpmig.migrations_template_path']) || isset($this->container['phpmig.sets'][$set]['migrations_template_path'])) {
95+
if (true === isset($this->container['phpmig.migrations_template_path'])) {
96+
$migrationsTemplatePath = $this->container['phpmig.migrations_template_path'];
97+
} else {
98+
$migrationsTemplatePath = $this->container['phpmig.sets'][$set]['migrations_template_path'];
99+
}
100+
95101
if (false === file_exists($migrationsTemplatePath)) {
96102
throw new \RuntimeException(sprintf(
97103
'The template file "%s" not found',
@@ -101,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
101107

102108
if (preg_match('/\.php$/', $migrationsTemplatePath)) {
103109
ob_start();
104-
include($migrationsTemplatePath);
110+
include $migrationsTemplatePath;
105111
$contents = ob_get_clean();
106112
} else {
107113
$contents = file_get_contents($migrationsTemplatePath);

0 commit comments

Comments
 (0)