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

Commit

Permalink
Change configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Oct 28, 2018
1 parent a497afe commit 346a11d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ $compiler->directive('directiveName', function ($expression) {
7. ```@csrf``` - сокращенная форма для ```<input type="hidden" name="sessid" value="{!! bitrix_sessid() !!}" />```
8. [Директивы по работе с эрмитажем](docs/hermitage.md)

## Конфигурация

При необходимости пути можно поменять в конфигурации.
.settings_extra.php
```php
'bitrix-blade' => [
'value' => [
'baseViewPath' => '/absolute/path/or/path/from/document/root', // по умолчанию 'local/views'
'cachePath' => '/absolute/path/or/path/from/document/root', // по умолчанию 'local/cache/blade'
],
'readonly' => false,
],
```

## Очистка кэша

Для обеспечения высокой скорости работы Blade кэширует скомпилированные шаблоны в php файлы.
В большинстве случаев чистить этот кэш самостоятельно потребности нет, потому что блейд сверяет время модификации файлов шаблонов и кэша и самостоятеьно инвалидирует этот кэш.
Однако в некоторых случаях (например при добавлении новой пользовательской директивы), этот кэш всё-же надо сбросить.
Делается это методом ```BladeProvider::clearCache()```


## Некоторые моменты

1. Битрикс позволяет использовать сторонние шаблонизаторы только в шаблонах компонентов. Шаблоны сайтов только на php.
Expand All @@ -58,7 +80,6 @@ $compiler->directive('directiveName', function ($expression) {
5. Проверку `<?if(!defined("B_PROLOG_INCLUDED")||B_PROLOG_INCLUDED!==true) die();?>` прописывать в blade-шаблоне не нужно, она добавляется в скомпилированные view автоматически. Также вместе с этим выполняется и ```extract($arResult, EXTR_SKIP);```
6. Чтобы языковой файл из шаблона подключился, его (этот языковой файл) надо назвать как обычно - `template.php`


## Дополнительно

PhpStorm
Expand Down
47 changes: 42 additions & 5 deletions src/BladeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace Arrilot\BitrixBlade;

use Bitrix\Main\Config\Configuration;
use ErrorException;
use Illuminate\Container\Container;
use Illuminate\Contracts\View\Factory;
use RuntimeException;

class BladeProvider
{
Expand Down Expand Up @@ -37,12 +40,13 @@ class BladeProvider

/**
* Register blade engine in Bitrix.
*
* @param string $baseViewPath
* @param string $cachePath
*/
public static function register($baseViewPath = 'local/views', $cachePath = 'bitrix/cache/blade')
public static function register()
{
$bitrixConfig = Configuration::getValue('bitrix-blade');
$baseViewPath = isset($bitrixConfig['baseViewPath']) ? $bitrixConfig['baseViewPath'] : 'local/views';
$cachePath = isset($bitrixConfig['cachePath']) ? $bitrixConfig['cachePath'] : 'local/cache/blade';

static::$baseViewPath = static::isAbsolutePath($baseViewPath) ? $baseViewPath : $_SERVER['DOCUMENT_ROOT'].'/'.$baseViewPath;
static::$cachePath = static::isAbsolutePath($cachePath) ? $cachePath : $_SERVER['DOCUMENT_ROOT'].'/'.$cachePath;
static::instantiateServiceContainer();
Expand Down Expand Up @@ -74,11 +78,36 @@ public static function getViewFactory()
/**
* @return BladeCompiler
*/
public function getCompiler()
public static function getCompiler()
{
return static::$container['blade.compiler'];
}

/**
* Clear all compiled view files.
*/
public static function clearCache()
{
$path = static::$cachePath;

if (!$path) {
throw new RuntimeException('Cache path is empty');
}

$success = true;
foreach (glob("{$path}/*") as $view) {
try {
if (!@unlink($view)) {
$success = false;
}
} catch (ErrorException $e) {
$success = false;
}
}

return $success;
}

/**
* Update paths where blade tries to find additional views.
*
Expand Down Expand Up @@ -271,4 +300,12 @@ private static function registerHermitageDirectives($compiler)
});
}
}

/**
* @return string|null
*/
public static function getCachePath()
{
return static::$cachePath;
}
}

0 comments on commit 346a11d

Please sign in to comment.