Skip to content

Commit

Permalink
Extension: Routing support format and source definition by array.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored May 30, 2021
1 parent ab57d79 commit 884630d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/LoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ final class LoaderExtension extends CompilerExtension
{
public function getConfigSchema(): Schema
{
// Expect::anyOf([
// Expect::string(), // URL
// Expect::structure([
// 'source' => Expect::string()->required(),
// 'format' => Expect::string()->required(),
// ]),
// ])->firstIsDefault()
return Expect::structure([
'basePath' => Expect::string(),
'routing' => Expect::arrayOf(Expect::arrayOf(Expect::string()->required())),
'routing' => Expect::arrayOf( // (route [*] => rules)
Expect::arrayOf( // (rule => definition)
Expect::mixed(),

This comment has been minimized.

Copy link
@janbarasek
),
Expect::anyOf(Expect::string()->required()),
),
'base' => Expect::array(),
'formatHeaders' => Expect::arrayOf(Expect::string()->required()), // 'css' => 'text/css'
'formatHtmlInjects' => Expect::arrayOf(Expect::string()->required()), // 'css' => '<link href="%path%" rel="stylesheet">'
Expand All @@ -40,7 +52,14 @@ public function beforeCompile(): void
foreach ($files as $route => $assetFiles) {
$this->validateRouteFormat($route);
foreach ($assetFiles as $assetFormat => $assetFile) {
if (\is_string($assetFormat)) {
if (is_array($assetFile)) {
if (isset($assetFile['format'], $assetFile['source'])) {
$format = $assetFile['format'];
$assetFile = $assetFile['source'];
} else {
throw new \RuntimeException('Invalid asset structure, expected keys "format" and "source".');
}
} elseif (is_string($assetFormat)) {
if (!preg_match('/^[a-zA-Z0-9]+$/', $assetFile)) {
throw new \RuntimeException('Invalid asset format for file "' . $assetFormat . '", because "' . $assetFile . '" given.');
}
Expand Down

0 comments on commit 884630d

Please sign in to comment.