/** * process subselects of query * * @param SelectStatement $AST * @param AclConditionStorage $aclCondition */ protected function processSubRequests(SelectStatement $AST, AclConditionStorage $aclCondition) { if (!is_null($aclCondition->getSubRequests())) { $subRequests = $aclCondition->getSubRequests(); foreach ($subRequests as $subRequest) { /** @var SubRequestAclConditionStorage $subRequest */ $conditionalExpression = $AST->whereClause->conditionalExpression; if (isset($conditionalExpression->conditionalFactors)) { $subselect = $conditionalExpression->conditionalFactors[$subRequest->getFactorId()]->simpleConditionalExpression->subselect; } elseif (isset($conditionalExpression->conditionalTerms)) { $subselect = $conditionalExpression->conditionalTerms[$subRequest->getFactorId()]->simpleConditionalExpression->subselect; } else { $subselect = $conditionalExpression->simpleConditionalExpression->subselect; } $whereConditions = $subRequest->getWhereConditions(); if (!is_null($whereConditions) && count($whereConditions)) { $this->addAclToWhereClause($subselect, $whereConditions); } $joinConditions = $subRequest->getJoinConditions(); if (!is_null($joinConditions) && count($joinConditions)) { $this->addAclToJoinClause($subselect, $joinConditions); } } } }
/** * Check subrequests for acl access level * * @param SelectStatement $ast * @param AclConditionStorage $storage * @param $permission */ protected function processSubselects(SelectStatement $ast, AclConditionStorage $storage, $permission) { $conditionalExpression = $ast->whereClause->conditionalExpression; if ($conditionalExpression instanceof ConditionalPrimary) { // we have request with only one where condition $expression = $conditionalExpression->simpleConditionalExpression; if (isset($expression->subselect) && $expression->subselect instanceof Subselect) { $subRequestAclStorage = $this->processSubselect($expression->subselect, $permission); if (!$subRequestAclStorage->isEmpty()) { $subRequestAclStorage->setFactorId(0); $storage->addSubRequests($subRequestAclStorage); } } } else { // we have request with only many where conditions $subQueryAcl = []; if (isset($conditionalExpression->conditionalFactors)) { $factors = $conditionalExpression->conditionalFactors; } else { $factors = $conditionalExpression->conditionalTerms; } foreach ($factors as $factorId => $expression) { if (isset($expression->simpleConditionalExpression->subselect) && $expression->simpleConditionalExpression->subselect instanceof Subselect) { $subRequestAclStorage = $this->processSubselect($expression->simpleConditionalExpression->subselect, $permission); if (!$subRequestAclStorage->isEmpty()) { $subRequestAclStorage->setFactorId($factorId); $subQueryAcl[] = $subRequestAclStorage; } } } if (!empty($subQueryAcl)) { $storage->setSubRequests($subQueryAcl); } } }
/** * process subselects of query * * @param SelectStatement $AST * @param AclConditionStorage $aclCondition */ protected function processSubRequests(SelectStatement $AST, AclConditionStorage $aclCondition) { if (!is_null($aclCondition->getSubRequests())) { $subRequests = $aclCondition->getSubRequests(); foreach ($subRequests as $subRequest) { /** @var SubRequestAclConditionStorage $subRequest */ $conditionalExpression = $AST->whereClause->conditionalExpression; if (isset($conditionalExpression->conditionalFactors)) { $factorId = $subRequest->getFactorId(); foreach ($conditionalExpression->conditionalFactors as $factor) { $subSelect = $this->getSubSelectFromFactor($factor, $factorId); if ($subSelect) { $this->addRequestConditions($subSelect, $subRequest); } } } elseif (isset($conditionalExpression->simpleConditionalExpression)) { $subSelect = $conditionalExpression->simpleConditionalExpression->subselect; $this->addRequestConditions($subSelect, $subRequest); } } } }
public function testStorage() { $whereConditions = [new AclCondition('test', 'id', [])]; $joinConditions = [new JoinAclCondition('testJoin', 'id', [])]; $subRequests = [new SubRequestAclConditionStorage([], [])]; $storage = new AclConditionStorage([], []); $this->assertTrue($storage->isEmpty()); $storage->setJoinConditions($joinConditions); $this->assertFalse($storage->isEmpty()); $storage->setJoinConditions([]); $storage->setWhereConditions($whereConditions); $this->assertFalse($storage->isEmpty()); $storage->setWhereConditions([]); $storage->setSubRequests($subRequests); $this->assertFalse($storage->isEmpty()); $storage->setWhereConditions($whereConditions); $storage->setJoinConditions($joinConditions); $this->assertEquals($whereConditions, $storage->getWhereConditions()); $this->assertEquals($joinConditions, $storage->getJoinConditions()); $this->assertEquals($subRequests, $storage->getSubRequests()); }