<commit_before>php-safe
========

Yii2 template engine.
Php compiler generate php code like source with next features:
 * `<?= 'smth' ?>`, `<?php echo 'smth' ?>` converts to somthing like `<?php echo \yii\helpers\Html::encode('smth') ?>` (safe converting)
 * `<?php print 'raw' ?> converts to something like <?php print 'raw' ?> (unsafe converting)

Usage
-----

To use this extension, simply add the following code in your application configuration:

```php
return [
    //....
    'components' => [
        //....
        'view' => [
            'renderers' => [
                'sphp' => [
                    'class' => 'flexibuild\phpsafe\ViewRenderer',
                    //the directory or path alias pointing to where Php-Safe engine compiled files will be stored.
                    //'compiledPath' => '@runtime/PhpSafe/compiled',
                    //'mkDirMode' => 0755,
                    //the name of Yii application cache component for caching rendered files.
                    //'cacheComponent' => 'cache',
                    //'compilerConfig' => [
                        // see flexibuild\phpsafe\Compiler for more info
                    //],
                ],
            ],
        ],
        //....
    ],
];
```

Than you can create view file with extension `.sphp` and write simple php code.
All `echo` structures in your view file (e.g. `<?=`, <?php echo...`) will be converted to save echo.
If you need to echo raw html you may use `print` syntax.

Notes
-----

 * Php-Safe engine will not parse functions, classes, interfaces & traits structures.
That also means php-safe engine will not works in body of anonymous function.

 * Php-Safe engine will parse only code of your `.sphp` view file. It doesn\'t know anything about your other code.

 * If your php configured to use short tags and/or asp tags, php-safe will also parse this tags.

 * You may configure your IDE to parse `.sphp` files like `.php` files for more convenience.

 * If Yii cache component configured, php-safe engine will compile views on the first rendering only.

 * Be carefull: code like `<?= print('smth') ?>` will be converted to smth like `<?php echo \yii\helpers\Html::encode(print('smth')) ?>`
After executing this code prints raw 'smth' and then echoes safe '1', because php engine will echo result of print function (that always return 1).
<commit_msg>Fixed readme.<commit_after>php-safe
========

Yii2 template engine.
Php-Safe compiler generate php code like source with next features:
 * `<?= 'smth' ?>`, `<?php echo 'smth' ?>` converts to something like `<?php echo \yii\helpers\Html::encode('smth') ?>` (safe converting);
 * `<?php print 'raw' ?>` converts to something like `<?php print 'raw' ?>` (unsafe converting).

Usage
-----

To use this extension, simply add the following code in your application configuration:

```php
return [
    //....
    'components' => [
        //....
        'view' => [
            'renderers' => [
                'sphp' => [
                    'class' => 'flexibuild\phpsafe\ViewRenderer',
                    //the directory or path alias pointing to where Php-Safe engine compiled files will be stored.
                    //'compiledPath' => '@runtime/PhpSafe/compiled',
                    //'mkDirMode' => 0755,
                    //the name of Yii application cache component for caching rendered files.
                    //'cacheComponent' => 'cache',
                    //'compilerConfig' => [
                        // see flexibuild\phpsafe\Compiler for more info
                    //],
                ],
            ],
        ],
        //....
    ],
];
```

Than you can create view file with extension `.sphp` and write simple php code.
All `echo` structures in your view file (e.g. `<?=`, `<?php echo...`) will be converted to safe echo.
If you need to echo raw html you may use `print` syntax.

Notes
-----

 * Php-Safe engine use [`token_get_all()`](http://php.net/manual/en/function.token-get-all.php) method for parsing code. It's pretty fast.

 * Php-Safe engine will not parse functions, classes, interfaces & traits structures.
That also means php-safe engine will not works in body of anonymous functions.

 * Php-Safe engine will parse only code of your `.sphp` view file. It doesn't know anything about your other code.

 * If your php configured to use short tags and/or asp tags, php-safe will also parse this tags.

 * You may configure your IDE to parse `.sphp` files like `.php` files for more convenience.

 * If Yii cache component configured, php-safe engine will compile views on the first rendering only.

 * Be carefull: code like `<?= print('smth') ?>` will be converted to smth like `<?php echo \yii\helpers\Html::encode(print('smth')) ?>`.
After executing this code prints raw 'smth' and echoes safe '1', because php engine will echo result of print function (that always return 1).

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0028594771241830064, 'mean_word_length': 2.3749138525155065, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3034880', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1281, 'n_words': 551}