From: Roland Häder Date: Sat, 14 Mar 2009 03:35:31 +0000 (+0000) Subject: Now all base paths are relative and constructed in BaseTemplateEngine genericly,... X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=e460e503df60eec92ab83b3167eed2e5399097f5 Now all base paths are relative and constructed in BaseTemplateEngine genericly, re-added cache path --- diff --git a/.gitattributes b/.gitattributes index d27ef43b..34429048 100644 --- a/.gitattributes +++ b/.gitattributes @@ -507,6 +507,8 @@ inc/selector.php -text /svn-externals.txt -text templates/.htaccess -text templates/_compiled/.htaccess -text +templates/images/.htaccess -text +templates/images/_cache/.htaccess -text tests/ConfigTest.php -text tests/RegistryTest.php -text tests/RequestTest.php -text diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index ade1a136..48ab38c3 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -740,13 +740,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // END - if } // END - if - // Generate FQFN for all application templates - $fqfn = sprintf("%s%s/%s", - $this->getConfigInstance()->readConfig('application_path'), - strtolower($appInstance->getAppShortName()), - $this->getConfigInstance()->readConfig('tpl_base_path') - ); - // Are both instances set? if ($appInstance->getLanguageInstance() === null) { // Invalid language instance @@ -757,7 +750,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // Initialize the template engine - $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance())); + $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($appInstance)); // Return the prepared instance return $templateInstance; diff --git a/inc/classes/main/io/class_FrameworkDirectoryPointer.php b/inc/classes/main/io/class_FrameworkDirectoryPointer.php index e0a0c4e5..fbd45cf5 100644 --- a/inc/classes/main/io/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/io/class_FrameworkDirectoryPointer.php @@ -62,22 +62,21 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { * Create a directory pointer based on the given path. The path will also * be verified here. * - * @param $pathName The path name we shall pass - * to opendir() - * @param $inConstructor If we are in de/con-structor - * or from somewhere else - * @throws PathIsEmptyException If the provided path name + * @param $pathName The path name we shall pass to opendir() + * @param $inConstructor If we are in de/con-structor or from somewhere + * else + * @return $pointerInstance A prepared instance of + * FrameworkDirectoryPointer + * @throws PathIsEmptyException If the provided path name * is empty * @throws InvalidPathStringException If the provided path name is - * not a string + * not a string * @throws PathIsNoDirectoryException If the provided path name is - * not valid + * not valid * @throws PathReadProtectedException If the provided path name is - * read-protected + * read-protected * @throws DirPointerNotOpened If opendir() returns not a - * directory resource - * @return $pointerInstance A prepared instance of - * FrameworkDirectoryPointer + * directory resource */ public final static function createFrameworkDirectoryPointer ($pathName, $inConstructor = false) { // Some pre-sanity checks... diff --git a/inc/classes/main/language/class_LanguageSystem.php b/inc/classes/main/language/class_LanguageSystem.php index fe66586a..9174badb 100644 --- a/inc/classes/main/language/class_LanguageSystem.php +++ b/inc/classes/main/language/class_LanguageSystem.php @@ -26,7 +26,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, /** * The full-qualified base path for the language include files */ - private $basePath = ''; + private $languageBasePath = ''; /** * The 2-char language code @@ -60,36 +60,36 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, /** * Creates an instance of the class LanguageSystem and prepares it for usage * - * @param $basePath The local base path for all language strings + * @param $languageBasePath The local base path for all language strings * @return $langInstance An instance of LanguageSystem - * @throws LanguagePathIsEmptyException If the provided $basePath is empty - * @throws InvalidLanguagePathStringException If $basePath is no string - * @throws LanguagePathIsNoDirectoryException If $basePath is no + * @throws LanguagePathIsEmptyException If the provided $languageBasePath is empty + * @throws InvalidLanguagePathStringException If $languageBasePath is no string + * @throws LanguagePathIsNoDirectoryException If $languageBasePath is no * directory or not found - * @throws LanguagePathReadProtectedException If $basePath is + * @throws LanguagePathReadProtectedException If $languageBasePath is * read-protected */ - public final static function createLanguageSystem ($basePath) { + public final static function createLanguageSystem ($languageBasePath) { // Get a new instance $langInstance = new LanguageSystem(); // Is the base path valid? - if (empty($basePath)) { + if (empty($languageBasePath)) { // Language path is empty throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($basePath)) { + } elseif (!is_string($languageBasePath)) { // Is not a string - throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING); - } elseif (!is_dir($basePath)) { + throw new InvalidLanguagePathStringException(array($langInstance, $languageBasePath), self::EXCEPTION_INVALID_STRING); + } elseif (!is_dir($languageBasePath)) { // Is not a path - throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME); - } elseif (!is_readable($basePath)) { + throw new LanguagePathIsNoDirectoryException(array($langInstance, $languageBasePath), self::EXCEPTION_INVALID_PATH_NAME); + } elseif (!is_readable($languageBasePath)) { // Is not readable - throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH); + throw new LanguagePathReadProtectedException(array($langInstance, $languageBasePath), self::EXCEPTION_READ_PROTECED_PATH); } // Set the base path - $langInstance->setBasePath($basePath); + $langInstance->setLanguageBasePath($languageBasePath); // Initialize the variable stack $langInstance->initLanguageStrings(); @@ -107,7 +107,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, /** * Singleton getter for this instance * - * @return $thisInstance An instance of this class + * @return $thisInstance An instance of this class */ public final static function getInstance () { return self::$thisInstance; @@ -116,18 +116,18 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, /** * Setter for base path * - * @param $basePath The local base path for all templates + * @param $languageBasePath The relative base path for all language files * @return void */ - protected final function setBasePath ($basePath) { + protected final function setLanguageBasePath ($languageBasePath) { // And set it - $this->basePath = (string) $basePath; + $this->languageBasePath = (string) $languageBasePath; } /** * Setter for language code * - * @param $langCode The language code for the current application + * @param $langCode The language code for the current application * @return void */ protected final function setLanguageCode ($langCode) { @@ -150,7 +150,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, /** * Getter for language code * - * @return $langCode The language code for the current application + * @return $langCode The language code for the current application */ public final function getLanguageCode () { return $this->langCode; diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 21234b81..60fa5f54 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -27,7 +27,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * templates are stored. We will internally determine the language plus * "html" for web templates or "emails" for email templates */ - private $basePath = ''; + private $templateBasePath = ''; /** * Template type @@ -45,9 +45,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem { private $codeExtension = '.ctp'; /** - * Path relative to $basePath and language code for compiled code-templates + * Path relative to $templateBasePath and language code for compiled code-templates */ - private $compileOutputPath = 'templates/_compiled'; + private $compileOutputPath = 'templates/_compiled/'; + + /** + * The path name for all templates + */ + private $genericBasePath = 'templates/'; /** * The raw (maybe uncompiled) template @@ -327,22 +332,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Setter for base path * - * @param $basePath The local base path for all templates + * @param $templateBasePath The relative base path for all templates * @return void */ - public final function setBasePath ($basePath) { + public final function setTemplateBasePath ($templateBasePath) { // And set it - $this->basePath = (string) $basePath; + $this->templateBasePath = (string) $templateBasePath; } /** * Getter for base path * - * @return $basePath The local base path for all templates + * @return $templateBasePath The relative base path for all templates */ - public final function getBasePath () { + public final function getTemplateBasePath () { // And set it - return $this->basePath; + return $this->templateBasePath; } /** @@ -523,10 +528,10 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } // END - if // Construct the FQFN for the template by honoring the current language - $fqfn = sprintf("%s%s/%s%s/%s/%s%s", - $this->getConfigInstance()->readConfig('application_path'), - Registry::getRegistry()->getInstance('application')->getAppShortName(), - $this->getBasePath(), + $fqfn = sprintf("%s%s%s%s/%s/%s%s", + $this->getConfigInstance()->readConfig('base_path'), + $this->getTemplateBasePath(), + $this->genericBasePath, $this->getLanguageInstance()->getLanguageCode(), $this->getTemplateType(), (string) $template, diff --git a/inc/classes/main/template/image/class_ImageTemplateEngine.php b/inc/classes/main/template/image/class_ImageTemplateEngine.php index f20dc1b6..21e1490f 100644 --- a/inc/classes/main/template/image/class_ImageTemplateEngine.php +++ b/inc/classes/main/template/image/class_ImageTemplateEngine.php @@ -74,41 +74,46 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl /** * Creates an instance of the class TemplateEngine and prepares it for usage * - * @param $basePath The local base path for all templates - * @param $langInstance An instance of LanguageSystem (default) - * @param $ioInstance An instance of FileIoHandler (default, middleware!) + * @param $appInstance A manageable application * @return $tplInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $basePath is empty - * @throws InvalidBasePathStringException If $basePath is no string - * @throws BasePathIsNoDirectoryException If $basePath is no + * @throws BasePathIsEmptyException If the provided $templateBasePath is empty + * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found - * @throws BasePathReadProtectedException If $basePath is + * @throws BasePathReadProtectedException If $templateBasePath is * read-protected */ - public final static function createImageTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) { + public final static function createImageTemplateEngine (ManageableApplication $appInstance) { // Get a new instance $tplInstance = new ImageTemplateEngine(); + // Get language and file I/O instances from application + $langInstance = $appInstance->getLanguageInstance(); + $ioInstance = $appInstance->getFileIoInstance(); + + // Determine base path + $templateBasePath = $tplInstance->getConfigInstance()->readConfig('application_base_path') . $appInstance->getRequestInstance()->getRequestElement('app') . '/'; + // Is the base path valid? - if (empty($basePath)) { + if (empty($templateBasePath)) { // Base path is empty throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($basePath)) { + } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING); - } elseif (!is_dir($basePath)) { + throw new InvalidBasePathStringException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + } elseif (!is_dir($templateBasePath)) { // Is not a path - throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME); - } elseif (!is_readable($basePath)) { + throw new BasePathIsNoDirectoryException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); + } elseif (!is_readable($templateBasePath)) { // Is not readable - throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH); + throw new BasePathReadProtectedException(array($tplInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH); } // Get configuration instance $configInstance = FrameworkConfiguration::getInstance(); // Set the base path - $tplInstance->setBasePath($basePath); + $tplInstance->setTemplateBasePath($templateBasePath); // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); @@ -469,7 +474,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl */ public function getImageCacheFqfn () { // Get the FQFN ready - $fqfn = $this->getBasePath().'_cache/' . md5($this->imageInstance->getImageName().':'.$this->__toString().':'.$this->imageInstance->__toString()) . '.' . $this->imageInstance->getImageType(); + $fqfn = $this->getTemplateBasePath().'_cache/' . md5($this->imageInstance->getImageName().':'.$this->__toString().':'.$this->imageInstance->__toString()) . '.' . $this->imageInstance->getImageType(); // Return it return $fqfn; diff --git a/inc/classes/main/template/mail/class_MailTemplateEngine.php b/inc/classes/main/template/mail/class_MailTemplateEngine.php index 64811c5e..c7c6d11b 100644 --- a/inc/classes/main/template/mail/class_MailTemplateEngine.php +++ b/inc/classes/main/template/mail/class_MailTemplateEngine.php @@ -60,41 +60,46 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla /** * Creates an instance of the class TemplateEngine and prepares it for usage * - * @param $basePath The local base path for all templates - * @param $langInstance An instance of LanguageSystem (default) - * @param $ioInstance An instance of FileIoHandler (default, middleware!) + * @param $appInstance A manageable application * @return $tplInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $basePath is empty - * @throws InvalidBasePathStringException If $basePath is no string - * @throws BasePathIsNoDirectoryException If $basePath is no + * @throws BasePathIsEmptyException If the provided $templateBasePath is empty + * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found - * @throws BasePathReadProtectedException If $basePath is + * @throws BasePathReadProtectedException If $templateBasePath is * read-protected */ - public final static function createMailTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) { + public final static function createMailTemplateEngine (ManageableApplication $appInstance) { // Get a new instance $tplInstance = new MailTemplateEngine(); + // Get language and file I/O instances from application + $langInstance = $appInstance->getLanguageInstance(); + $ioInstance = $appInstance->getFileIoInstance(); + + // Determine base path + $templateBasePath = $tplInstance->getConfigInstance()->readConfig('application_base_path') . $appInstance->getRequestInstance()->getRequestElement('app') . '/'; + // Is the base path valid? - if (empty($basePath)) { + if (empty($templateBasePath)) { // Base path is empty throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($basePath)) { + } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING); - } elseif (!is_dir($basePath)) { + throw new InvalidBasePathStringException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + } elseif (!is_dir($templateBasePath)) { // Is not a path - throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME); - } elseif (!is_readable($basePath)) { + throw new BasePathIsNoDirectoryException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); + } elseif (!is_readable($templateBasePath)) { // Is not readable - throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH); + throw new BasePathReadProtectedException(array($tplInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH); } // Get configuration instance $configInstance = FrameworkConfiguration::getInstance(); // Set the base path - $tplInstance->setBasePath($basePath); + $tplInstance->setTemplateBasePath($templateBasePath); // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); diff --git a/inc/classes/main/template/web/class_WebTemplateEngine.php b/inc/classes/main/template/web/class_WebTemplateEngine.php index fbd5d572..855a2a02 100644 --- a/inc/classes/main/template/web/class_WebTemplateEngine.php +++ b/inc/classes/main/template/web/class_WebTemplateEngine.php @@ -36,41 +36,46 @@ class WebTemplateEngine extends BaseTemplateEngine implements CompileableTemplat /** * Creates an instance of the class TemplateEngine and prepares it for usage * - * @param $basePath The local base path for all templates - * @param $langInstance An instance of LanguageSystem (default) - * @param $ioInstance An instance of FileIoHandler (default, middleware!) + * @param $appInstance A manageable application * @return $tplInstance An instance of TemplateEngine - * @throws BasePathIsEmptyException If the provided $basePath is empty - * @throws InvalidBasePathStringException If $basePath is no string - * @throws BasePathIsNoDirectoryException If $basePath is no + * @throws BasePathIsEmptyException If the provided $templateBasePath is empty + * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws BasePathIsNoDirectoryException If $templateBasePath is no * directory or not found - * @throws BasePathReadProtectedException If $basePath is + * @throws BasePathReadProtectedException If $templateBasePath is * read-protected */ - public final static function createWebTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) { + public final static function createWebTemplateEngine (ManageableApplication $appInstance) { // Get a new instance $tplInstance = new WebTemplateEngine(); + // Get language and file I/O instances from application + $langInstance = $appInstance->getLanguageInstance(); + $ioInstance = $appInstance->getFileIoInstance(); + + // Determine base path + $templateBasePath = $tplInstance->getConfigInstance()->readConfig('application_base_path') . $appInstance->getRequestInstance()->getRequestElement('app') . '/'; + // Is the base path valid? - if (empty($basePath)) { + if (empty($templateBasePath)) { // Base path is empty throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($basePath)) { + } elseif (!is_string($templateBasePath)) { // Is not a string - throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING); - } elseif (!is_dir($basePath)) { + throw new InvalidBasePathStringException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + } elseif (!is_dir($templateBasePath)) { // Is not a path - throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME); - } elseif (!is_readable($basePath)) { + throw new BasePathIsNoDirectoryException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); + } elseif (!is_readable($templateBasePath)) { // Is not readable - throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH); + throw new BasePathReadProtectedException(array($tplInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH); } // Get configuration instance $configInstance = FrameworkConfiguration::getInstance(); // Set the base path - $tplInstance->setBasePath($basePath); + $tplInstance->setTemplateBasePath($templateBasePath); // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); diff --git a/inc/config.php b/inc/config.php index d4620733..72d5f986 100644 --- a/inc/config.php +++ b/inc/config.php @@ -80,8 +80,11 @@ $cfg->setConfigEntry('lang_base_path', "inc/language/"); // CFG: COMPRESSOR-BASE-PATH $cfg->setConfigEntry('compressor_base_path', "inc/classes/main/compressor/"); +// CFG: APPLICATION-BASE-PATH +$cfg->setConfigEntry('application_base_path', "application/"); + // CFG: APPLICATION-PATH -$cfg->setConfigEntry('application_path', $cfg->readConfig('base_path') . "application/"); +$cfg->setConfigEntry('application_path', $cfg->readConfig('base_path') . $cfg->readConfig('application_base_path')); // CFG: COMPILE-OUTPUT-PATH $cfg->setConfigEntry('compile_output_path', "templates/_compiled/"); diff --git a/templates/images/.htaccess b/templates/images/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/templates/images/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/templates/images/_cache/.htaccess b/templates/images/_cache/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/templates/images/_cache/.htaccess @@ -0,0 +1 @@ +Deny from all