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
|
|
|
* @return \Twig_LoaderInterface[] |
88
|
|
|
*/ |
89
|
|
|
public static function twig_loaders(array $loaders, string $THEMES_PATH): array |
90
|
|
|
{ |
91
|
|
|
$loaders[] = new \Twig_Loader_Filesystem($THEMES_PATH); |
92
|
|
|
return $loaders; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|