Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction of false exception message in startup check #332

Merged
merged 22 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
859151e
opened 4.0-dev
dg Dec 14, 2023
b3ad622
removed support for Latte 2
dg Apr 6, 2024
8965e93
removed compatibility for old class names
dg Oct 15, 2021
c2d1a27
added type hints (BC break)
dg Feb 8, 2024
dc518be
RouteList: array access is deprecated
dg Oct 15, 2021
8195579
Presenter::handleInvalidLink() -> processInvalidLink() (BC break)
dg May 12, 2024
a43dc48
Revert "UI\PresenterComponent: removed references created by loadStat…
dg Oct 24, 2022
6df3a08
Component: method checkRequirements() is called for createComponent<N…
dg Apr 20, 2024
a061fe1
Component: only UI components can be added to presenter/component (BC…
dg Apr 7, 2024
31a1179
deprecated magic properties except for $template & $payload (BC break)
dg Sep 24, 2021
13a4616
Component::link() & etc uses variadic parameter
dg Oct 19, 2021
52410d9
Component::getParameter() $default is deprecated
dg Jun 21, 2022
d3a858c
PresenterFactoryCallback: refreshes page instead of creating presente…
dg Apr 28, 2024
7da2e57
LinkGenerator: query part in link is deprecated
dg Apr 19, 2024
95fa3e2
Presenter: removed constructor (BC break!)
dg Dec 11, 2023
c4767bb
@annotations are deprecated (BC break)
dg Apr 19, 2024
6ef6c90
LatteFactory: $control is passed to create() (BC break)
dg Apr 6, 2024
8b57c9f
PresenterFactory: default mapping is App\UI\*\**Presenter (BC break)
dg Apr 14, 2024
9a0af13
uses nette/routing 4.0
dg Jan 21, 2024
ecb200c
LatteExtension: added option 'variables'
dg Jan 9, 2023
83880f2
Correction of false exception message in startup check
mildabre May 28, 2024
3491c0d
Merge branch 'master' into patch-4
dg Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* The router broker.
*/
class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess

Check failure on line 19 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

The @implements tag of class Nette\Application\Routers\RouteList describes IteratorAggregate but the class implements: Nette\Routing\Router, ArrayAccess
{
private const PresenterKey = 'presenter';

Expand Down Expand Up @@ -61,21 +61,21 @@
}


public function addRoute(

Check failure on line 64 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #3 $oneWay (bool) of method Nette\Application\Routers\RouteList::addRoute() is not contravariant with parameter #3 $oneWay (int) of method Nette\Routing\RouteList::addRoute().
#[Language('TEXT')]
string $mask,
array|string|\Closure $metadata = [],
int|bool $oneWay = 0,
bool $oneWay = false,
): static
{
$this->add(new Route($mask, $metadata), (int) $oneWay);
$this->add(new Route($mask, $metadata), $oneWay);

Check failure on line 71 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #2 $oneWay of method Nette\Routing\RouteList::add() expects int, bool given.
return $this;
}


public function withModule(string $module): static
{
$router = new static;

Check failure on line 78 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unsafe usage of new static().
$router->module = $module . ':';
$router->parent = $this;
$this->add($router);
Expand All @@ -98,7 +98,7 @@
if ($router instanceof Route) {
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED);
} else {
$class = getclass($router);

Check failure on line 101 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

Function getclass not found.
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function run(Application\Request $request): Application\Response
$this->startup();
if (!$this->startupCheck) {
$class = static::getReflection()->getMethod('startup')->getDeclaringClass()->getName();
throw new Nette\InvalidStateException("Method $class::startup() or its descendant doesn't call parent::startup().");
throw new Nette\InvalidStateException("Method $class::startup() or its parents doesn't call parent::startup().");
}

// calls $this->action<Action>()
Expand Down
6 changes: 4 additions & 2 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function loadConfiguration(): void
}

$builder->addDefinition($this->prefix('templateFactory'))
->setFactory(ApplicationLatte\TemplateFactory::class)
->setArguments(['templateClass' => $config->templateClass]);
->setFactory(ApplicationLatte\TemplateFactory::class, [
'templateClass' => $config->templateClass,
'configVars' => $config->variables,
]);

if ($this->name === 'latte') {
$builder->addAlias('nette.latteFactory', $this->prefix('latteFactory'));
Expand Down
1 change: 1 addition & 0 deletions src/Bridges/ApplicationLatte/DefaultTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class DefaultTemplate extends Template

/** @var \stdClass[] */
public array $flashes = [];
public \stdClass $config;


/**
Expand Down
2 changes: 2 additions & 0 deletions src/Bridges/ApplicationLatte/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
private readonly ?Nette\Http\IRequest $httpRequest = null,
private readonly ?Nette\Security\User $user = null,
$templateClass = null,
private array $configVars = [],
) {
if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) {
throw new Nette\InvalidArgumentException("Class $templateClass does not implement " . Template::class . ' or it does not exist.');
Expand Down Expand Up @@ -63,6 +64,7 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul
'flashes' => $flashes,
'control' => $control,
'presenter' => $presenter,
'config' => $control instanceof UI\Presenter && $this->configVars ? (object) $this->configVars : null,
];

foreach ($params as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function analyse(Routing\RouteList $router, ?Nette\Http\IRequest $httpRe
continue;
}

$matched = $flags[$i] & $router::ONE_WAY ? 'oneway' : 'no';
$matched = empty($flags[$i]['oneWay']) ? 'no' : 'oneway';
$params = $e = null;
try {
if (
Expand Down
74 changes: 74 additions & 0 deletions tests/Bridges.DI/LatteExtension.variables.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* Test: LatteExtension v3
*/

declare(strict_types=1);

use Nette\DI;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

Tester\Environment::bypassFinals();


test('no variables', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
latte:
variables:
', 'neon'));

$compiler = new DI\Compiler;
$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false));
$code = $compiler
->addConfig($config)
->setClassName('Container1')
->compile();
eval($code);

$container = new Container1;
$latteFactory = $container->getService('latte.templateFactory');
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();

$template = $latteFactory->createTemplate($presenter);
Assert::notContains('config', $template->getParameters());
});


test('presenter presence', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
latte:
variables:
foo: bar
', 'neon'));

$compiler = new DI\Compiler;
$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false));
$code = $compiler
->addConfig($config)
->setClassName('Container2')
->compile();
eval($code);

$container = new Container2;
$latteFactory = $container->getService('latte.templateFactory');
$template = $latteFactory->createTemplate();
Assert::notContains('config', $template->getParameters());


$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();

$template = $latteFactory->createTemplate($presenter);
Assert::equal(
(object) ['foo' => 'bar'],
$template->getParameters()['config'],
);
});
2 changes: 1 addition & 1 deletion tests/Routers/RouteList.addRoute.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require __DIR__ . '/Route.php';

$list = new RouteList;
$list->addRoute('foo', ['presenter' => 'foo'], RouteList::ONE_WAY);
$list->addRoute('bar', ['presenter' => 'bar'], RouteList::ONE_WAY);
$list->addRoute('bar', ['presenter' => 'bar'], oneWay: true);
$list->addRoute('hello', ['presenter' => 'hello']);


Expand Down
Loading