Completed
Push — master ( d1e0a9...cb6f48 )
by David
11s
created

StaticRegistryServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getPagesDirectory() 0 3 1
A getBlockRegistry() 0 3 1
A getPageRegistry() 0 3 1
A getStaticRegistry() 0 3 1
A getSubthemesDirectory() 0 3 1
A getThemesDirectory() 0 3 1
A getBlocksDirectory() 0 3 1
A getThemeRegistry() 0 3 1
A twig_loaders() 0 4 1
1
<?php
2
namespace TheCodingMachine\CMS\StaticRegistry\DI;
3
4
use Psr\Container\ContainerInterface;
5
use Psr\SimpleCache\CacheInterface;
6
use TheCodingMachine\CMS\StaticRegistry\Registry\BlockRegistry;
7
use TheCodingMachine\CMS\StaticRegistry\Registry\PageRegistry;
8
use TheCodingMachine\CMS\StaticRegistry\Registry\StaticRegistry;
9
use TheCodingMachine\CMS\StaticRegistry\Registry\ThemeRegistry;
10
use TheCodingMachine\Funky\Annotations\Extension;
11
use TheCodingMachine\Funky\Annotations\Factory;
12
use TheCodingMachine\Funky\ServiceProvider;
13
use TheCodingMachine\CMS\Page\PageRegistryInterface;
14
15
class StaticRegistryServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * @Factory(
19
     *     aliases={PageRegistryInterface::class}
20
     * )
21
     */
22
    public static function getStaticRegistry(PageRegistry $pageRegistry, ThemeRegistry $themeRegistry): StaticRegistry
23
    {
24
        return new StaticRegistry($pageRegistry, $themeRegistry);
25
    }
26
27
    /**
28
     * @Factory()
29
     */
30
    public static function getPageRegistry(string $PAGES_PATH, CacheInterface $cache): PageRegistry
31
    {
32
        return new PageRegistry($PAGES_PATH, $cache);
33
    }
34
35
    /**
36
     * @Factory()
37
     */
38
    public static function getThemeRegistry(string $THEMES_PATH, string $SUBTHEMES_PATH, ContainerInterface $container, CacheInterface $cache, BlockRegistry $blockRegistry): ThemeRegistry
39
    {
40
        return new ThemeRegistry($THEMES_PATH, $SUBTHEMES_PATH, $container, $cache, $blockRegistry);
41
    }
42
43
    /**
44
     * @Factory()
45
     */
46
    public static function getBlockRegistry(string $BLOCKS_PATH, ContainerInterface $container, CacheInterface $cache): BlockRegistry
47
    {
48
        return new BlockRegistry($BLOCKS_PATH, $container, $cache);
49
    }
50
51
    /**
52
     * @Factory(name="PAGES_PATH")
53
     */
54
    public static function getPagesDirectory(string $CMS_ROOT): string
55
    {
56
        return $CMS_ROOT.'/pages';
57
    }
58
59
    /**
60
     * @Factory(name="THEMES_PATH")
61
     */
62
    public static function getThemesDirectory(string $CMS_ROOT): string
63
    {
64
        return $CMS_ROOT.'/public/themes';
65
    }
66
67
    /**
68
     * @Factory(name="SUBTHEMES_PATH")
69
     */
70
    public static function getSubthemesDirectory(string $CMS_ROOT): string
71
    {
72
        return $CMS_ROOT.'/sub_themes';
73
    }
74
75
    /**
76
     * @Factory(name="BLOCKS_PATH")
77
     */
78
    public static function getBlocksDirectory(string $CMS_ROOT): string
79
    {
80
        return $CMS_ROOT.'/blocks';
81
    }
82
83
    /**
84
     * @Extension(
85
     *     nameFromMethodName=true
86
     * )
87
     * @param \Twig_LoaderInterface[] $loaders
88
     * @param string $THEMES_PATH
89
     * @return \Twig_LoaderInterface[]
90
     */
91
    public static function twig_loaders(array $loaders, string $THEMES_PATH): array
92
    {
93
        $loaders[] = new \Twig_Loader_Filesystem($THEMES_PATH);
94
        return $loaders;
95
    }
96
}
97