1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* BEdita, API-first content management framework |
6
|
|
|
* Copyright 2024 ChannelWeb Srl, Chialab Srl |
7
|
|
|
* |
8
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
10
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
14
|
|
|
*/ |
15
|
|
|
namespace BEdita\DevTools\Command; |
16
|
|
|
|
17
|
|
|
use Cake\Console\Arguments; |
18
|
|
|
use Cake\Console\ConsoleIo; |
19
|
|
|
use Migrations\Command\BakeSimpleMigrationCommand; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritDoc} |
23
|
|
|
* |
24
|
|
|
* Command class for generating resources migrations files. |
25
|
|
|
*/ |
26
|
|
|
class ResourcesMigrationCommand extends BakeSimpleMigrationCommand |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Main migration file name. |
30
|
|
|
* |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
protected ?string $migrationFile = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
|
|
public function name(): string |
39
|
|
|
{ |
40
|
|
|
return 'resources_migration'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function fileName($name): string |
47
|
|
|
{ |
48
|
|
|
if (isset($this->migrationFile)) { |
49
|
|
|
return $this->migrationFile; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $this->migrationFile = parent::fileName($name); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function template(): string |
59
|
|
|
{ |
60
|
|
|
return 'BEdita/DevTools.resources'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
|
|
public function bake(string $name, Arguments $args, ConsoleIo $io): void |
67
|
|
|
{ |
68
|
|
|
// create .php file first, then .yml |
69
|
|
|
parent::bake($name, $args, $io); |
70
|
|
|
|
71
|
|
|
$contents = $this->createTemplateRenderer() |
72
|
|
|
->set('name', $name) |
73
|
|
|
->set($this->templateData($args)) |
74
|
|
|
->generate('BEdita/DevTools.yaml'); |
75
|
|
|
|
76
|
|
|
$filename = $this->getPath($args) . str_replace('.php', '.yml', $this->fileName($name)); |
77
|
|
|
$io->createFile($filename, $contents, $this->force); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|