-
Notifications
You must be signed in to change notification settings - Fork 11
/
skeleton.php
executable file
·134 lines (113 loc) · 3.63 KB
/
skeleton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* NOTICE OF LICENSE
*
* @author INVERTUS, UAB www.invertus.eu <[email protected]>
* @copyright Copyright (c) permanent, INVERTUS, UAB
* @license MIT
* @see /LICENSE
*
* International Registered Trademark & Property of INVERTUS, UAB
*/
use Invertus\Skeleton\Install\Installer;
use Invertus\Skeleton\Install\Uninstaller;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use \Invertus\Skeleton\Install\Tab;
class Skeleton extends Module
{
/**
* If false, then SkeletonContainer is in immutable state
*/
const DISABLE_CACHE = true;
/**
* @var SkeletonContainer
*/
private $moduleContainer;
public function __construct()
{
$this->tab = 'other_modules';
$this->name = 'skeleton';
$this->version = '1.0.0';
$this->author = 'Invertus';
parent::__construct();
$this->autoLoad();
$this->compile();
$this->displayName = $this->l('Skeleton');
$this->description = $this->l('This is module description');
}
public function getTabs()
{
/** @var Tab $tab */
$tab = $this->getContainer()->get('install.tab');
return $tab->getTabs();
}
public function getContent()
{
/** @var Tab $tab */
$tab = $this->getContainer()->get('install.tab');
$redirectLink = $this->context->link->getAdminLink($tab->getControllerInfo());
Tools::redirectAdmin($redirectLink);
}
public function install()
{
/** @var Installer $installer */
$installer = $this->getContainer()->get('installer');
return parent::install() && $installer->init();
}
public function uninstall()
{
/** @var Uninstaller $unInstaller */
$unInstaller = $this->getContainer()->get('uninstaller');
return parent::uninstall() && $unInstaller->init();
}
public function hookActionDispatcherBefore()
{
$this->autoLoad();
}
/**
* Gets container with loaded classes defined in src folder
*
* @return SkeletonContainer
*/
public function getContainer()
{
return $this->moduleContainer;
}
/**
* Autoload's project files from /src directory
*/
private function autoLoad()
{
$autoLoadPath = $this->getLocalPath().'vendor/autoload.php';
require_once $autoLoadPath;
}
/**
* Creates compiled dependency injection container which holds data configured in config/config.yml file.
*
* @throws Exception
*/
private function compile()
{
$containerCache = $this->getLocalPath().'var/cache/container.php';
$containerConfigCache = new ConfigCache($containerCache, self::DISABLE_CACHE);
$containerClass = get_class($this).'Container';
if (!$containerConfigCache->isFresh()) {
$containerBuilder = new ContainerBuilder();
$locator = new FileLocator($this->getLocalPath().'/config');
$loader = new YamlFileLoader($containerBuilder, $locator);
$loader->load('config.yml');
$containerBuilder->compile();
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write(
$dumper->dump(['class' => $containerClass]),
$containerBuilder->getResources()
);
}
require_once $containerCache;
$this->moduleContainer = new $containerClass();
}
}