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

exception in application: pass reference to previous presenter #317

Merged
merged 43 commits into from
Oct 6, 2023

Conversation

dakur
Copy link
Contributor

@dakur dakur commented Oct 5, 2023

  • 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
Copy link
Contributor

mabar commented Oct 5, 2023

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
Copy link
Member

dg commented Oct 5, 2023

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

@dakur
Copy link
Contributor Author

dakur commented Oct 5, 2023

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
2 of 9 checks passed
@dakur dakur deleted the patch-1 branch October 6, 2023 14:15
@dakur
Copy link
Contributor Author

dakur commented Oct 6, 2023

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