SimpleSAML_Configuration::resolvePath PHP Method

resolvePath() public method

The path will never end with a '/'.
public resolvePath ( string | null $path ) : string | null
$path string | null The path we should resolve. This option may be null.
return string | null $path if $path is an absolute path, or $path prepended with the base directory of this SimpleSAMLphp installation. We will return NULL if $path is null.
    public function resolvePath($path)
    {
        if ($path === null) {
            return null;
        }
        assert('is_string($path)');
        /* Prepend path with basedir if it doesn't start with a slash or a Windows drive letter (e.g. "C:\"). We assume
         * getBaseDir ends with a slash.
         */
        if ($path[0] !== '/' && !(preg_match('@^[a-z]:[\\\\/]@i', $path, $matches) && is_dir($matches[0]))) {
            $path = $this->getBaseDir() . $path;
        }
        // remove trailing slashes
        $path = rtrim($path, '/');
        return $path;
    }

Usage Example

コード例 #1
0
 /**
  * Setup twig.
  */
 private function setupTwig()
 {
     $auto_reload = $this->configuration->getBoolean('template.auto_reload', true);
     $cache = false;
     if (!$auto_reload) {
         // Cache only used if auto_reload = false
         $cache = $this->configuration->getString('template.cache', $this->configuration->resolvePath('cache'));
     }
     // set up template paths
     $loader = $this->setupTwigTemplatepaths();
     // abort if twig template does not exist
     if (!$loader->exists($this->twig_template)) {
         return false;
     }
     // load extra i18n domains
     if ($this->module) {
         $this->localization->addModuleDomain($this->module);
     }
     $options = array('cache' => $cache, 'auto_reload' => $auto_reload, 'translation_function' => array('\\SimpleSAML\\Locale\\Translate', 'translateSingularNativeGettext'), 'translation_function_plural' => array('\\SimpleSAML\\Locale\\Translate', 'translatePluralNativeGettext'));
     // set up translation
     if ($this->localization->i18nBackend === \SimpleSAML\Locale\Localization::GETTEXT_I18N_BACKEND) {
         $options['translation_function'] = array('\\SimpleSAML\\Locale\\Translate', 'translateSingularGettext');
         $options['translation_function_plural'] = array('\\SimpleSAML\\Locale\\Translate', 'translatePluralGettext');
     }
     // TODO: add a branch for the old SimpleSAMLphp backend
     $twig = new Twig_Environment($loader, $options);
     $twig->addExtension(new Twig_Extensions_Extension_I18n());
     return $twig;
 }
All Usage Examples Of SimpleSAML_Configuration::resolvePath