/** * This method is meant to set appropriated extra data to $pra depending on comparison type * * @param PolicyRuleAttribute $pra * @param object $user * @param object $resource */ public function processRuleAttributeComparisonType(PolicyRuleAttribute $pra, $user, $resource) { switch ($pra->getComparisonType()) { case 'user': $pra->setExtraData(['user' => $user]); break; case 'object': $pra->setExtraData(['resource' => $resource]); break; } }
/** * @param \PhpAbac\Model\PolicyRuleAttribute $pra * @param object $user * @param object $resource */ public function processExtraData(PolicyRuleAttribute $pra, $user, $resource) { foreach ($pra->getExtraData() as $key => $data) { switch ($key) { case 'with': // This data has to be removed for it will be stored elsewhere // in the policy rule attribute $pra->removeExtraData('with'); // The "with" extra data is an array of attributes, which are objects // Once we process it as policy rule attributes, we set it as the main policy rule attribute value $subPolicyRuleAttributes = []; $extraData = []; foreach ($this->policyRuleManager->processRuleAttributes($data, $user, $resource) as $subPolicyRuleAttribute) { $subPolicyRuleAttributes[] = $subPolicyRuleAttribute; } $pra->setValue($subPolicyRuleAttributes); // This data can be used in complex comparisons $pra->addExtraData('attribute', $pra->getAttribute()); $pra->addExtraData('user', $user); $pra->addExtraData('resource', $resource); break; } } }