-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
use shared laminas escaper instance #3274
Conversation
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.
@lukasbestle looks good to me, what do you think? But I would probably introduce a new static::escaper() method to clean it up a bit.
@pine3ree Thanks for your PR! I saw your post in the forum and wanted to make the same changes. I agree with Bastian. To make the code DRY, there should be a new Please also use |
@pine3ree If you don't have time, do you want us to take care of minor improvements? |
Hello @lukasbestle, @bastianallgeier , @afbora , sorry guys...bad health these last couple of days... I though about a ::getEscaper() singleton, but in the last years I'have tried to avoid too many recursive calls if I have shorthand alternatives such as I would avoid (but it doesn't hurt) adding For the other changes let me know If you prefer that I add them (and which ones) to by pr or if you pick them from @afbora . I am just browsing kirby code these days (and enjoying doing it), even if I remember tooking an interest a few years back in the first versions, so I apologise If I say something obvious or obviously wrong. I noticed that this class is used directly by the I would also recommend to start importing gobal php functions and constants and not only classes. It's not required but it can speed up php code execution up to 4~5%. kirby is already very fast, but faster is better when not affecting code readability. For this we just need a few more kind regards |
Thanks for your reply @pine3ree! Don't worry about the code, Nico has already made the changes.
Not only that – it makes the code DRY and makes sure that we don't forget changes in one method in case we ever need to change the returned object.
Absolutely! But you never know in which use-cases escaping is needed in a Kirby site. Especially because templates are created by our users and not by us. :)
You are right, I've opened an issue here: #3291
It is currently not possible to substitute the classes that are being used by the helpers. But we don't want to make our classes
Oh interesting, I never thought of that. There's one minor issue: We currently abuse this PHP feature to mock PHP functions in tests. For example we override the |
@lukasbestle, :-) That's (the?) one good thing about global functions lookup...intercepting and replacing them for unit testing. As I said, It will take time to look at every aspects of kirby. So, apologies for having made you spend time to explain. About the class substitution, don't get me wrong. I am not a fan. I was just having doubts about the existence of some - unknown to me - kirby mechanism to allow subclassing static helper classes and have them being automatically used by any framework/field method relying on their original ancestors. kind regards. |
Don't worry, it's great to get feedback like yours. Thank you! 👍 |
Describe the PR
Use a single laminas escaper instance instead of a different instance per method call. This is possible as all instances are created with the same
utf-8
$encoding and the fact that the escaper internal encoding cannot be changed after creation.