public function testGetRule() { $countries = (include 'tests/fixtures/countries.php'); $visas = (include 'tests/fixtures/visas.php'); $users = (include 'tests/fixtures/users.php'); $vehicles = (include 'tests/fixtures/vehicles.php'); $policyRule = $this->manager->getRule('vehicle-homologation', $users[0], $vehicles[0]); $this->assertInstanceof('PhpAbac\\Model\\PolicyRule', $policyRule); $this->assertEquals('vehicle-homologation', $policyRule->getName()); $this->assertCount(6, $policyRule->getPolicyRuleAttributes()); $policyRuleAttribute = $policyRule->getPolicyRuleAttributes()[0]; $this->assertInstanceOf('PhpAbac\\Model\\PolicyRuleAttribute', $policyRuleAttribute); $this->assertInstanceOf('PhpAbac\\Model\\Attribute', $policyRuleAttribute->getAttribute()); $this->assertEquals('boolean', $policyRuleAttribute->getComparisonType()); $this->assertEquals('boolAnd', $policyRuleAttribute->getComparison()); $this->assertTrue($policyRuleAttribute->getValue()); }
/** * @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; } } }