/** * This method is meant to convert attribute data from array to formatted policy rule attribute * * @param array $attributes * @param object $user * @param object $resource */ public function processRuleAttributes($attributes, $user, $resource) { foreach ($attributes as $attributeName => $attribute) { $pra = (new PolicyRuleAttribute())->setAttribute($this->attributeManager->getAttribute($attributeName))->setComparison($attribute['comparison'])->setComparisonType($attribute['comparison_type'])->setValue(isset($attribute['value']) ? $attribute['value'] : null); $this->processRuleAttributeComparisonType($pra, $user, $resource); // In the case the user configured more keys than the basic ones // it will be stored as extra data foreach ($attribute as $key => $value) { if (!in_array($key, ['comparison', 'comparison_type', 'value'])) { $pra->addExtraData($key, $value); } } // This generator avoid useless memory consumption instead of returning a whole array (yield $pra); } }
/** * Function to prepare Getter Params when getter require parameters ( this parameters must be specified in configuration file) * * @param $getter_params * @param $user * @param $resource * * @return array */ private function prepareGetterParams($getter_params, $user, $resource) { if (empty($getter_params)) { return []; } $values = []; foreach ($getter_params as $getter_name => $params) { foreach ($params as $param) { if ('@' !== $param['param_name'][0]) { $values[$getter_name][] = $param['param_value']; } else { $values[$getter_name][] = $this->attributeManager->retrieveAttribute($this->attributeManager->getAttribute($param['param_value']), $user, $resource); } } } return $values; }
public function testRetrieveEnvironmentAttribute() { $this->assertEquals('OPEN', $this->manager->retrieveAttribute($this->manager->getAttribute('environment.service_state'), (new User())->setAge(18))); }