Skip to content

Commit e07f067

Browse files
committed
global defaults
1 parent d54b03b commit e07f067

File tree

7 files changed

+143
-52
lines changed

7 files changed

+143
-52
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
},
3030
"require": {
3131
"php": ">=8.1",
32-
"nette/php-generator": "^3.0 | ^4.0",
33-
"symfony/console": "^8.0",
32+
"nette/php-generator": "^3.0 || ^4.0",
33+
"symfony/console": "^6.2 || ^7.0",
3434
"nette/neon": "^3.3",
3535
"nette/safe-stream": "^3.0",
36-
"symfony/yaml": "^8.0",
37-
"symfony/validator": "^8.0",
36+
"symfony/yaml": "^6.2 || ^7.0",
37+
"symfony/validator": "^6.2 || ^7.0",
3838
"nette/finder": "^3.0",
3939
"opis/json-schema": "^2.3",
40-
"matronator/parsem": "^3.2",
40+
"matronator/parsem": "^3.3",
4141
"guzzlehttp/guzzle": "^7.5"
4242
},
4343
"minimum-stability": "stable",

composer.lock

Lines changed: 39 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renovate.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Mtrgen/Template/Generator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static function parseAnyFile(string $path, array $arguments = [], bool $u
2828
$arguments["default:$key"] = $value;
2929
}
3030

31+
var_dump($arguments);
32+
3133
$parsed = Parser::parseString($file, $arguments, false, new PatternsOption(null, null, $useCommentSyntax !== false ? self::COMMENT_PATTERN : null));
3234

3335
$header = static::getTemplateHeader($parsed);
@@ -101,7 +103,7 @@ public static function getTemplateHeader(string $content): TemplateHeader
101103
$value = trim($keyValue[1]);
102104
$info[$key] = $value;
103105
} else {
104-
$info['defaults'] = array_slice($lines, array_search($line, $lines) + 1);
106+
$info['defaults'] = array_slice($lines, 5);
105107
break;
106108
}
107109
}
@@ -111,11 +113,17 @@ public static function getTemplateHeader(string $content): TemplateHeader
111113
}
112114

113115
if (isset($info['defaults'])) {
114-
foreach ($info['defaults'] as $value) {
116+
foreach ($info['defaults'] as $index => $value) {
117+
$value = trim($value);
118+
if ($value === '') {
119+
unset($info['defaults'][$index]);
120+
continue;
121+
}
115122
$keyValue = explode(':', $value, 2);
116123
$key = trim($keyValue[0]);
117124
$value = trim($keyValue[1]);
118125
$info['defaults'][$key] = $value;
126+
unset($info['defaults'][$index]);
119127
}
120128
}
121129

src/Mtrgen/Template/TemplateHeader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public function __construct(string $name, string $filename, string $path, array
2121

2222
public static function fromArray(array $array): static
2323
{
24-
return new static($array['name'], $array['filename'], $array['path'], $array['defaults'] ?? []);
24+
if (!isset($array['name']) || !isset($array['filename']) || !isset($array['path'])) {
25+
throw new \RuntimeException('Template header is missing some required properties (name, filename, path).');
26+
}
27+
28+
if (!isset($array['defaults'])) {
29+
$array['defaults'] = [];
30+
}
31+
32+
return new static($array['name'], $array['filename'], $array['path'], $array['defaults']);
2533
}
2634
}

0 commit comments

Comments
 (0)