ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\Utils\Attributes Class Reference
+ Collaboration diagram for SimpleSAML\Utils\Attributes:

Static Public Member Functions

static getExpectedAttribute ($attributes, $expected, $allow_multiple=false)
 Look for an attribute in a normalized attributes array, failing if it's not there. More...
 
static normalizeAttributesArray ($attributes)
 Validate and normalize an array with attributes. More...
 
static getAttributeNamespace ($name, $defaultns)
 Extract an attribute's namespace, or revert to default. More...
 

Detailed Description

Definition at line 10 of file Attributes.php.

Member Function Documentation

◆ getAttributeNamespace()

static SimpleSAML\Utils\Attributes::getAttributeNamespace (   $name,
  $defaultns 
)
static

Extract an attribute's namespace, or revert to default.

This function takes in a namespaced attribute name and splits it in a namespace/attribute name tuple. When no namespace is found in the attribute name, it will be namespaced with the default namespace. This default namespace can be overriden by supplying a second parameter to this function.

Parameters
string$nameThe namespaced attribute name.
string$defaultnsThe default namespace that should be used when no namespace is found.
Returns
array The attribute name, split to the namespace and the actual attribute name.

Definition at line 123 of file Attributes.php.

References $name, and array.

Referenced by sspmod_adfs_IdP_ADFS\generateResponse().

124  {
125  $slash = strrpos($name, '/');
126  if ($slash !== false) {
127  $defaultns = substr($name, 0, $slash);
128  $name = substr($name, $slash + 1);
129  }
130  return array(htmlspecialchars($defaultns), htmlspecialchars($name));
131  }
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getExpectedAttribute()

static SimpleSAML\Utils\Attributes::getExpectedAttribute (   $attributes,
  $expected,
  $allow_multiple = false 
)
static

Look for an attribute in a normalized attributes array, failing if it's not there.

Parameters
array$attributesThe normalized array containing attributes.
string$expectedThe name of the attribute we are looking for.
bool$allow_multipleWhether to allow multiple values in the attribute or not.
Returns
mixed The value of the attribute we are expecting. If the attribute has multiple values and $allow_multiple is set to true, the first value will be returned.
Exceptions

Definition at line 26 of file Attributes.php.

References $attributes.

27  {
28  if (!is_array($attributes)) {
29  throw new \InvalidArgumentException(
30  'The attributes array is not an array, it is: '.print_r($attributes, true).'.'
31  );
32  }
33 
34  if (!is_string($expected)) {
35  throw new \InvalidArgumentException(
36  'The expected attribute is not a string, it is: '.print_r($expected, true).'.'
37  );
38  }
39 
40  if (!array_key_exists($expected, $attributes)) {
41  throw new \SimpleSAML_Error_Exception("No such attribute '".$expected."' found.");
42  }
43  $attribute = $attributes[$expected];
44 
45  if (!is_array($attribute)) {
46  throw new \InvalidArgumentException('The attributes array is not normalized, values should be arrays.');
47  }
48 
49  if (count($attribute) === 0) {
50  throw new \SimpleSAML_Error_Exception("Empty attribute '".$expected."'.'");
51 
52  } elseif (count($attribute) > 1) {
53  if ($allow_multiple === false) {
54  throw new \SimpleSAML_Error_Exception(
55  'More than one value found for the attribute, multiple values not allowed.'
56  );
57  }
58  }
59  return reset($attribute);
60  }
$attributes

◆ normalizeAttributesArray()

static SimpleSAML\Utils\Attributes::normalizeAttributesArray (   $attributes)
static

Validate and normalize an array with attributes.

This function takes in an associative array with attributes, and parses and validates this array. On success, it will return a normalized array, where each attribute name is an index to an array of one or more strings. On failure an exception will be thrown. This exception will contain an message describing what is wrong.

Parameters
array$attributesThe array containing attributes that we should validate and normalize.
Returns
array The normalized attributes array.
Exceptions

Definition at line 80 of file Attributes.php.

References $attributes, $name, array, and SimpleSAML\Utils\Arrays\arrayize().

Referenced by sspmod_exampleauth_Auth_Source_Static\__construct(), sspmod_exampleauth_Auth_Source_UserPass\__construct(), sspmod_authcrypt_Auth_Source_Hash\__construct(), sspmod_authcrypt_Auth_Source_Htpasswd\__construct(), and SimpleSAML_Utilities\parseAttributes().

81  {
82  if (!is_array($attributes)) {
83  throw new \InvalidArgumentException(
84  'The attributes array is not an array, it is: '.print_r($attributes, true).'".'
85  );
86  }
87 
88  $newAttrs = array();
89  foreach ($attributes as $name => $values) {
90  if (!is_string($name)) {
91  throw new \InvalidArgumentException('Invalid attribute name: "'.print_r($name, true).'".');
92  }
93 
94  $values = Arrays::arrayize($values);
95 
96  foreach ($values as $value) {
97  if (!is_string($value)) {
98  throw new \InvalidArgumentException(
99  'Invalid attribute value for attribute '.$name.': "'.print_r($value, true).'".'
100  );
101  }
102  }
103 
104  $newAttrs[$name] = $values;
105  }
106 
107  return $newAttrs;
108  }
static arrayize($data, $index=0)
Put a non-array variable into an array.
Definition: Arrays.php:24
$attributes
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: