コード例 #1
0
 /**
  * The entity ID will pass validation, but raise an exception if the format of the service name and privacy realm
  * are in the incorrect format.
  * The service name and privacy realm need to be under 10 chars eg.
  * http://hostname.domain/serviceName/privacyRealm
  *
  * @return void
  */
 private function validateEntityID()
 {
     foreach ($this->service->getAllowedRealMeEnvironments() as $env) {
         $entityId = $this->service->getEntityIDForEnvironment($env);
         if (true === is_null($entityId)) {
             $this->errors[] = _t('RealMeSetupTask.ERR_CONFIG_NO_ENTITYID', '', '', array('env' => $env));
         }
         // make sure the entityID is a valid URL
         $entityId = filter_var($entityId, FILTER_VALIDATE_URL);
         if (false === $entityId) {
             $this->errors[] = _t('RealMeSetupTask.ERR_CONFIG_ENTITYID', '', '', array('env' => $env, 'entityId' => $entityId));
             // invalid entity id, no point continuing.
             return;
         }
         // check it's not localhost and HTTPS. and make sure we have a host / scheme
         $urlParts = parse_url($entityId);
         if ('localhost' === $urlParts['host'] || 'http' === $urlParts['scheme']) {
             $this->errors[] = _t('RealMeSetupTask.ERR_CONFIG_ENTITYID', '', '', array('env' => $env, 'entityId' => $entityId));
             // if there's this much wrong, we want them to fix it first.
             return;
         }
         $path = ltrim($urlParts['path']);
         $urlParts = preg_split("/\\//", $path);
         // Validate Service Name
         $serviceName = array_pop($urlParts);
         if (mb_strlen($serviceName) > 10 || 0 === mb_strlen($serviceName)) {
             $this->errors[] = _t('RealMeSetupTask.ERR_CONFIG_ENTITYID_SERVICE_NAME', '', '', array('env' => $env, 'serviceName' => $serviceName, 'entityId' => $entityId));
         }
         // Validate Privacy Realm
         $privacyRealm = array_pop($urlParts);
         if (mb_strlen($privacyRealm) > 10 || 0 === mb_strlen($privacyRealm)) {
             $this->errors[] = _t('RealMeSetupTask.ERR_CONFIG_ENTITYID_PRIVACY_REALM', '', '', array('env' => $env, 'privacyRealm' => $privacyRealm, 'entityId' => $entityId));
         }
     }
 }