StaticRegistryServiceProvider::getStaticRegistry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\CMS\StaticRegistry\Twig\CmsPageExtension;
11
use TheCodingMachine\Funky\Annotations\Extension;
12
use TheCodingMachine\Funky\Annotations\Factory;
13
use TheCodingMachine\Funky\ServiceProvider;
14
use TheCodingMachine\CMS\Page\PageRegistryInterface;
15
16
class StaticRegistryServiceProvider extends ServiceProvider
17
{
18
    /**
19
     * @Factory(
20
     *     aliases={PageRegistryInterface::class}
21
     * )
22
     */
23
    public static function getStaticRegistry(PageRegistry $pageRegistry, ThemeRegistry $themeRegistry): StaticRegistry
24
    {
25
        return new StaticRegistry($pageRegistry, $themeRegistry);
26
    }
27
28
    /**
29
     * @Factory()
30
     */
31
    public static function getPageRegistry(string $PAGES_PATH, CacheInterface $cache): PageRegistry
32
    {
33
        return new PageRegistry($PAGES_PATH, $cache);
34
    }
35
36
    /**
37
     * @Factory()
38
     */
39
    public static function getThemeRegistry(string $THEMES_PATH, string $SUBTHEMES_PATH, ContainerInterface $container, CacheInterface $cache, BlockRegistry $blockRegistry): ThemeRegistry
40
    {
41
        return new ThemeRegistry($THEMES_PATH, $SUBTHEMES_PATH, $container, $cache, $blockRegistry);
42
    }
43
44
    /**
45
     * @Factory()
46
     */
47
    public static function getBlockRegistry(string $BLOCKS_PATH, ContainerInterface $container, CacheInterface $cache): BlockRegistry
48
    {
49
        return new BlockRegistry($BLOCKS_PATH, $container, $cache);
50
    }
51
52
    /**
53
     * @Factory(name="PAGES_PATH")
54
     */
55
    public static function getPagesDirectory(string $CMS_ROOT): string
56
    {
57
        return $CMS_ROOT.'/pages';
58
    }
59
60
    /**
61
     * @Factory(name="THEMES_PATH")
62
     */
63
    public static function getThemesDirectory(string $CMS_ROOT): string
64
    {
65
        return $CMS_ROOT.'/public/themes';
66
    }
67
68
    /**
69
     * @Factory(name="SUBTHEMES_PATH")
70
     */
71
    public static function getSubthemesDirectory(string $CMS_ROOT): string
72
    {
73
        return $CMS_ROOT.'/sub_themes';
74
    }
75
76
    /**
77
     * @Factory(name="BLOCKS_PATH")
78
     */
79
    public static function getBlocksDirectory(string $CMS_ROOT): string
80
    {
81
        return $CMS_ROOT.'/blocks';
82
    }
83
84
    /**
85
     * @Extension(
86
     *     nameFromMethodName=true
87
     * )
88
     * @param \Twig_LoaderInterface[] $loaders
89
     * @param string $THEMES_PATH
90
     * @return \Twig_LoaderInterface[]
91
     */
92
    public static function twig_loaders(array $loaders, string $THEMES_PATH): array
93
    {
94
        $loaders[] = new \Twig_Loader_Filesystem($THEMES_PATH);
95
        return $loaders;
96
    }
97
98
    /**
99
     * @Factory()
100
     * @return CmsPageExtension
101
     */
102
    public static function getCmsPageExtension(PageRegistry $pageRegistry, BlockRegistry $blockRegistry, string $ROOT_URL): CmsPageExtension
103
    {
104
        return new CmsPageExtension($pageRegistry, $blockRegistry, $ROOT_URL);
105
    }
106
107
    /**
108
     * @Extension(nameFromMethodName=true)
109
     * @param \Twig_ExtensionInterface[] $extensions
110
     * @param CmsPageExtension $cmsPageExtension
111
     * @return \Twig_ExtensionInterface[]
112
     */
113
    public static function twig_extensions(?array $extensions, CmsPageExtension $cmsPageExtension): array
114
    {
115
        $extensions[] = $cmsPageExtension;
116
        return $extensions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $extensions could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
117
    }
118
}
119