]> git.mxchange.org Git - core.git/commitdiff
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 d27ef43b139c03987bde3c7fbf3b168f63b33109..34429048609f38247725691200a12623812fa91d 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 ade1a13689ac103c78ec8f242eb438a343fcf9d5..48ab38c3c2554eaacb91ee16f6fd7c9a072c2061 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 e0a0c4e5bfcae51f016229ba1e1d758302787ad7..fbd45cf5b561f5c6abba91b1926090c8945f1aec 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 fe66586aadaae8a5240595705bc910090b8259c4..9174badb31ef745a44f7d1ae3b820dd319459047 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 21234b81e8295b2e6eac43680f543a7068202fb8..60fa5f54e3c9fc997af5ce9f906ba71598c6379d 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 f20dc1b6732ee529174fefb49c02639b19f5a0e1..21e1490f5bc5e7ea0d809e34b2a467bf026d3815 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 64811c5e5104eb7e05cdb5ad5a5875b1dc349d98..c7c6d11bca52eea6037e5ec6afbf3f449f23bdc8 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 fbd5d5724c7515270b28e310f8f25b71610ef666..855a2a0297e29f7f7beab12420f999fb9df411ea 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 d46207331f9b536d02bdaa54a389cb10994f1438..72d5f9868c550393803fa138d6a6e67a371fd671 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