-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
added PresentersExtension WIP #56
Conversation
eval($code); | ||
|
||
$container = new Container1; | ||
Assert::same( 1, count($container->findByType('NetteModule\ErrorPresenter')) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am correct, Assert::count(...
can be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, we have assert::count!
I am addicted to new Nette features... |
|
||
} elseif (!$services) { | ||
$rc = new \ReflectionClass($this->container); | ||
@unlink($rc->getFileName() . '.meta'); // @ file may not exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Should this force rebuilding the container?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some legal way how to invalidate container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there should be. But you certainly must not do this in production. If someone is using presenters without the Presenter
suffix, this will get triggered on every request. Or am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it does nothing on production nor on development, it is just WIP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pro tip: if you know that code has flaws, add a comment such as "// TODO: this may kill performance if application uses presenter not discovered by the extension".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(but it really does nothing, it deletes unused .meta file)
Great, I'm really excited to see this in Nette!
Depending on the order in which the classes are processed, you'll get one or both presenters registered. |
@xificurk fixed |
I tell myself that ApplicationExtension and PresentersExtension should be merged. |
$counter = 0; | ||
|
||
foreach ($this->findClasses() as $class) { | ||
if ($services = $container->findByType($class, FALSE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should search by tag as well.
And before processing found classes, there should be one more pass over already defined presenter services, that would add appropriate tags to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope...
a) It goes over the list compiled by findClasses()
, thus ignoring presenters manually registered as services by user.
b) There is still the problem I mentioned earlier - if findClasses()
returns the list containing BPresenter
before APresenter
, you'll get only BPresenter
registered with a wrong tag nette.presenter=APresenter
. Because first BPresenter
is registered and then when the loop later gets to processing APresenter
, the findByType("APresenter", FALSE)
will return previously registered definition of BPresenter
and set it wrong tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's probably ok
2f1c3c9
to
cc4e015
Compare
What do you think about something like this xificurk/nette-application@d6c90a7 ? |
What is it good for? |
@dg Currently it's really hard to use presenters distributed in a module with some package, because you cannot easily customize (templates, extra components, ...) it to the needs of your specific application. |
You can manually register presenter https://github.com/dg/nette-application/blob/extension/tests/Application.DI/PresentersExtension.basic.phpt#L57 |
That's not the point. Let's say you've installed some package that ships with several presenter classes
|
Just as in Nette 2.1:
Tag |
Yeh, but that presenter is supplied by 3rd party package, e.g. same as |
I do not understand you at all. Do you have an example? |
@dg To be specific - we've got a composer package that ships with Nette module providing generic web administration interface, but sometimes we need to customize some minor stuff, so app-specific presenter is created like:
So, we need to somehow force the application to use everywhere MyFooPresenter instead of the generic version shipped with the package. But as I think about it now, it will be probably better for us to rewrite presenter mapping part of |
I see. And agree that it should be probably solved mapping. |
What about this: when you define setup for base presenter, it will be used by all children. |
@dg a bit magical, but it makes sense. But reset of setups for "child" service should also work. |
Presenters should be probably defined inside They are not services. And abstract classes cannot be used as services. |
Sure, but you've made some good points here. Having some presenters as service should keep working, right? |
Curiosity question: What prevents them from being services? You would just need to make sure that the internal state is cleared after or before |
@JanTvrdik that is unneccesary... having them registered as services, but never really fetching the instance from container, but rather using it as a factory is less magic and works great.
I didn't mean having their instances shared, but rather having them only registered as services and using the createService every time, exactly as PresenterFactory is doing it now. |
No description provided.