ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 122 of file Attributes.php.

123 {
124 $slash = strrpos($name, '/');
125 if ($slash !== false) {
126 $defaultns = substr($name, 0, $slash);
127 $name = substr($name, $slash + 1);
128 }
129 return array(htmlspecialchars($defaultns), htmlspecialchars($name));
130 }

References $name.

Referenced by sspmod_adfs_IdP_ADFS\generateResponse().

+ 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

InvalidArgumentException If $attributes is not an array or $expected is not a string.

Exceptions

SimpleSAML_Error_Exception If the expected attribute was not found in the attributes array.

Definition at line 26 of file Attributes.php.

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 } elseif (count($attribute) > 1) {
52 if ($allow_multiple === false) {
53 throw new \SimpleSAML_Error_Exception(
54 'More than one value found for the attribute, multiple values not allowed.'
55 );
56 }
57 }
58 return reset($attribute);
59 }
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85

References $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

InvalidArgumentException If input is not an array, array keys are not strings or attribute values are not strings.

Author
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no
Jaime Perez, UNINETT AS jaime.nosp@m..per.nosp@m.ez@un.nosp@m.inet.nosp@m.t.no

Definition at line 79 of file Attributes.php.

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

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

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

+ 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: