Skip to content

Commit a978705

Browse files
committed
add Strict, fix LazyEntityGetter
1 parent 465a9fb commit a978705

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Strict/NetteStrict.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Utilitte\Nette\Strict;
4+
5+
use Nette\Bridges\ApplicationLatte\Template;
6+
use Nette\Forms\Controls\BaseControl;
7+
use stdClass;
8+
9+
final class NetteStrict
10+
{
11+
12+
public static function template(object $template): Template
13+
{
14+
assert($template instanceof Template);
15+
16+
return $template;
17+
}
18+
19+
public static function stdClass(object $stdClass): stdClass
20+
{
21+
assert($stdClass instanceof stdClass);
22+
23+
return $stdClass;
24+
}
25+
26+
public static function formControl(object $control): BaseControl
27+
{
28+
assert($control instanceof BaseControl);
29+
30+
return $control;
31+
}
32+
33+
}

src/Traits/Application/LazyEntityGetter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ final protected function addLazyEntityGetterValidator(callable $validator): void
3333
/**
3434
* @template T
3535
* @param class-string<T> $class
36+
* @param mixed[] $checkParameters
3637
* @return T|null
3738
*/
3839
final protected function getEntityIfParameterPresented(string $class, string $parameterName = 'id', array $checkParameters = []): ?object
@@ -44,10 +45,15 @@ final protected function getEntityIfParameterPresented(string $class, string $pa
4445
return $this->getEntity($class, $parameterName, $checkParameters);
4546
}
4647

48+
/**
49+
* @template T
50+
* @param class-string<T> $class
51+
* @param mixed[] $checkParameters
52+
* @return T|null
53+
*/
4754
final protected function getNullableEntity(string $class, string $parameterName = 'id', array $checkParameters = []): ?object
4855
{
4956
if ($this->_entityMeta === null) {
50-
$object = $this->getOptionalEntity($class, $parameterName, $checkParameters);
5157
$id = $this->getParameter($parameterName);
5258

5359
if ($id === null) {
@@ -110,6 +116,7 @@ final protected function getNullableEntity(string $class, string $parameterName
110116
/**
111117
* @template T
112118
* @param class-string<T> $class
119+
* @param mixed[] $checkParameters
113120
* @return T
114121
*/
115122
final protected function getEntity(string $class, string $parameterName = 'id', array $checkParameters = []): object

0 commit comments

Comments
 (0)