SimpleSAML_Configuration::getLocalizedString PHP Method

getLocalizedString() public method

The default language returned is always 'en'.
public getLocalizedString ( string $name, mixed $default = self::REQUIRED_OPTION ) : array
$name string The name of the option.
$default mixed The default value. If no default is given, and the option isn't found, an exception will be thrown.
return array Associative array with language => string pairs.
    public function getLocalizedString($name, $default = self::REQUIRED_OPTION)
    {
        assert('is_string($name)');
        $ret = $this->getValue($name, $default);
        if ($ret === $default) {
            // the option wasn't found, or it matches the default value. In any case, return this value
            return $ret;
        }
        $loc = $this->location . '[' . var_export($name, true) . ']';
        if (is_string($ret)) {
            $ret = array('en' => $ret);
        }
        if (!is_array($ret)) {
            throw new Exception($loc . ': Must be an array or a string.');
        }
        foreach ($ret as $k => $v) {
            if (!is_string($k)) {
                throw new Exception($loc . ': Invalid language code: ' . var_export($k, true));
            }
            if (!is_string($v)) {
                throw new Exception($loc . '[' . var_export($v, true) . ']: Must be a string.');
            }
        }
        return $ret;
    }

Usage Example

コード例 #1
0
 /**
  * Add an AttributeConsumingService element to the metadata.
  *
  * @param \SAML2\XML\md\SPSSODescriptor $spDesc The SPSSODescriptor element.
  * @param SimpleSAML_Configuration     $metadata The metadata.
  */
 private function addAttributeConsumingService(\SAML2\XML\md\SPSSODescriptor $spDesc, SimpleSAML_Configuration $metadata)
 {
     $attributes = $metadata->getArray('attributes', array());
     $name = $metadata->getLocalizedString('name', null);
     if ($name === null || count($attributes) == 0) {
         // we cannot add an AttributeConsumingService without name and attributes
         return;
     }
     $attributesrequired = $metadata->getArray('attributes.required', array());
     /*
      * Add an AttributeConsumingService element with information as name and description and list
      * of requested attributes
      */
     $attributeconsumer = new \SAML2\XML\md\AttributeConsumingService();
     $attributeconsumer->index = 0;
     $attributeconsumer->ServiceName = $name;
     $attributeconsumer->ServiceDescription = $metadata->getLocalizedString('description', array());
     $nameFormat = $metadata->getString('attributes.NameFormat', \SAML2\Constants::NAMEFORMAT_UNSPECIFIED);
     foreach ($attributes as $friendlyName => $attribute) {
         $t = new \SAML2\XML\md\RequestedAttribute();
         $t->Name = $attribute;
         if (!is_int($friendlyName)) {
             $t->FriendlyName = $friendlyName;
         }
         if ($nameFormat !== \SAML2\Constants::NAMEFORMAT_UNSPECIFIED) {
             $t->NameFormat = $nameFormat;
         }
         if (in_array($attribute, $attributesrequired)) {
             $t->isRequired = true;
         }
         $attributeconsumer->RequestedAttribute[] = $t;
     }
     $spDesc->AttributeConsumingService[] = $attributeconsumer;
 }
All Usage Examples Of SimpleSAML_Configuration::getLocalizedString