ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Attributes.php
Go to the documentation of this file.
1<?php
2namespace SimpleSAML\Utils;
3
11{
12
26 public static function getExpectedAttribute($attributes, $expected, $allow_multiple = false)
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 }
60
61
79 public static function normalizeAttributesArray($attributes)
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 }
108
109
122 public static function getAttributeNamespace($name, $defaultns)
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 }
131}
An exception for terminatinating execution or to throw for unit testing.
static arrayize($data, $index=0)
Put a non-array variable into an array.
Definition: Arrays.php:24
static getExpectedAttribute($attributes, $expected, $allow_multiple=false)
Look for an attribute in a normalized attributes array, failing if it's not there.
Definition: Attributes.php:26
static normalizeAttributesArray($attributes)
Validate and normalize an array with attributes.
Definition: Attributes.php:79
static getAttributeNamespace($name, $defaultns)
Extract an attribute's namespace, or revert to default.
Definition: Attributes.php:122
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$values