Completed
Push — master ( 77abb4...5b1cd3 )
by Chris
02:37
created

SmartyViewService   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 1
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 25 1
1
<?php
2
namespace Darya\Foundation\Providers;
3
4
use Darya\Service\Contracts\Container;
5
use Darya\Service\Contracts\Provider;
6
use Darya\Smarty\ViewResolver;
7
8
/**
9
 * A service provider that provides a Smarty view resolver.
10
 * 
11
 * @author Chris Andrew <[email protected]>
12
 */
13
class SmartyViewService implements Provider
14
{
15
	/**
16
	 * Register a Smarty view resolver with the service container.
17
	 * 
18
	 * @param Container $container
19
	 */
20
	public function register(Container $container)
21
	{
22
		$container->register(array(
23
			'Darya\Smarty\ViewResolver' => function ($container) {
24
				$config = $container->config;
25
				$basePath = $config['project.base_path'];
26
				$realBasePath = realpath("{$basePath}/views/smarty");
27
				
28
				$viewResolver = new ViewResolver('Darya\Smarty\View', $realBasePath);
29
				
30
				$viewResolver->shareConfig(array(
31
					'base'	  => $realBasePath,
32
					'cache'   => '../../storage/cache',
33
					'compile' => '../../storage/views'
34
				));
35
				
36
				$viewResolver->share(array(
37
					'config' => $container->config
38
				));
39
				
40
				return $viewResolver;
41
			},
42
			'Darya\View\Resolver' => 'Darya\Smarty\ViewResolver'
43
		));
44
	}
45
}
46