Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 16, 2021
1 parent 78fad1a commit 4a2d940
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function processException(\Throwable $e): void
$this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getHttpCode() ?: 404) : 500);
}

$args = ['exception' => $e, 'request' => end($this->requests) ?: null];
$args = ['exception' => $e, 'request' => Arrays::last($this->requests) ?: null];
if ($this->presenter instanceof UI\Presenter) {
try {
$this->presenter->forward(":$this->errorPresenter:", $args);
Expand Down
4 changes: 2 additions & 2 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function sendTemplate(Template $template = null): void
}

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

if ($this->layout) {
$file = strtr(reset($files), '/', DIRECTORY_SEPARATOR);
$file = strtr(Arrays::first($files), '/', DIRECTORY_SEPARATOR);
throw new Nette\FileNotFoundException("Layout not found. Missing template '$file'.");
}
return null;
Expand Down
27 changes: 13 additions & 14 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use Latte;
use Nette;
use Nette\Bridges\ApplicationLatte;
use Nette\Schema\Expect;


/**
Expand All @@ -29,20 +31,17 @@ public function __construct(string $tempDir, bool $debugMode = false)
{
$this->tempDir = $tempDir;
$this->debugMode = $debugMode;
}

$this->config = new class {
/** @var bool */
public $xhtml = false;

/** @var string[] */
public $macros = [];

/** @var ?string */
public $templateClass;

/** @var bool */
public $strictTypes = false;
};
public function getConfigSchema(): Nette\Schema\Schema
{
return Expect::structure([
'xhtml' => Expect::bool(false),
'macros' => Expect::arrayOf('string'),
'templateClass' => Expect::string(),
'strictTypes' => Expect::bool(false),
]);
}


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

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

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

foreach ($config->macros as $macro) {
Expand Down

0 comments on commit 4a2d940

Please sign in to comment.