1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Providers; |
6
|
|
|
|
7
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
8
|
|
|
use Phalcon\DiInterface; |
9
|
|
|
use Phalcon\Mvc\View\Engine\Volt as VoltEngine; |
10
|
|
|
use function Canvas\Core\appPath; |
11
|
|
|
|
12
|
|
|
class ViewProvider implements ServiceProviderInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param DiInterface $container |
16
|
|
|
*/ |
17
|
|
|
public function register(DiInterface $container) |
18
|
|
|
{ |
19
|
|
|
$config = $container->get('config'); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Setting up the view component. |
23
|
|
|
*/ |
24
|
|
|
$container->set('view', function () use ($config, $container) { |
25
|
|
|
$view = new \Phalcon\Mvc\View\Simple(); |
26
|
|
|
$view->setViewsDir($config->filesystem->local->path . '/view/'); |
27
|
|
|
$view->registerEngines([ |
28
|
|
|
'.volt' => function ($view, $container) use ($config) { |
29
|
|
|
$volt = new VoltEngine($view, $container); |
30
|
|
|
$volt->setOptions([ |
31
|
|
|
//CACHE save DISABLED IN DEV ENVIRONMENT |
32
|
|
|
'compiledPath' => appPath('storage/cache/volt/'), |
33
|
|
|
'compiledSeparator' => '_', |
34
|
|
|
'compileAlways' => !$config->app->production, |
35
|
|
|
]); |
36
|
|
|
|
37
|
|
|
return $volt; |
38
|
|
|
}, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
return $view; |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* View cache. |
46
|
|
|
*/ |
47
|
|
|
$container->set( |
48
|
|
|
'viewCache', |
49
|
|
|
function () use ($config) { |
50
|
|
|
if (!$config->app->production) { |
51
|
|
|
$frontCache = new \Phalcon\Cache\Frontend\None(); |
52
|
|
|
} else { |
53
|
|
|
//Cache data for one day by default |
54
|
|
|
$frontCache = new \Phalcon\Cache\Frontend\Output([ |
55
|
|
|
'lifetime' => 172800, |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
return new \Phalcon\Cache\Backend\File($frontCache, [ |
59
|
|
|
'cacheDir' => appPath('storage/cache/volt/'), |
60
|
|
|
'prefix' => $config->app->id . '-', |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|