SimpleSAML_Metadata_MetaDataStorageHandler::getPreferredEntityIdFromCIDRhint PHP Method

getPreferredEntityIdFromCIDRhint() public method

This method will call getPreferredEntityIdFromCIDRhint() on all of the sources.
public getPreferredEntityIdFromCIDRhint ( string $set, string $ip ) : string
$set string Which set of metadata we are looking it up in.
$ip string IP address
return string The entity id of a entity which have a CIDR hint where the provided IP address match.
    public function getPreferredEntityIdFromCIDRhint($set, $ip)
    {
        foreach ($this->sources as $source) {
            $entityId = $source->getPreferredEntityIdFromCIDRhint($set, $ip);
            if ($entityId !== null) {
                return $entityId;
            }
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * Retrieve a recommended IdP based on the IP address of the client.
  *
  * @return string|null  The entity ID of the IdP if one is found, or null if not.
  */
 protected function getFromCIDRhint()
 {
     foreach ($this->metadataSets as $metadataSet) {
         $idp = $this->metadata->getPreferredEntityIdFromCIDRhint($metadataSet, $_SERVER['REMOTE_ADDR']);
         if (!empty($idp)) {
             return $idp;
         }
     }
     return null;
 }