1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Providers; |
6
|
|
|
|
7
|
|
|
use function Canvas\Core\appPath; |
8
|
|
|
use Phalcon\Cache\Backend\File as BackendFileCache; |
|
|
|
|
9
|
|
|
use Phalcon\Cache\Frontend\None as NoneCache; |
|
|
|
|
10
|
|
|
use Phalcon\Cache\Frontend\Output as FrontenCacheOutput; |
|
|
|
|
11
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
|
|
|
12
|
|
|
use Phalcon\DiInterface; |
|
|
|
|
13
|
|
|
use Phalcon\Mvc\View\Engine\Volt as VoltEngine; |
|
|
|
|
14
|
|
|
use Phalcon\Mvc\View\Simple as SimpleView; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class ViewProvider implements ServiceProviderInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param DiInterface $container |
20
|
|
|
*/ |
21
|
|
|
public function register(DiInterface $container) |
22
|
|
|
{ |
23
|
|
|
$config = $container->get('config'); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Setting up the view component. |
27
|
|
|
*/ |
28
|
|
|
$container->set('view', function () use ($config, $container) { |
|
|
|
|
29
|
|
|
$view = new SimpleView(); |
30
|
|
|
$view->setViewsDir($config->filesystem->local->path . '/view/'); |
31
|
|
|
$view->registerEngines([ |
32
|
|
|
'.volt' => function ($view, $container) use ($config) { |
33
|
|
|
$volt = new VoltEngine($view, $container); |
34
|
|
|
$volt->setOptions([ |
35
|
|
|
//CACHE save DISABLED IN DEV ENVIRONMENT |
36
|
|
|
'compiledPath' => appPath('storage/cache/volt/'), |
37
|
|
|
'compiledSeparator' => '_', |
38
|
|
|
'compileAlways' => !$config->app->production, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$volt->getCompiler()->addExtension(new class { |
42
|
|
|
/** |
43
|
|
|
* This method is called for any PHP function on the volt. |
44
|
|
|
*/ |
45
|
|
|
public function compileFunction($name, $arguments) |
46
|
|
|
{ |
47
|
|
|
if (function_exists($name)) { |
48
|
|
|
return "{$name}({$arguments})"; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
return $volt; |
54
|
|
|
}, |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
return $view; |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* View cache. |
62
|
|
|
*/ |
63
|
|
|
$container->set( |
64
|
|
|
'viewCache', |
65
|
|
|
function () use ($config) { |
66
|
|
|
if (!$config->app->production) { |
67
|
|
|
$frontCache = new NoneCache(); |
68
|
|
|
} else { |
69
|
|
|
//Cache data for one day by default |
70
|
|
|
$frontCache = new FrontenCacheOutput([ |
71
|
|
|
'lifetime' => 172800, |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
return new BackendFileCache($frontCache, [ |
75
|
|
|
'cacheDir' => appPath('storage/cache/volt/'), |
76
|
|
|
'prefix' => $config->app->id . '-', |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths