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

Presenter::$onAfterSignal event #309

Open
wants to merge 3 commits into
base: v3.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

fail-fast: false

Expand Down
22 changes: 19 additions & 3 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Nette\Application\Responses;
use Nette\Http;
use Nette\Utils\Arrays;
use Throwable;


/**
Expand Down Expand Up @@ -52,6 +53,9 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var array<callable(self): void> Occurs when the presenter is starting */
public $onStartup = [];

/** @var array<callable(self, Throwable|null): void> Occurs after presenter processed a signal */
public $onAfterSignal = [];

/** @var array<callable(self): void> Occurs when the presenter is rendering after beforeRender */
public $onRender = [];

Expand Down Expand Up @@ -230,7 +234,17 @@ public function run(Application\Request $request): Application\Response

// SIGNAL HANDLING
// calls $this->handle<Signal>()
$this->processSignal();
$signalException = null;
try {
$this->processSignal();
} catch (Throwable $signalException) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the catch can be omitted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to assign Throwable to $signalException

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it too. Just try ... finally

// Handled bellow
} finally {
Arrays::invoke($this->onAfterSignal, $this, $signalException);
if ($signalException !== null) {
throw $signalException;
}
}

// RENDERING VIEW
$this->beforeRender();
Expand Down Expand Up @@ -780,7 +794,8 @@ protected function createRequest(
string $destination,
array $args,
string $mode
): ?string {
): ?string
{
// note: createRequest supposes that saveState(), run() & tryCall() behaviour is final

$this->lastCreatedRequest = $this->lastCreatedRequestFlag = null;
Expand Down Expand Up @@ -1034,7 +1049,8 @@ public static function argsToParams(
array &$args,
array $supplemental = [],
?array &$missing = null
): void {
): void
{
$i = 0;
$rm = new \ReflectionMethod($class, $method);
foreach ($rm->getParameters() as $param) {
Expand Down
3 changes: 2 additions & 1 deletion src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ private function findPresenters(): array
public static function initializeBlueScreenPanel(
Tracy\BlueScreen $blueScreen,
Nette\Application\Application $application
): void {
): void
{
$blueScreen->addPanel(function (?\Throwable $e) use ($application, $blueScreen): ?array {
$dumper = $blueScreen->getDumper();
return $e ? null : [
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 @@ -18,6 +18,7 @@
* @method bool isLinkCurrent(string $destination = null, ...$args)
* @method bool isModuleCurrent(string $module)
*/
#[\AllowDynamicProperties]
final class DefaultTemplate extends Template
{
/** @var Nette\Application\UI\Presenter */
Expand Down
3 changes: 2 additions & 1 deletion src/Bridges/ApplicationLatte/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private function setupLatte2(
?UI\Control $control,
?UI\Presenter $presenter,
Template $template
): void {
): void
{
if ($latte->onCompile instanceof \Traversable) {
$latte->onCompile = iterator_to_array($latte->onCompile);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ private function analyse(
?string $path = null,
int $level = -1,
int $flag = 0
): void {
): void
{
if ($router instanceof Routing\RouteList) {
if ($httpRequest) {
try {
Expand Down
4 changes: 2 additions & 2 deletions tests/Bridges.Latte2/UIMacros.link.2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ link:['login']
<a href="link:['default!#hash',10,20]"></a>
EOD

, strtr($latte->renderToString(<<<'EOD'
, strtr($latte->renderToString(<<<'EOD'
{plink Homepage:}

{plink Homepage: }
Expand Down Expand Up @@ -122,4 +122,4 @@ EOD

<a n:href="default!#hash 10, 20"></a>
EOD
, $params), ['&#039;' => "'", '&apos;' => "'", '&#123;' => '{']));
, $params), ['&#039;' => "'", '&apos;' => "'", '&#123;' => '{']));
2 changes: 1 addition & 1 deletion tests/Bridges.Latte3/{control}.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Assert::match(
$ʟ_tmp->renderType() /* line 1 */;
%A%
XX
,
,
$latte->compile('{control form:type}'),
);

Expand Down
4 changes: 2 additions & 2 deletions tests/Bridges.Latte3/{link}.2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Assert::match(<<<'EOD'
<a href="link:['default!#hash',10,20]"></a>
EOD

, strtr($latte->renderToString(<<<'EOD'
, strtr($latte->renderToString(<<<'EOD'
{plink Homepage:}

{plink Homepage: }
Expand Down Expand Up @@ -121,4 +121,4 @@ Assert::match(<<<'EOD'

<a n:href="default!#hash 10, 20"></a>
EOD
, $params), ['&#039;' => "'", '&apos;' => "'", '&#123;' => '{']));
, $params), ['&#039;' => "'", '&apos;' => "'", '&#123;' => '{']));
3 changes: 2 additions & 1 deletion tests/UI/Component.isLinkCurrent().asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function callIsComponentLinkCurrent(
Application\Request $request,
$destination,
array $args
): bool {
): bool
{
$url = new Http\UrlScript('http://localhost/index.php', '/index.php');
$presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class);
$presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter');
Expand Down
3 changes: 2 additions & 1 deletion tests/UI/Presenter.storeRequest().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class MockSession extends Http\Session
public function getSection(
string $section,
string $class = Nette\Http\SessionSection::class
): Nette\Http\SessionSection {
): Nette\Http\SessionSection
{
return $this->testSection;
}
}
Expand Down