Completed
Push — 183-default-layout-ext ( a97107 )
by
unknown
10:37
created

PathExtension::register()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 1
nop 1
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\Path;
4
5
use League\Plates;
6
7
final class PathExtension implements Plates\Extension
8
{
9
    public function register(Plates\Engine $plates) {
10
        $c = $plates->getContainer();
11
        $c->add('path.resolvePath.stack', function($c) {
12
            $config = $c->get('config');
13
14
            // wrap base dir in an array if not already
15
            $base_dir = isset($config['base_dir']) ? $config['base_dir'] : null;
16
            $base_dir = $base_dir ? (is_string($base_dir) ? [$base_dir] : $base_dir) : $base_dir;
17
18
            return array_filter([
19
                'relative' =>relativeResolvePath(),
20
                'ext' => isset($config['ext']) ? extResolvePath($config['ext']) : null,
21
                'prefix' => $base_dir ? prefixResolvePath($base_dir, $c->get('fileExists')) : null,
22
                'id' => idResolvePath(),
23
            ]);
24
        });
25
        $c->add('path.resolvePath', function($c) {
26
            return Plates\Util\stack($c->get('path.resolvePath.stack'));
27
        });
28
        $c->wrap('compose', function($compose, $c) {
29
            return Plates\Util\compose(
30
                $compose,
31
                resolvePathCompose($c->get('path.resolvePath'))
32
            );
33
        });
34
    }
35
}
36