The function will always return an absolute path unless the option is not set. It will then return the default
value.
It checks if the value starts with a slash, and prefixes it with the value from getBaseDir if it doesn't.
public getPathValue ( string $name, string | null $default = null ) : string | null | ||
$name | string | Name of the configuration option. |
$default | string | null | Default value of the configuration option. This parameter will default to null if not specified. |
Результат | string | null | The path configuration option with name $name, or $default if the option was not found. |
/** * Initialize the output. * * @param SimpleSAML_Configuration $config The configuration for this output. */ public function __construct(SimpleSAML_Configuration $config) { $this->logDir = $config->getPathValue('directory'); if ($this->logDir === NULL) { throw new Exception('Missing "directory" option for core:File'); } if (!is_dir($this->logDir)) { throw new Exception('Could not find log directory: ' . var_export($this->logDir, TRUE)); } }
/** * Find template path. * * This function locates the given template based on the template name. It will first search for the template in * the current theme directory, and then the default theme. * * The template name may be on the form <module name>:<template path>, in which case it will search for the * template file in the given module. * * @param string $template The relative path from the theme directory to the template file. * * @return string The absolute path to the template file. * * @throws Exception If the template file couldn't be found. */ private function findTemplatePath($template, $throw_exception = true) { assert('is_string($template)'); $result = $this->findModuleAndTemplateName($template); $templateModule = $result[0] ? $result[0] : 'default'; $templateName = $result[1]; $tmp = explode(':', $this->configuration->getString('theme.use', 'default'), 2); if (count($tmp) === 2) { $themeModule = $tmp[0]; $themeName = $tmp[1]; } else { $themeModule = null; $themeName = $tmp[0]; } // first check the current theme if ($themeModule !== null) { // .../module/<themeModule>/themes/<themeName>/<templateModule>/<templateName> $filename = \SimpleSAML\Module::getModuleDir($themeModule) . '/themes/' . $themeName . '/' . $templateModule . '/' . $templateName; } elseif ($templateModule !== 'default') { // .../module/<templateModule>/templates/<templateName> $filename = \SimpleSAML\Module::getModuleDir($templateModule) . '/templates/' . $templateName; } else { // .../templates/<theme>/<templateName> $filename = $this->configuration->getPathValue('templatedir', 'templates/') . $templateName; } if (file_exists($filename)) { return $filename; } // not found in current theme \SimpleSAML\Logger::debug($_SERVER['PHP_SELF'] . ' - Template: Could not find template file [' . $template . '] at [' . $filename . '] - now trying the base template'); // try default theme if ($templateModule !== 'default') { // .../module/<templateModule>/templates/<templateName> $filename = \SimpleSAML\Module::getModuleDir($templateModule) . '/templates/' . $templateName; } else { // .../templates/<templateName> $filename = $this->configuration->getPathValue('templatedir', 'templates/') . '/' . $templateName; } if (file_exists($filename)) { return $filename; } // not found in default template if ($throw_exception) { // log error and throw exception $error = 'Template: Could not find template file [' . $template . '] at [' . $filename . ']'; \SimpleSAML\Logger::critical($_SERVER['PHP_SELF'] . ' - ' . $error); throw new Exception($error); } else { // missing template expected, return NULL return null; } }
/** * Build a new logging handler based on files. */ public function __construct(\SimpleSAML_Configuration $config) { // get the metadata handler option from the configuration $this->logFile = $config->getPathValue('loggingdir', 'log/') . $config->getString('logging.logfile', 'simplesamlphp.log'); $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp'); if (@file_exists($this->logFile)) { if (!@is_writeable($this->logFile)) { throw new \Exception("Could not write to logfile: " . $this->logFile); } } else { if (!@touch($this->logFile)) { throw new \Exception("Could not create logfile: " . $this->logFile . " The logging directory is not writable for the web server user."); } } \SimpleSAML\Utils\Time::initTimezone(); }
/** * Include a language file from the dictionaries directory. * * @param string $file File name of dictionary to include * @param \SimpleSAML_Configuration|null $otherConfig Optionally provide a different configuration object than the * one provided in the constructor to be used to find the directory of the dictionary. This allows to combine * dictionaries inside the SimpleSAMLphp main code distribution together with external dictionaries. Defaults to * null. */ public function includeLanguageFile($file, $otherConfig = null) { if (!empty($otherConfig)) { $filebase = $otherConfig->getPathValue('dictionarydir', 'dictionaries/'); } else { $filebase = $this->configuration->getPathValue('dictionarydir', 'dictionaries/'); } $lang = $this->readDictionaryFile($filebase . $file); \SimpleSAML\Logger::debug('Template: Merging language array. Loading [' . $file . ']'); $this->langtext = array_merge($this->langtext, $lang); }