fenom/docs/en/configuration.md

72 lines
2.8 KiB
Markdown
Raw Normal View History

2014-05-14 17:07:48 +04:00
Setup
=====
## Configure
### Template cache
```php
$fenom->setCompileDir($dir);
```
This method set the name of the directory where template caches are stored. By default this is `/tmp`. This directory must be writeable.
### Template settings
```php
// set options using factory
$fenom = Fenom::factory($tpl_dir, $compile_dir, $options);
// or inline using method setOptions
$fenom->setOptions($options);
```
Options may by associative array like `'option_name' => true` or bitwise mask.
| Option name | Constant | Description | Affect |
| ---------------------- | ------------------------- | ------------ | ------- |
2018-09-10 14:27:45 +03:00
| *disable_methods* | `Fenom::DENY_METHODS` | disable calling methods of objects in templates. | |
| *disable_native_funcs* | `Fenom::DENY_NATIVE_FUNCS`| disable calling native function in templates, except allowed. | |
2014-05-14 17:07:48 +04:00
| *auto_reload* | `Fenom::AUTO_RELOAD` | reload template if source will be changed | decreases performance |
| *force_compile* | `Fenom::FORCE_COMPILE` | recompile template every time when the template renders | very decreases performance |
| *disable_cache* | `Fenom::DISABLE_CACHE` | disable compile cache | greatly decreases performance |
| *force_include* | `Fenom::FORCE_INCLUDE` | paste template body instead of include-tag | increases performance, increases cache size |
| *auto_escape* | `Fenom::AUTO_ESCAPE` | html-escape each variables outputs | decreases performance |
| *force_verify* | `Fenom::FORCE_VERIFY` | check existence every used variable | decreases performance |
2018-09-10 14:27:45 +03:00
| *disable_statics* | `Fenom::DENY_STATICS` | disable calling static methods in templates. | |
| *strip* | `Fenom::AUTO_STRIP` | strip all whitespaces in templates. | decrease cache size |
<!--
| *auto_trim* | `Fenom::AUTO_TRIM` | remove space-characters before and after tags | |
-->
2014-05-14 17:07:48 +04:00
```php
$fenom->setOptions(array(
"compile_check" => true,
"force_include" => true
));
// same
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_INCLUDE);
```
**Note**
By default all options disabled
## Extends
2014-06-18 17:21:29 +04:00
### Template providers
2014-05-14 17:07:48 +04:00
2018-09-10 14:27:45 +03:00
Sometimes templates are stored not in the file system, but in some repository, for example, in the MySQL database. In this case, the template needs to describe how to take templates from the repository, how to check the date the template was modified, and where to store the template cache (optional). This task is taken by the `Provider` classes, these are objects realizing the interface `Fenom\ProviderInterface`.
2014-05-14 17:07:48 +04:00
### Callbacks and filters
2014-05-17 12:09:37 +04:00
#### Before compile callback
```php
$fenom->addPreFilter(function () { /* ... */ });
```
#### Tag filter callback
#### Filter callback
#### After compile callback