SimpleSAML_XML_Shib13_AuthnResponse::enc_attribute PHP Method

enc_attribute() private method

Format a shib13 attribute.
private enc_attribute ( string $name, array $values, boolean $base64, array $scopedAttributes ) : string
$name string Name of the attribute.
$values array Values of the attribute (as an array of strings).
$base64 boolean Whether the attriubte values should be base64-encoded.
$scopedAttributes array Array of attributes names which are scoped.
return string The attribute encoded as an XML-string.
    private function enc_attribute($name, $values, $base64, $scopedAttributes)
    {
        assert('is_string($name)');
        assert('is_array($values)');
        assert('is_bool($base64)');
        assert('is_array($scopedAttributes)');
        if (in_array($name, $scopedAttributes, TRUE)) {
            $scoped = TRUE;
        } else {
            $scoped = FALSE;
        }
        $attr = '<Attribute AttributeName="' . htmlspecialchars($name) . '" AttributeNamespace="urn:mace:shibboleth:1.0:attributeNamespace:uri">';
        foreach ($values as $value) {
            $scopePart = '';
            if ($scoped) {
                $tmp = explode('@', $value, 2);
                if (count($tmp) === 2) {
                    $value = $tmp[0];
                    $scopePart = ' Scope="' . htmlspecialchars($tmp[1]) . '"';
                }
            }
            if ($base64) {
                $value = base64_encode($value);
            }
            $attr .= '<AttributeValue' . $scopePart . '>' . htmlspecialchars($value) . '</AttributeValue>';
        }
        $attr .= '</Attribute>';
        return $attr;
    }