public function getAcl() { if ($this->acl) { return $this->acl; } $cache = $this->getCache(); if ($cache && ($data = $cache->get('acl'))) { return $this->acl = $data; } $acl = new MemoryAcl(); $acl->setDefaultAction(Acl::DENY); $roles = Entities\Roles::find(); foreach ($roles as $role) { $roleName = $role->name ? $role->name : $role->roleKey; $acl->addRole($role->roleKey, $role->roleKey); } $resources = Entities\Resources::find(); foreach ($resources as $resource) { $acl->addResource($resource->resourceKey); } $operations = Entities\Operations::find(); foreach ($operations as $operation) { $acl->addResourceAccess($operation->resourceKey, $operation->operationKey); if ($operation->roles) { foreach ($operation->roles as $role) { $acl->allow($role->roleKey, $operation->resourceKey, $operation->operationKey); } } } if ($cache) { $cache->save('acl', $acl); } return $this->acl = $acl; }
public function process(SplFileInfo $controller) { $controllerPath = $controller->getPathName(); $controllerClass = $this->getClassName($controller->getContents()); if (!$controllerClass) { return $this; } $resource = $this->getResource($controllerClass); if (!$resource) { return $this; } $operations = $this->getOperations($controllerClass); if (!$operations) { return $this; } $resourceModel = Entities\Resources::findFirstByResourceKey($resource['resourceKey']); if (!$resourceModel) { $resourceModel = new Entities\Resources(); } $resourceModel->assign($resource); $operationModels = array(); foreach ($operations as $operation) { $operationModel = Entities\Operations::findFirst(array("conditions" => "resourceKey = :resourceKey: AND operationKey = :operationKey:", "bind" => array('resourceKey' => $operation['resourceKey'], 'operationKey' => $operation['operationKey']))); if (!$operationModel) { $operationModel = new Entities\Operations(); } $operationModel->assign($operation); $operationModels[] = $operationModel; } $resourceModel->operations = $operationModels; if ($resourceModel->save()) { echo sprintf("Resource %s already added to DB\n", $resource['resourceKey']); } else { print_r($resourceModel->getMessages()); } /* p($resource); p($operations); p('-----------------'); */ return $this; }