SimpleSAML_Configuration::getBasePath PHP Method

getBasePath() public method

The path is guaranteed to start and end with a slash ('/'). E.g.: /simplesaml/
public getBasePath ( ) : string
return string The absolute path where SimpleSAMLphp can be reached in the web server.
    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);
        }
    }

Usage Example

コード例 #1
0
 /**
  * Constructor
  *
  * @param SimpleSAML_Configuration $configuration Configuration object
  * @param string                   $template Which template file to load
  * @param string|null              $defaultDictionary The default dictionary where tags will come from.
  */
 public function __construct(\SimpleSAML_Configuration $configuration, $template, $defaultDictionary = null)
 {
     $this->configuration = $configuration;
     $this->template = $template;
     // TODO: do not remove the slash from the beginning, change the templates instead!
     $this->data['baseurlpath'] = ltrim($this->configuration->getBasePath(), '/');
     $result = $this->findModuleAndTemplateName($template);
     $this->module = $result[0];
     $this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary);
     $this->localization = new \SimpleSAML\Locale\Localization($configuration);
     $this->twig = $this->setupTwig();
 }
All Usage Examples Of SimpleSAML_Configuration::getBasePath