Skip to content

LinkGenerator: accept classname in $dest#296

Draft
mabar wants to merge 22 commits into
nette:masterfrom
mabar:class-links
Draft

LinkGenerator: accept classname in $dest#296
mabar wants to merge 22 commits into
nette:masterfrom
mabar:class-links

Conversation

@mabar

@mabar mabar commented Sep 25, 2021

Copy link
Copy Markdown
Contributor
  • new feature
  • BC break? no

This is minimal change needed in Nette in order to support NOT using mapping and to reference class directly instead.

$this->linkGenerator->link(self::class . ':default');

To fully support that behavior also a class_exists() check is needed in PresenterFactory. Without this is my change untestable, so let me know if I should modify also PresenterFactory and write tests.
https://github.com/orisai/nette-application/blob/73906f0f3009f751c15d8170467246957ca2e239/src/Mapping/DefaultPresenterFactory.php#L147-L163

I am already able to achieve it with $this->presenter->link($this->presenter::class . ':default');.

Benefit of this change is presenters don't have to follow any namespace structure, just like any class.

@dg

dg commented Sep 26, 2021

Copy link
Copy Markdown
Member

There should be a condition that always makes it clear whether it is a class or a presenter, otherwise it could get awkward. For example, a class must contain at least one character \.

@mabar

mabar commented Sep 26, 2021

Copy link
Copy Markdown
Contributor Author

I wrote an regex which expects [[Class\Name:]action] [#fragment] and all the tests on regex101.com work (check the unit tests tab). But I cannot get it work in PHP, it does not match my test string App\Admin\User\List\UserListPresenter:default, not sure why :/
https://regex101.com/r/u2DneV/1

@mabar

mabar commented Sep 26, 2021

Copy link
Copy Markdown
Contributor Author

Okay, got it. Had to add some character classes. Seems like regex101 does not use php, just PCRE2 - regex with [\\] and \\ works with regex101, [\\\] works with php

@mabar mabar marked this pull request as draft September 28, 2021 15:59
@dg dg force-pushed the master branch 3 times, most recently from cb29fc4 to ef31716 Compare October 6, 2021 23:39
@dg dg force-pushed the master branch 11 times, most recently from f4a6300 to babd383 Compare May 8, 2022 04:41
@dg dg force-pushed the master branch 18 times, most recently from f41dfbe to bdbb336 Compare May 18, 2022 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants