1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PWWEB\Artomator\Generators; |
4
|
|
|
|
5
|
|
|
use InfyOm\Generator\Generators\BaseGenerator; |
6
|
|
|
use InfyOm\Generator\Utils\FileUtil; |
7
|
|
|
use PWWEB\Artomator\Common\CommandData; |
8
|
|
|
|
9
|
|
|
class ContractGenerator extends BaseGenerator |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Command Data. |
13
|
|
|
* |
14
|
|
|
* @var CommandData |
15
|
|
|
*/ |
16
|
|
|
private $commandData; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Path. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $path; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Filename. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $fileName; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* @param CommandData $commandData Command Data. |
36
|
|
|
*/ |
37
|
|
|
public function __construct(CommandData $commandData) |
38
|
|
|
{ |
39
|
|
|
$this->commandData = $commandData; |
40
|
|
|
$this->path = $commandData->config->pathContract; |
41
|
|
|
$this->fileName = $this->commandData->modelName.'RepositoryContract.php'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Generate. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function generate() |
50
|
|
|
{ |
51
|
|
|
$templateData = get_artomator_template('contract'); |
52
|
|
|
|
53
|
|
|
$templateData = fill_template($this->commandData->dynamicVars, $templateData); |
54
|
|
|
|
55
|
|
|
$searchables = []; |
56
|
|
|
|
57
|
|
|
foreach ($this->commandData->fields as $field) { |
58
|
|
|
if (true === $field->isSearchable) { |
59
|
|
|
$searchables[] = "'".$field->name."'"; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$templateData = str_replace('$FIELDS$', implode(','.infy_nl_tab(1, 2), $searchables), $templateData); |
64
|
|
|
|
65
|
|
|
FileUtil::createFile($this->path, $this->fileName, $templateData); |
66
|
|
|
|
67
|
|
|
$this->commandData->commandComment("\nRepository Contract created: "); |
68
|
|
|
$this->commandData->commandInfo($this->fileName); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Rollback. |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function rollback() |
77
|
|
|
{ |
78
|
|
|
if (true === $this->rollbackFile($this->path, $this->fileName)) { |
79
|
|
|
$this->commandData->commandComment('Repository Contract file deleted: '.$this->fileName); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|