You can also add some parameters for phpstan-latte extension. All of them are under latte
key in parameters
section.
- Latte engine configuration
- Analyser configuration
- Ignoring errors
- Link checking
- Other configuration options
Type: string
If provided this return value of this php file is used as Latte Engine.
If not provided default Latte Engine is used.
Example:
parameters:
latte:
engineBootstrap: latte.engine.php
Example latte.engine.php
:
<?php
$engine = new \Latte\Engine();
// ...
return $engine;
Example latte.engine.php
for loading configured Engine from Nette application container:
<?php
return App\Bootstrap::boot()->createContainer()->getService("latte.templateFactory")->createTemplate()->getLatte();
Type: array
List of methods to register macros in format Class::method
.
Macros known to Latte engine are added by default. If you use engineBootstrap
you probably do not need to set this up manually.
Example:
parameters:
latte:
macros:
- MyMacro::install
Type: array
List of Latte extension classes.
Extensions known to Latte engine are added by default. If you use engineBootstrap
you probably do not need to set this up manually.
Example:
parameters:
latte:
extensions:
- MyExtension()
Type: array
List of filters used in your apps. Name of filter is used as key, callback or function name is value.
Filters known to Latte engine are added by default. If you use engineBootstrap
you probably do not need to set this up manually.
Default:
parameters:
latte:
filters:
translate: [Nette\Localization\Translator, translate]
Example:
parameters:
latte:
filters:
myFilter: [My\Global\Type, doFoo]
functionFilter: strlen
closureFilter: 'Closure(string, int): string'
closureWithSlashFilter: '\Closure(string, int): string'
callableFilter: 'callable(string, int): string'
Type: array
List of functions used in your apps. They are configured in same way as filters. Different is only usage in latte:
{$foo|fooFilter}
{fooFunction($foo)}
Type: array
List of paths outside of analysedPaths that are scanned when latte context (variables, components, ...) is collected for template analysis.
Example:
parameters:
latte:
collectedPaths:
- vendor/some/package
Type: array
List of variables and their types which are always defined in all your templates.
Default:
parameters:
latte:
globalVariables: []
Example:
parameters:
latte:
globalVariables:
myGlobalStringVariable: string
myOtherGlobalVariable: My\Global\Type
Type: bool
When expression containing variables is used as template path it is not resolved becase we do not know value of variable.
With this option set to true we will search for all potentional templates that could match given expression. May lead to false positives.
Example:
parameters:
latte:
resolveAllPossiblePaths: true
Type: bool
When set to true all *.latte files in analysed paths that were not checked (because no render call of them was resolved) are reported as errors.
Example:
parameters:
latte:
reportUnanalysedTemplates: true
Type: array
List of patterns which can be found in compiled latte specific error message. These errors are ignored, and they are not sent back to phpstan.
Default:
parameters:
latte:
errorPatternsToIgnore: []
Example:
parameters:
latte:
errorPatternsToIgnore:
- '/Unknown tag/'
Type: array
With our TableErrorFormatter, warnings are not count as errors, they are just printed to output. If you want to transform some errors to warnings, you can use this parameter. It is list of pattern strings.
Default:
parameters:
latte:
warningPatterns: []
Example:
parameters:
latte:
warningPatterns:
- '/Cannot automatically resolve latte template from expression\./'
If you want to check links in your application, we need to know how links are transformed to correct method calls ({link SomePresenter:create}
is transformed to SomePresenter->actionCreate()
). For this purpose IPresenterFactory is used in Nette applications.
You have two options how to configure it. If no one is set, link calls are not checked.
Type: string
Path to file where IPresenterFactory is set up.
Example:
parameters:
latte:
presenterFactoryBootstrap: presenter.factory.php
Example of presenter.factory.php
for loading IPresenterFactory from Nette application container:
<?php
return App\Bootstrap::boot()->createContainer()->getByType(IPresenterFactory::class);
Type: array
Sometimes you don't have IPresenterFactory available (e.g. for some libraries or packages). You can add application mapping to configuration. Application mapping should be the same as the mapping used in application. Default PresenterFactory is created.
Default:
parameters:
latte:
applicationMapping: []
Example:
parameters:
latte:
applicationMapping:
*: App\*\Presenters\*Presenter
Foo: Foo\Bar\Presenters\*Presenter
Type: bool
Defines if compiled template is declared as strict (declare(strict_types=1);
).
Default:
parameters:
latte:
strictMode: false
Example:
parameters:
latte:
strictMode: true