42 public function __construct(array &$config, array $classes = []) {
43 Startup::$config=$config;
48 $this->aclClass = $classes[
'acl'] ??
AclElement::class;
49 $this->roleClass = $classes[
'role'] ?? Role::class;
50 $this->resourceClass = $classes[
'resource'] ?? Resource::class;
51 $this->permissionClass = $classes[
'permission'] ?? Permission::class;
71 public function setDbOffset(
string $dbOffset =
'default',
bool $persist=
true): void {
72 DAO::setModelDatabase($this->aclClass, $dbOffset);
86 public function createModels(
string $dbOffset=
'default', ?array $classes=
null): void {
88 'acl'=>
'models\\AclElement',
'role'=>
'models\\Role',
'resource'=>
'models\\Resource',
'permission'=>
'models\\Permission'
90 $this->setClasses($classes);
91 $this->createModel($classes[
'acl'] ?? $this->aclClass,AclElement::class, $dbOffset);
92 $this->createModel($classes[
'role'] ?? $this->roleClass,Role::class, $dbOffset);
93 $this->createModel($classes[
'resource'] ?? $this->resourceClass,Resource::class, $dbOffset);
94 $this->createModel($classes[
'permission'] ?? $this->permissionClass,Permission::class, $dbOffset);
97 public function createModel(
string $modelName,
string $refName,
string $dbOffset=
'default'): void {
98 if ($modelName!==$refName) {
99 $className=ClassUtils::getClassSimpleName($modelName);
100 $ns=ClassUtils::getNamespaceFromCompleteClassname($modelName);
101 $cCreator=
new ClassCreator($className, $ns,
' extends \\'.$refName);
102 if ($dbOffset!==
'default') {
103 $annot=CacheManager::getAnnotationsEngineInstance()->getAnnotation($cCreator,
'database', [
'name'=>$dbOffset]);
104 $cCreator->addClassAttribute($annot);
106 $cCreator->generate();
117 $this->setDbOffset($dbOffset);
119 $activeOffsetValue=DAO::getDbOffset(Startup::$config, $dbOffset);
120 if (($dbName=$activeOffsetValue[
'dbName']??
'')!=
'') {
121 $generator->setModels([$this->aclClass,$this->roleClass,$this->resourceClass,$this->permissionClass]);
122 $generator->createDatabase($dbName, $createDb);
123 $db=DAO::getDatabase($dbOffset);
124 $db->beginTransaction();
125 $db->execute($generator->__toString());
128 throw new AclException(
'dbName key is not present or his value is empty!');
138 $result=
DAO::getAll($this->aclClass);
139 foreach ($result as $elm) {
140 $elm->setType(AclDAOProvider::class);
151 $aclElement->_rest=[];
152 if (!$this->existPart($aclElement->
getResource())) {
158 if (!$this->existPart($aclElement->
getRole())) {
159 $this->savePart($aclElement->
getRole());
161 $object = $this->castElement($aclElement);
162 if ($this->existAcl($aclElement)) {
163 $res=DAO::update($object);
165 $res = DAO::insert($object);
168 $aclElement->
setId($object->getId());
179 return DAO::remove($aclElement);
183 $elements =
DAO::getAll($className);
185 foreach ($elements as $elm) {
186 $elm->setType(AclDAOProvider::class);
187 $result[$elm->getName()] = $elm;
193 $class = $this->getModelClasses()[get_class($part)] ?? get_class($part);
194 return $part->castAs($class);
203 return $this->loadElements($this->permissionClass);
212 return $this->loadElements($this->resourceClass);
221 return $this->loadElements($this->roleClass);
230 $object = $this->castElement($part);
231 if ($this->existPart($part)) {
233 $res = DAO::update($object);
235 $res=DAO::insert($object);
238 $part->setName($object->getName());
249 $object=$this->castElement($part);
251 $object->_pkv[
'___name']=$id;
252 return DAO::update($object);
261 return DAO::remove($this->castElement($part));
271 $elm = $this->castElement($part);
272 return DAO::exists(\get_class($elm),
'name= ?', [
278 $elm = $this->castElement($aclElement);
279 return DAO::exists(\get_class($elm),
'id= ?', [
286 'user' => $this->roleClass,
287 'archive' => $this->resourceClass,
288 'unlock alternate' => $this->permissionClass,
289 'lock' => $this->aclClass
294 $swap = $this->getModelClasses();
295 $classes = \array_values($swap);
297 foreach ($classes as $class) {
298 $result[$class] = $swap;
306 Role::class => $this->roleClass,
307 Resource::class => $this->resourceClass,
325 public static function initializeProvider(array $config,string $dbOffset=
'default',array $classes = []):
AclDAOProvider {
328 $dbProvider->setDbOffset($dbOffset);
329 $dbProvider->generateDbTables($dbOffset);
Manager for caches (Router, Rest, models).
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
static start(array &$config)
Starts the cache in dev mode, for generating the other caches Do not use in production.
static storeModelsDatabases(array $modelsDatabases)
static createOrmModelCache(string $classname)
Ubiquity\exceptions$AclException This class is part of Ubiquity.
Gateway class between database and object model.
static setModelDatabase($model, $database='default')
Defines the database connection to use for $model class.
static getModelsDatabase()
Ubiquity\security\acl\models$AbastractAclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$AclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$Permission This class is part of Ubiquity.
Ubiquity\security\acl\models$Resource This class is part of Ubiquity.
Ubiquity\security\acl\models$Role This class is part of Ubiquity.
Load and save Acls with a database using DAO.
removeAcl(AclElement $aclElement)
{}
loadAllResources()
{Resource[]}
createModels(string $dbOffset='default', ?array $classes=null)
Generates the models.
__construct(array &$config, array $classes=[])
loadAllAcls()
{AclElement[]}
initModelsCache(&$config)
Initialize the cache for the ACL models.
updatePart(string $id, \Ubiquity\security\acl\models\AbstractAclPart $part)
{}
loadElements(string $className)
generateDbTables(string $dbOffset='default', bool $createDb=false)
Generates the tables for ACL model classes.
createModel(string $modelName, string $refName, string $dbOffset='default')
removePart(\Ubiquity\security\acl\models\AbstractAclPart $part)
{}
setDbOffset(string $dbOffset='default', bool $persist=true)
Defines the database offset used for ACL.
loadAllPermissions()
{Permission[]}
saveAcl(AclElement $aclElement)
{}
savePart(\Ubiquity\security\acl\models\AbstractAclPart $part)
{}
setClasses(array $classes)
existAcl(AclElement $aclElement)
Ubiquity\security\acl\persistence$AclProviderInterface This class is part of Ubiquity.
Class Configuration \config.