Exemplo n.º 1
0
 /**
  * Compiles PHP-tags in the given template.
  *
  * @param string $template The template to compile the PHP tags in
  * @return string
  */
 private function compilePhpTags($template)
 {
     if (StringUtil::contains($template, '<?')) {
         $template = str_replace(array('<?', '?>'), array('@@PHP_OPEN_TAG@@', '@@PHP_CLOSE_TAG@@'), $template);
         $template = str_replace(array('@@PHP_OPEN_TAG@@', '@@PHP_CLOSE_TAG@@'), array('<?php echo \'<?\'; ?>', '<?php echo \'?>\'; ?>'), $template);
     }
     return $template;
 }
Exemplo n.º 2
0
 /**
  * Returns the file where to save the compiled version of the given source template.
  *
  * @param string $sourceTemplateFile The source template file for which to get the file of the compiled version
  * @throws \Ableron\Core\Exception\SystemException
  * @return string
  */
 public function getCompiledTemplateFile($sourceTemplateFile)
 {
     // make sure "./" and "../" are handled correctly
     $sourceTemplateFile = StringUtil::contains($sourceTemplateFile, './') ? FileUtil::normalizePath(realpath($sourceTemplateFile)) : $sourceTemplateFile;
     // extract template information from path (module, area and template name)
     if (!preg_match('#/Modules/(?<module>[^/]+)(?<path>(/[^/]+)+?)/(?<name>[^/]+)\\.tpl$#', $sourceTemplateFile, $templateInfo)) {
         throw new SystemException(sprintf('Template file has invalid path: %s (Pattern of valid template file: .../<module>/**/<name>.tpl, e.g. **/app/Modules/Core/Pages/Backend/Templates/IndexPage.tpl)', $sourceTemplateFile), 0, E_USER_ERROR, __FILE__, __LINE__);
     }
     // build and return file name of the compiled template
     return FileUtil::getTempFileName(sprintf('tpl/%s/%s/%s', $templateInfo['module'], $templateInfo['path'], Application::getI18nHandler()->getLocale()->getLocaleCode()), '', $templateInfo['name'], 'php');
 }
Exemplo n.º 3
0
 /**
  * Checks whether the given host name needs to be surrounded by square brackets.
  *
  * The host name needs to be surrounded by square brackets in case it contains
  * a colon (:) and is not already surrounded by square brackets.
  *
  * Returns TRUE in case the given host name needs to be surrounded by square brackets.
  * Otherwise returns FALSE.
  *
  * @param string $host The host name to check
  * @return bool
  */
 public static function needsSquareBrackets($host)
 {
     return $host !== null && StringUtil::contains($host, ':') && !StringUtil::startsWith($host, '[');
 }
Exemplo n.º 4
0
 /**
  * Validates the given cache key.
  *
  * A valid key has a length of at least one character and does not
  * contains any of these characters: {}()/\@:
  *
  * @param string $key The key to validate
  * @throws \Psr\Cache\InvalidArgumentException In case the given key is invalid
  * @return void
  */
 protected function validateKey(string $key)
 {
     // check minimum length
     if (StringUtil::getLength($key) < 1) {
         throw new InvalidArgumentException('Cache key must have a length of at least one character');
     }
     // check reserved characters
     foreach ($this->reservedCharacters as $reservedCharacter) {
         if (StringUtil::contains($key, $reservedCharacter)) {
             throw new InvalidArgumentException('Cache key must must not contain reserved character "' . $reservedCharacter . '"');
         }
     }
 }