/**
  * Retrieve the absolute path pointing to the SimpleSAMLphp installation.
  *
  * The path is guaranteed to start and end with a slash ('/'). E.g.: /simplesaml/
  *
  * @return string The absolute path where SimpleSAMLphp can be reached in the web server.
  *
  * @throws SimpleSAML\Error\CriticalConfigurationError If the format of 'baseurlpath' is incorrect.
  */
 public function getBasePath()
 {
     $baseURL = $this->getString('baseurlpath', 'simplesaml/');
     if (preg_match('#^https?://[^/]*(?:/(.+/?)?)?$#', $baseURL, $matches)) {
         // we have a full url, we need to strip the path
         if (!array_key_exists(1, $matches)) {
             // absolute URL without path
             return '/';
         }
         return '/' . rtrim($matches[1], '/') . "/";
     } elseif ($baseURL === '' || $baseURL === '/') {
         // root directory of site
         return '/';
     } elseif (preg_match('#^/?((?:[^/\\s]+/?)+)#', $baseURL, $matches)) {
         // local path only
         return '/' . rtrim($matches[1], '/') . '/';
     } else {
         /*
          * Invalid 'baseurlpath'. We cannot recover from this, so throw a critical exception and try to be graceful
          * with the configuration. Use a guessed base path instead of the one provided.
          */
         $c = $this->toArray();
         $c['baseurlpath'] = SimpleSAML\Utils\HTTP::guessBasePath();
         throw new SimpleSAML\Error\CriticalConfigurationError('Incorrect format for option \'baseurlpath\'. Value is: "' . $this->getString('baseurlpath', 'simplesaml/') . '". Valid format is in the form' . ' [(http|https)://(hostname|fqdn)[:port]]/[path/to/simplesaml/].', $this->filename, $c);
     }
 }