Skip to content

exception in application: pass reference to previous presenter - #317

Merged
dg merged 43 commits into
nette:masterfrom
dakur:patch-1
Oct 6, 2023
Merged

exception in application: pass reference to previous presenter#317
dg merged 43 commits into
nette:masterfrom
dakur:patch-1

Conversation

@dakur

@dakur dakur commented Oct 5, 2023

Copy link
Copy Markdown
Contributor
  • new feature
  • BC break? no
  • doc PR: n/a

I need separate handling of bad request of presenters that implement some interface. To check this in error presenter, I need instance of the original presenter therefore this PR. It can be probably achieved also via reflection, but this it seems cleaner to me.

todo:

  • update tests

dg added 30 commits October 2, 2023 13:09
…e() for persistent parameters. [Closes nette/nette#703]" (possible BC break)

This reverts commit cda17f4.

See https://forum.nette.org/cs/35528-stejne-pojmenovany-parametr-akce-presenteru-a-persistentni-odlisne-chovani-v-nette-2-0-oproti-aktualnimu#p221742

BC break: Property must be nullable, ie: #[Persistent] public ?int $foo
@dakur
dakur marked this pull request as draft October 5, 2023 09:10
@dakur
dakur marked this pull request as ready for review October 5, 2023 09:21
@mabar

mabar commented Oct 5, 2023

Copy link
Copy Markdown
Contributor

So, you don't need an instance?

class ErrorPresenter extends Presenter 
{
	public function __construct(private readonly IPresenterFactory $presenterFactory) {}

	public function actionDefault(Throwable $exception, Request|null $request): void
	{
		$presenterName = $request?->getPresenterName() ?? null;
		if ($presenterName !== null) {
			$presenterClass = $this->presenterFactory->getPresenterClass($presenterName);
			dump(is_a($presenterClass, CheckedInterface::class, true));
        }
	}

}

@dg

dg commented Oct 5, 2023

Copy link
Copy Markdown
Member

Isn't it easier to inject an Application into the errorpresenter?

@dakur

dakur commented Oct 5, 2023

Copy link
Copy Markdown
Contributor Author

So, you don't need an instance?

No. Even though your solution work, it seems strange to me to work with presenter factory inside of presenter. Extracting the presenter router<->class name translation into separate single responsibility service would probably solve that. Does it make sense?

Isn't it easier to inject an Application into the errorpresenter?

What would I do then? I can see getRequests() there but still you have to call $presenterFactory->getPresenterClass(). Not to mention going into injection loop..

My proposal seems quite straightforward to me, is there any problem with it?

@dg
dg force-pushed the master branch 3 times, most recently from e3a690a to 4e12415 Compare October 6, 2023 03:13
@dg
dg merged commit b23ebc3 into nette:master Oct 6, 2023
@dakur
dakur deleted the patch-1 branch October 6, 2023 14:15
@dakur

dakur commented Oct 6, 2023

Copy link
Copy Markdown
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants