Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

[Latte PHPStan compiler] Added support for another filters - function calls and custom filters #3699

Merged
merged 8 commits into from
Oct 29, 2021

Conversation

lulco
Copy link
Contributor

@lulco lulco commented Oct 22, 2021

function calls from Latte\Runtime\Defaults like

'escapeUrl' => 'rawurlencode',
'number' => 'number_format',

were ignored. Now they are implemented

custom filters (or also nette filter translate) were ignored too. This PR adds support for them by config %latteTemplateFilters% where can be definded static, non-static and also function call filters

For non-static calls I'm trying to add php doc over call, but no success

/** @var \Nette\Localization\Translator $translator */
echo \Latte\Runtime\Filters::escapeHtmlText($translator->translate($var));

Do you have any idea how to achieve this?

@@ -1,3 +1,9 @@
parameters:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where to store parameters and parametersSchema if the service using them is here

@TomasVotruba
Copy link
Member

For non-static calls I'm trying to add php doc over call, but no success

I'll see. Could you add a separate PR so it's clear what is related code and test?

@lulco
Copy link
Contributor Author

lulco commented Oct 23, 2021

I've changed approach - all non static filter can have its own variable registered. It works like a charm!

@lulco
Copy link
Contributor Author

lulco commented Oct 25, 2021

@TomasVotruba PR is ready for review, do you need some more info?

@lulco
Copy link
Contributor Author

lulco commented Oct 27, 2021

@TomasVotruba all done, please check again

latteFilters:
customFilter: [Symplify\LattePHPStanCompiler\Tests\LatteToPhpCompiler\Source\StaticFilter, process]
translate: [Nette\Localization\Translator, translate]
asdf: qwerty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 👏

@TomasVotruba
Copy link
Member

Thank you, I think is good to go 👍

@TomasVotruba
Copy link
Member

I have to merge this one first #3711, so the "Update branch" is build on clean "main". There are couple bugs in Rector/PHPStan 1.0 fixed

@TomasVotruba TomasVotruba self-requested a review October 29, 2021 12:39
@TomasVotruba TomasVotruba enabled auto-merge (squash) October 29, 2021 15:04
@TomasVotruba TomasVotruba enabled auto-merge (squash) October 29, 2021 15:23
@TomasVotruba TomasVotruba merged commit 4c132b7 into deprecated-packages:main Oct 29, 2021
@TomasVotruba
Copy link
Member

Thanks for the feature ☺️

I've noticed after merge the docs update is missing. Could you add couple of lines to README.md to let people now how to use it? Thanks

@lulco
Copy link
Contributor Author

lulco commented Oct 29, 2021

Sure, I wanted to do so but there is just big todo in latte-phpstan-compiler and also phpstan-latte-rules :) I would place it to phpstan-latte-rules. Do you agree?

@TomasVotruba
Copy link
Member

I would place it to phpstan-latte-rules. Do you agree?

Yes, that's the best place IMO 👍

@lulco lulco deleted the non-default-filters branch November 1, 2021 22:55
@lulco
Copy link
Contributor Author

lulco commented Nov 1, 2021

done #3737

@deprecated-packages deprecated-packages locked as resolved and limited conversation to collaborators Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants