]> git.mxchange.org Git - core.git/commitdiff
MenuTemplateEngine heavily extended, but still in non-working state
authorRoland Häder <roland@mxchange.org>
Wed, 2 Sep 2009 21:56:00 +0000 (21:56 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Sep 2009 21:56:00 +0000 (21:56 +0000)
12 files changed:
.gitattributes
inc/classes/exceptions/controller/class_DefaultControllerException.php
inc/classes/exceptions/controller/class_InvalidControllerException.php
inc/classes/exceptions/crypto/class_EncryptInvalidLengthException.php
inc/classes/exceptions/main/class_InvalidCommandException.php
inc/classes/exceptions/state/class_InvalidStateException.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/menu/class_BaseMenu.php
inc/classes/main/template/image/class_ImageTemplateEngine.php
inc/classes/main/template/menu/class_MenuTemplateEngine.php
templates/menus/.htaccess [new file with mode: 0644]
templates/menus/_cache/.htaccess [new file with mode: 0644]

index 4f46c62127de77a3536f3886835758a685304242..0185c481464acb134b29f5f881ecba75c0f250f5 100644 (file)
@@ -552,6 +552,8 @@ templates/.htaccess -text
 templates/_compiled/.htaccess -text
 templates/images/.htaccess -text
 templates/images/_cache/.htaccess -text
+templates/menus/.htaccess -text
+templates/menus/_cache/.htaccess -text
 tests/ConfigTest.php -text
 tests/RegistryTest.php -text
 tests/RequestTest.php -text
index 89a1a5063557500f281fb6e5dc7010c8358b32ff..551c0c5decc348c61211ba85fd72af1bc1e17390 100644 (file)
@@ -38,7 +38,7 @@ class DefaultControllerException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($resolverInstance->getClassName().':'.$this->getLine());
+               $this->setExtraData($resolverInstance->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
index a8e1d96a9b599e72d45b00c9091395e776aac884..b637ae7a4f39f4b1550cc8a054847903b9b47fc6 100644 (file)
@@ -39,7 +39,7 @@ class InvalidControllerException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
index 63c6c2e37238526876bc58a666ab4499b10cc0f2..a6af83da2f00765ff966dbdb1e018b20d85aef3e 100644 (file)
@@ -41,7 +41,7 @@ class EncryptInvalidLengthException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($filterInstance->__toString().':'.$length);
+               $this->setExtraData($filterInstance->__toString() . ':' . $length);
 
                // Call parent exception constructor
                parent::__construct($message, $code);
index a46bb95f977d8db3822a3381abe19fc58f0e0887..ea743a53ee0e9adbf6d898647b39f3ca3f6fd544 100644 (file)
@@ -39,7 +39,7 @@ class InvalidCommandException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent constructor
                parent::__construct($message, $code);
index 1aeefefb293cdd64baa3571aa0388cd3716ad2c2..f781c48c5979f1f435f257f2d549fae6d98ae57e 100644 (file)
@@ -39,7 +39,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -89,7 +89,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -139,7 +139,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -189,7 +189,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -239,7 +239,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -289,7 +289,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -339,7 +339,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -389,7 +389,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
@@ -439,7 +439,7 @@ class InvalidStateException extends FrameworkException {
                );
 
                // Set extra data
-               $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine());
+               $this->setExtraData($msgArray[0]->getClassName() . ':' . $this->getLine());
 
                // Call parent contructor with message
                parent::__construct($message, $code);
index f07ba33bc3f0ebe8e5e6c47a010cab8457fc315a..f297db74122d5f41ec0c7d49af7c2076891c85c5 100644 (file)
@@ -88,6 +88,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $listInstance = null;
 
+       /**
+        * Instance of a menu
+        */
+       private $menuInstance = null;
+
        /**
         * The real class name
         */
@@ -1205,6 +1210,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        protected final function getListInstance () {
                return $this->listInstance;
        }
+
+       /**
+        * Setter for the menu instance
+        *
+        * @param       $menuInstance   A RenderableMenu instance
+        * @return      void
+        */
+       protected final function setMenuInstance (RenderableMenu $menuInstance) {
+               $this->menuInstance = $menuInstance;
+       }
+
+       /**
+        * Getter for the menu instance
+        *
+        * @return      $menuInstance   A RenderableMenu instance
+        */
+       protected final function getMenuInstance () {
+               return $this->menuInstance;
+       }
 }
 
 // [EOF]
index aedf6c2873c53cb4d8441be4b22026c4c58eb6f7..8041813b3f5151eb955eed43db010f55c585a044 100644 (file)
@@ -41,13 +41,23 @@ class BaseMenu extends BaseFrameworkSystem {
         */
        public function renderMenu () {
                // Initialize the menu system by preparing it's template instance
-               $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this->getApplicationInstance()));
+               $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this->getApplicationInstance(), $this));
 
                // Set it for later use
                $this->setTemplateInstance($templateInstance);
 
-               // Load the base (XML) template for generating menus
-               $this->getTemplateInstance()->loadMenuTemplate('base_menu');
+               // Load the menu template for all
+               $this->getTemplateInstance()->loadMenuTemplate('generic_menu_entries');
+
+               // Get the 'page' from request instance
+               $page = $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page');
+
+               // Load the menu template for this page
+               try {
+                       $this->getTemplateInstance()->loadMenuTemplate($page . '_menu_entries');
+               } catch (FileNotFoundException $e) {
+                       // @TODO Should we log it here? We should, because it will be silently ignored.
+               }
 
                // Get the prepared content
                $menuContent = $this->getTemplateInstance()->getRawTemplateData();
index 13192647bff39340215213238ddb7b9bd865f0f3..19b83c77f90b69991f616afe0c6f322e935c6276 100644 (file)
@@ -199,7 +199,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         * @return      void
         * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
         */
-       protected function endElement ($resource, $nodeName) {
+       public function endElement ($resource, $nodeName) {
                // Make all lower-case
                $nodeName = strtolower($nodeName);
 
@@ -228,7 +228,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         * @return      void
         * @todo        Find something usefull with this!
         */
-       protected function characterHandler ($resource, $characters) {
+       public function characterHandler ($resource, $characters) {
                // Trim all spaces away
                $characters = trim($characters);
 
@@ -479,7 +479,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                        $this->getGenericBasePath(),
                        'images/_cache',
                        md5(
-                               $this->imageInstance->getImageName().':'.$this->__toString().':'.$this->imageInstance->__toString()
+                               $this->imageInstance->getImageName() . ':' . $this->__toString() . ':' . $this->imageInstance->__toString()
                        ),
                        $this->imageInstance->getImageType()
                );
index 9f179c0f4e8928e0d0c9f2272ea4bb5a8d159340..0dbd2cb806bcaf7799a99ab2c2ade74d3415b3eb 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
+       /**
+        * Main nodes in the XML tree ('menu' is ignored)
+        */
+       private $mainNodes = array(
+               'header',
+               'entries',
+               'footer',
+       );
+
+       /**
+        * Sub nodes in the XML tree
+        */
+       private $subNodes = array(
+               'title',
+               'entry',
+               'anchor',
+               'design',
+               'text',
+               'advert',
+       );
+
+       /**
+        * Menu instance
+        */
+       private $menuInstance = null;
+
+       /**
+        * Current main node
+        */
+       private $currMainNode = '';
+
        /**
         * Protected constructor
         *
@@ -36,6 +67,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * Creates an instance of the class TemplateEngine and prepares it for usage
         *
         * @param       $appInstance    A manageable application
+        * @param       $menuInstance   A RenderableMenu instance
         * @return      $tplInstance    An instance of TemplateEngine
         * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
         * @throws      InvalidBasePathStringException  If $templateBasePath is no string
@@ -44,7 +76,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @throws      BasePathReadProtectedException  If $templateBasePath is
         *                                                                                      read-protected
         */
-       public final static function createMenuTemplateEngine (ManageableApplication $appInstance) {
+       public final static function createMenuTemplateEngine (ManageableApplication $appInstance, RenderableMenu $menuInstance) {
                // Get a new instance
                $tplInstance = new MenuTemplateEngine();
 
@@ -87,6 +119,9 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                // Absolute output path for compiled templates
                $tplInstance->setCompileOutputPath($configInstance->getConfigEntry('base_path') . $configInstance->getConfigEntry('compile_output_path'));
 
+               // Set the menu instance
+               $tplInstance->setMenuInstance($menuInstance);
+
                // Return the prepared instance
                return $tplInstance;
        }
@@ -105,6 +140,154 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                // Load the special template
                $this->loadTemplate($template);
        }
+
+       /**
+        * Getter for current main node
+        *
+        * @return      $currMainNode   Current main node
+        */
+       public final function getCurrMainNode () {
+               return $this->currMainNode;
+       }
+
+       /**
+        * Getter for main node array
+        *
+        * @return      $mainNodes      Array with valid main node names
+        */
+       public final function getMainNodes () {
+               return $this->mainNodes;
+       }
+
+       /**
+        * Getter for sub node array
+        *
+        * @return      $subNodes       Array with valid sub node names
+        */
+       public final function getSubNodes () {
+               return $this->subNodes;
+       }
+
+       /**
+        * Handles the start element of an XML resource
+        *
+        * @param       $resource               XML parser resource (currently ignored)
+        * @param       $element                The element we shall handle
+        * @param       $attributes             All attributes
+        * @return      void
+        * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
+        */
+       public function startElement ($resource, $element, array $attributes) {
+               // Initial method name which will never be called...
+               $methodName = 'initMenu';
+
+               // Make the element name lower-case
+               $element = strtolower($element);
+
+               // Is the element a main node?
+               /* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
+               if (in_array($element, $this->getMainNodes())) {
+                       // Okay, main node found!
+                       $methodName = 'startMenu' . $this->convertToClassName($element);
+
+                       // Set it
+                       $this->currMainNode = $element;
+               } elseif (in_array($element, $this->getSubNodes())) {
+                       // Sub node found
+                       $methodName = 'setMenuProperty' . $this->convertToClassName($element);
+               } elseif ($element != 'menu') {
+                       // Invalid node name found
+                       throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
+               }
+
+               // Call method
+               /* DEBUG: */ echo "call: ".$methodName."<br />\n";
+               call_user_func_array(array($this, $methodName), $attributes);
+       }
+
+       /**
+        * Ends the main or sub node by sending out the gathered data
+        *
+        * @param       $resource       An XML resource pointer (currently ignored)
+        * @param       $nodeName       Name of the node we want to finish
+        * @return      void
+        * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
+        */
+       public function endElement ($resource, $nodeName) {
+               // Make all lower-case
+               $nodeName = strtolower($nodeName);
+
+               // Does this match with current main node?
+               /* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
+               if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
+                       // Did not match!
+                       throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
+               } elseif (in_array($nodeName, $this->getSubNodes())) {
+                       // Silently ignore sub nodes
+                       return;
+               }
+
+               // Construct method name
+               $methodName = 'finish' . $this->convertToClassName($nodeName);
+
+               // Call the corresponding method
+               /* DEBUG: */ echo "call: ".$methodName."<br />\n";
+               call_user_func_array(array($this->getMenuInstance(), $methodName), array());
+       }
+
+       /**
+        * Currently not used
+        *
+        * @param       $resource               XML parser resource (currently ignored)
+        * @param       $characters             Characters to handle
+        * @return      void
+        * @todo        Find something usefull with this!
+        */
+       public function characterHandler ($resource, $characters) {
+               // Trim all spaces away
+               $characters = trim($characters);
+
+               // Is this string empty?
+               if (empty($characters)) {
+                       // Then skip it silently
+                       return false;
+               } // END - if
+
+               // Unfinished work!
+               $this->partialStub("Handling extra characters is not yet supported!");
+       }
+
+       /**
+        * Intializes the menu
+        *
+        * @return      void
+        * @todo        Add cache creation here
+        */
+       private function initMenu () {
+               // Unfinished work!
+               $this->partialStub('Please implement this method.');
+       }
+
+       /**
+        * Getter for menu cache file (FQFN)
+        *
+        * @return      $fqfn   Full-qualified file name of the menu cache
+        */
+       public function getMenuCacheFqfn () {
+               // Get the FQFN ready
+               $fqfn = sprintf("%s%s%s/%s.%s",
+                       $this->getConfigInstance()->getConfigEntry('base_path'),
+                       $this->getGenericBasePath(),
+                       'menus/_cache',
+                       md5(
+                               $this->getMenuInstance()->getMenuName() . ':' . $this->__toString() . ':' . $this->getMenuInstance()->__toString()
+                       ),
+                       $this->getMenuInstance()->getMenuType()
+               );
+
+               // Return it
+               return $fqfn;
+       }
 }
 
 // [EOF]
diff --git a/templates/menus/.htaccess b/templates/menus/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/templates/menus/_cache/.htaccess b/templates/menus/_cache/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all