示例#1
0
 /**
  * This method retrieves a dictionary with the name given.
  *
  * @param string $name The name of the dictionary, as the filename in the dictionary directory, without the
  * '.php' ending.
  *
  * @return array An associative array with the dictionary.
  */
 private function getDictionary($name)
 {
     assert('is_string($name)');
     if (!array_key_exists($name, $this->dictionaries)) {
         $sepPos = strpos($name, ':');
         if ($sepPos !== false) {
             $module = substr($name, 0, $sepPos);
             $fileName = substr($name, $sepPos + 1);
             $dictDir = \SimpleSAML\Module::getModuleDir($module) . '/dictionaries/';
         } else {
             $dictDir = $this->configuration->getPathValue('dictionarydir', 'dictionaries/');
             $fileName = $name;
         }
         $this->dictionaries[$name] = $this->readDictionaryFile($dictDir . $fileName);
     }
     return $this->dictionaries[$name];
 }
示例#2
0
 /**
  * Test for SimpleSAML\Module::getModuleDir().
  */
 public function testGetModuleDir()
 {
     // test for the most basic functionality
     $this->assertEquals(dirname(dirname(dirname(dirname(__FILE__)))) . '/modules/module', Module::getModuleDir('module'));
 }
示例#3
0
 /**
  * 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;
     }
 }