Skip to content

Commit

Permalink
Extension: Better formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored May 30, 2022
1 parent b1e12a1 commit 583d993
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/ImageGeneratorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ public function getConfigSchema(): Schema
return Expect::structure(
[
'debugMode' => Expect::bool(false),
'defaultBackgroundColor' => Expect::arrayOf(Expect::int())->max(3),
'cropPoints' => Expect::arrayOf(Expect::arrayOf(Expect::int())),
'defaultBackgroundColor' => Expect::arrayOf(Expect::int())->max(3)->default([255, 255, 255]),
'cropPoints' => Expect::arrayOf(Expect::arrayOf(Expect::int()))->default([
480 => [910, 30, 1845, 1150],
600 => [875, 95, 1710, 910],
768 => [975, 130, 1743, 660],
1024 => [805, 110, 1829, 850],
1280 => [615, 63, 1895, 800],
1440 => [535, 63, 1975, 800],
1680 => [410, 63, 2090, 800],
1920 => [320, 63, 2240, 800],
2560 => [0, 63, 2560, 800],
]),
],
)->castTo('array');
}
Expand All @@ -39,27 +49,14 @@ public function beforeCompile(): void

$builder->addDefinition($this->prefix('image'))
->setFactory(Image::class)
->addSetup('?->setDebugMode(?)', ['@self', $config['debugMode'] ?? false]);
->addSetup('?->setDebugMode(?)', ['@self', $config['debugMode']]);

$builder->addDefinition($this->prefix('config'))
->setFactory(Config::class)
->setArguments(
[
'defaultBackgroundColor' => $config['defaultBackgroundColor'] ?? [255, 255, 255],
'cropPoints' => $config['cropPoints'] ?? [
480 => [910, 30, 1845, 1150],
600 => [875, 95, 1710, 910],
768 => [975, 130, 1743, 660],
1024 => [805, 110, 1829, 850],
1280 => [615, 63, 1895, 800],
1440 => [535, 63, 1975, 800],
1680 => [410, 63, 2090, 800],
1920 => [320, 63, 2240, 800],
2560 => [0, 63, 2560, 800],
],
],
);

->setArguments([
'defaultBackgroundColor' => $config['defaultBackgroundColor'],
'cropPoints' => $config['cropPoints'],
]);

$builder->addDefinition($this->prefix('imageGenerator'))
->setFactory(ImageGenerator::class);
Expand All @@ -69,9 +66,7 @@ public function beforeCompile(): void
$latte->getResultDefinition()
->addSetup(
'?->onCompile[] = function ($engine) { ' . Macros::class . '::install($engine->getCompiler()); }',
[
'@self',
],
['@self'],
);
}

Expand Down

0 comments on commit 583d993

Please sign in to comment.