Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AclManagerInit.php
Go to the documentation of this file.
1<?php
2
4
14
23 public static function start(): void {
24 self::$aclList = new AclList();
25 self::$aclList->init();
26 }
27
31 public static function startWithCacheProvider(): void {
32 self::start();
33 self::initFromProviders([new AclCacheProvider()]);
34 }
35
41 public static function isStarted(): bool {
42 return isset(self::$aclList) && (self::$aclList instanceof AclList);
43 }
44
50 public static function initFromProviders(?array $providers = []): void {
51 self::$aclList->setProviders($providers);
52 if (\count($providers) > 0) {
53 self::$aclList->loadAcls();
54 self::$aclList->loadRoles();
55 self::$aclList->loadResources();
56 self::$aclList->loadPermissions();
57 }
58 }
59
64 public static function reloadFromSelectedProviders($selectedProviders = '*'): void {
65 $sProviders = self::$aclList->getProviders();
66 self::$aclList->clear();
67 $providers = [];
68 foreach ($sProviders as $prov) {
69 if ($selectedProviders === '*' || (\is_array($selectedProviders) && \array_search(\get_class($prov), $selectedProviders) !== false)) {
70 $providers[] = $prov;
71 }
72 }
73 self::initFromProviders($providers);
74 self::$aclList->setProviders($sProviders);
75 }
76
82 public static function getProvider(string $providerClass):?AclProviderInterface {
83 return self::$aclList->getProvider($providerClass);
84 }
85
86 public static function getModelClassesSwap(): array {
87 $result = [];
88 $aclList = self::getAclList();
89 if (isset($aclList)) {
90 foreach ($aclList->getProviders() as $prov) {
91 $result += $prov->getModelClassesSwap();
92 }
93 }
94 return $result;
95 }
96
97 public static function filterProviders(string $providerClass):void {
98 $providers = self::$aclList->getProviders();
99 $filter = [];
100 foreach ($providers as $prov) {
101 if ($prov instanceof $providerClass) {
102 $filter[] = $prov;
103 }
104 }
105 self::$aclList->setProviders($filter);
106 self::$providersPersistence = $providers;
107 }
108
109 public static function removefilterProviders():void {
110 self::$aclList->setProviders(self::$providersPersistence);
111 }
112
123 public static function initializeDAOProvider(array &$config, string $dbOffset='default', array $classes=[]): AclDAOProvider {
124 self::start();
125 return AclDAOProvider::initializeProvider($config,$dbOffset,$classes);
126 }
127
136 public static function initCache(array &$config, bool $silent=false): void {
137 self::cacheOperation($config, $silent, function ($parser) {
138 $parser->save();
139 }, "ACLs cache reset\n");
140 }
141
146 public static function checkCache(array &$config): bool {
147 return self::cacheOperation($config, true, function ($parser) {
148 return $parser->cacheUpdated();
149 });
150 }
151
152 private static function cacheOperation(array &$config, bool $silent, $operation, $message=null) {
153 if (!self::isStarted()) {
154 self::start();
155 self::initFromProviders([
156 new AclCacheProvider()
157 ]);
158 }
159 self::filterProviders(AclCacheProvider::class);
160 self::reloadFromSelectedProviders([]);
161 self::registerAnnotations();
162 $files = \Ubiquity\cache\CacheManager::getControllersFiles($config, $silent);
163 $parser = new AclControllerParser();
164
165 foreach ($files as $file) {
166 if (\is_file($file)) {
167 $controller = ClassUtils::getClassFullNameFromFile($file);
168 try {
169 $parser->parse($controller);
170 } catch (\Exception $e) {
171 if ($e instanceof AclException) {
172 throw $e;
173 }
174 }
175 }
176 }
177 $result = $operation($parser);
178 self::removefilterProviders();
179 self::reloadFromSelectedProviders();
180 if (!$silent) {
181 echo $message;
182 }
183 return $result;
184 }
185
186 protected static function registerAnnotations(): void {
187 CacheManager::getAnnotationsEngineInstance()->registerAcls();
188 }
189}
Manager for caches (Router, Rest, models).
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
Starts the framework.
Definition Startup.php:19
Ubiquity\exceptions$AclException This class is part of Ubiquity.
Ubiquity\security\acl\cache$AclControllerParser This class is part of Ubiquity.
Ubiquity\security\acl\models$AclList This class is part of Ubiquity.
Definition AclList.php:18
Ubiquity\security\acl\persistence$AclCacheProvider This class is part of Ubiquity.
Load and save Acls with a database using DAO.
static reloadFromSelectedProviders($selectedProviders=' *')
static start()
Create AclList with default roles and resources.
static filterProviders(string $providerClass)
static getProvider(string $providerClass)
static startWithCacheProvider()
Start the Acls with AclCacheProvider (for attributes or annotations).
static cacheOperation(array &$config, bool $silent, $operation, $message=null)
static initializeDAOProvider(array &$config, string $dbOffset='default', array $classes=[])
Initializes AclDAOProvider and creates ACL tables in the specified dbOffset.
static initCache(array &$config, bool $silent=false)
Initialize acls cache with controllers annotations.
static initFromProviders(?array $providers=[])
Load acls, roles, resources and permissions from providers.
static isStarted()
Check whether the Acl service is started.
Ubiquity\security\acl\persistence$AclProviderInterface This class is part of Ubiquity.