Skip to content

Commit 4a2d940

Browse files
committed
refactoring
1 parent 78fad1a commit 4a2d940

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/Application/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function processException(\Throwable $e): void
179179
$this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getHttpCode() ?: 404) : 500);
180180
}
181181

182-
$args = ['exception' => $e, 'request' => end($this->requests) ?: null];
182+
$args = ['exception' => $e, 'request' => Arrays::last($this->requests) ?: null];
183183
if ($this->presenter instanceof UI\Presenter) {
184184
try {
185185
$this->presenter->forward(":$this->errorPresenter:", $args);

src/Application/UI/Presenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public function sendTemplate(Template $template = null): void
463463
}
464464

465465
if (!$template->getFile()) {
466-
$file = strtr(reset($files), '/', DIRECTORY_SEPARATOR);
466+
$file = strtr(Arrays::first($files), '/', DIRECTORY_SEPARATOR);
467467
$this->error("Page not found. Missing template '$file'.");
468468
}
469469
}
@@ -489,7 +489,7 @@ public function findLayoutTemplateFile(): ?string
489489
}
490490

491491
if ($this->layout) {
492-
$file = strtr(reset($files), '/', DIRECTORY_SEPARATOR);
492+
$file = strtr(Arrays::first($files), '/', DIRECTORY_SEPARATOR);
493493
throw new Nette\FileNotFoundException("Layout not found. Missing template '$file'.");
494494
}
495495
return null;

src/Bridges/ApplicationDI/LatteExtension.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Latte;
1313
use Nette;
14+
use Nette\Bridges\ApplicationLatte;
15+
use Nette\Schema\Expect;
1416

1517

1618
/**
@@ -29,20 +31,17 @@ public function __construct(string $tempDir, bool $debugMode = false)
2931
{
3032
$this->tempDir = $tempDir;
3133
$this->debugMode = $debugMode;
34+
}
3235

33-
$this->config = new class {
34-
/** @var bool */
35-
public $xhtml = false;
36-
37-
/** @var string[] */
38-
public $macros = [];
39-
40-
/** @var ?string */
41-
public $templateClass;
4236

43-
/** @var bool */
44-
public $strictTypes = false;
45-
};
37+
public function getConfigSchema(): Nette\Schema\Schema
38+
{
39+
return Expect::structure([
40+
'xhtml' => Expect::bool(false),
41+
'macros' => Expect::arrayOf('string'),
42+
'templateClass' => Expect::string(),
43+
'strictTypes' => Expect::bool(false),
44+
]);
4645
}
4746

4847

@@ -56,7 +55,7 @@ public function loadConfiguration()
5655
$builder = $this->getContainerBuilder();
5756

5857
$latteFactory = $builder->addFactoryDefinition($this->prefix('latteFactory'))
59-
->setImplement(Nette\Bridges\ApplicationLatte\LatteFactory::class)
58+
->setImplement(ApplicationLatte\LatteFactory::class)
6059
->getResultDefinition()
6160
->setFactory(Latte\Engine::class)
6261
->addSetup('setTempDirectory', [$this->tempDir])
@@ -70,7 +69,7 @@ public function loadConfiguration()
7069

7170
$builder->addDefinition($this->prefix('templateFactory'))
7271
->setType(Nette\Application\UI\TemplateFactory::class)
73-
->setFactory(Nette\Bridges\ApplicationLatte\TemplateFactory::class)
72+
->setFactory(ApplicationLatte\TemplateFactory::class)
7473
->setArguments(['templateClass' => $config->templateClass]);
7574

7675
foreach ($config->macros as $macro) {

0 commit comments

Comments
 (0)