Now all base paths are relative and constructed in BaseTemplateEngine genericly,...
authorRoland Häder <roland@mxchange.org>
Sat, 14 Mar 2009 03:35:31 +0000 (03:35 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 14 Mar 2009 03:35:31 +0000 (03:35 +0000)
.gitattributes
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/io/class_FrameworkDirectoryPointer.php
inc/classes/main/language/class_LanguageSystem.php
inc/classes/main/template/class_BaseTemplateEngine.php
inc/classes/main/template/image/class_ImageTemplateEngine.php
inc/classes/main/template/mail/class_MailTemplateEngine.php
inc/classes/main/template/web/class_WebTemplateEngine.php
inc/config.php
templates/images/.htaccess [new file with mode: 0644]
templates/images/_cache/.htaccess [new file with mode: 0644]

index d27ef43..3442904 100644 (file)
@@ -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
index ade1a13..48ab38c 100644 (file)
@@ -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;
index e0a0c4e..fbd45cf 100644 (file)
@@ -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...
index fe66586..9174bad 100644 (file)
@@ -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;
index 21234b8..60fa5f5 100644 (file)
@@ -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,
index f20dc1b..21e1490 100644 (file)
@@ -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;
index 64811c5..c7c6d11 100644 (file)
@@ -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);
index fbd5d57..855a2a0 100644 (file)
@@ -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);
index d462073..72d5f98 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/templates/images/_cache/.htaccess b/templates/images/_cache/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all