[geeklog-cvs] MVCnPHP ArrayLoader.php,1.1.1.1,1.2 BaseLoader.php,1.1.1.1,1.2 BaseView.php,1.1.1.1,1.2 CommandFactory.php,1.1.1.1,1.2 CommandInterface.php,1.1.1.1,1.2 Constants.php,1.1.1.1,1.2 Controller.php,1.1.1.1,1.2 Form.php,1.1.1.1,1.2 LoaderFactory.php,1.1.1.1,1.2 Mapping.php,1.1.1.1,1.2 Validator.php,1.1.1.1,1.2 ViewFactory.php,1.1.1.1,1.2 ViewInterface.php,1.1.1.1,1.2 XMLLoader.php,1.1.1.1,1.2 XMLParser.php,1.1.1.1,NONE

tony at iowaoutdoors.org tony at iowaoutdoors.org
Wed Mar 2 14:55:51 EST 2005


Update of /var/cvs/MVCnPHP
In directory www:/tmp/cvs-serv31871

Modified Files:
	ArrayLoader.php BaseLoader.php BaseView.php CommandFactory.php 
	CommandInterface.php Constants.php Controller.php Form.php 
	LoaderFactory.php Mapping.php Validator.php ViewFactory.php 
	ViewInterface.php XMLLoader.php 
Removed Files:
	XMLParser.php 
Log Message:
Updates to use PHP5 XML features.







Index: Constants.php
===================================================================
RCS file: /var/cvs/MVCnPHP/Constants.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Constants.php	14 Dec 2004 20:53:36 -0000	1.1.1.1
--- Constants.php	2 Mar 2005 19:55:49 -0000	1.2
***************
*** 13,17 ****
  *
  * @author Tony Bibbs <tony at geeklog.net>
! * @copyright Tony Bibbs 2003
  * @package net.geeklog.mvc
  * @version $Id$
--- 13,17 ----
  *
  * @author Tony Bibbs <tony at geeklog.net>
! * @copyright Tony Bibbs 2003-2005
  * @package net.geeklog.mvc
  * @version $Id$

Index: XMLLoader.php
===================================================================
RCS file: /var/cvs/MVCnPHP/XMLLoader.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** XMLLoader.php	14 Dec 2004 20:53:36 -0000	1.1.1.1
--- XMLLoader.php	2 Mar 2005 19:55:49 -0000	1.2
***************
*** 25,33 ****
  
  /**
- * MVC XML parser
- */
- require_once 'XMLParser.php';
- 
- /**
  * This loader creates a mapping from an XML file
  *
--- 25,28 ----
***************
*** 37,40 ****
--- 32,67 ----
  */
  class MVCnPHP_XMLLoader extends MVCnPHP_BaseLoader {
+     /**
+      * Handle to an XML DOM
+      * @access protected
+      * @var array
+      */
+     protected $dom = null;
+     
+     /**
+      * Holds array representation of XML config file
+      * @access protected
+      * @var array
+      */
+     protected $arrayData = null;
+     
+     const VIEWS = 'VIEW';    
+     const COMMANDS = 'COMMAND';
+     
+     /**
+      * Constructor
+      *
+      * Initializes object properties and, if the XML has been supplied it will parse it immediately 
+      * instead of waiting for an explicit call to parseXML
+      *
+      * @author Tony Bibbs <tony at geeklog.net>
+      * @access public
+      * @param string $xmlString XML to parse
+      *
+      */
+     public function __construct()
+     {
+         $this->dom = new DomDocument();
+     }
      
      /**
***************
*** 51,116 ****
      public function getMapping($name, $viewsDir, $commandsDir, $baseURL, $arrayData = '')
      {
          if (!file_exists($arrayData) AND !is_array($this->arrayData)) {
              return false;
          }
          if (empty($this->arrayData)) {                
!             $xmlData = file_get_contents($arrayData);
!             $this->arrayData = $this->XMLToArray($xmlData);
          }
          return parent::getMapping($name, $viewsDir, $commandsDir, $baseURL, $this->arrayData);
      }
      
      /**
!     * Parses XML string into loader's expected array format
!     *
!     * @author Tony Bibbs <tony at geeklog.net>
!     * @access private
!     * @param string $xmlData XML to be parsed
!     *
!     */
!     private function XMLToArray($xmlData)
      {
!         $parser = new MVCnPHP_XMLParser($xmlData);
!         $elements = $parser->getElementIndexes();
!         $configData = Array();
!         foreach ($elements as $curIndex) {
!             switch ($parser->getTag($curIndex)) {
!                 case 'VIEW':
!                     $view = $parser->getAttribute($curIndex, 'id');
!                     $default = $parser->getAttribute($curIndex, 'default');
!                     $configData[MVC_VIEWS][$view][MVC_NAME] = $parser->getAttribute($curIndex, 'name');
!                     if ($default) {
!                         $configData[MVC_VIEWS][$view][MVC_DEFAULT] = true;
!                     }
!                     break;
!                 case 'COMMAND':
!                     $command = $parser->getAttribute($curIndex, 'id');
!                     $default = $parser->getAttribute($curIndex, 'default');
!                     $configData[MVC_COMMANDS][$command][MVC_NAME] = $parser->getAttribute($curIndex, 'name');
!                     if ($default) {
!                         $configData[MVC_COMMANDS][$command][MVC_DEFAULT] = true;
!                     }
!                     break;
!                 case 'FORWARD':
!                     $name = $parser->getAttribute($curIndex, 'id');
!                     $parentTag = $parser->getTag($parser->getAttribute($curIndex, 'parent'));
!                     $parentIDAttr = $parser->getAttribute($parser->getAttribute($curIndex, 'parent'), 'id');
!                     if ($parentTag == 'VIEW') {
!                         $configData[MVC_VIEWS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TARGET] = $parser->getValue($curIndex);
!                         $configData[MVC_VIEWS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TYPE] = $parser->getAttribute($curIndex, 'type');
!                     } else {
!                         if ($parentTag == 'COMMAND') {
!                             $configData[MVC_COMMANDS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TARGET] = $parser->getValue($curIndex);
!                             $configData[MVC_COMMANDS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TYPE] = $parser->getAttribute($curIndex, 'type');
!                         } else {
!                         	throw new Exception('Hit unexpected XML tag in XMLLoader::_XMLToArray');
!                         }    
!                     }
!                     break;
!                 default:
              }
          }
!         return $configData;
!     }    
  }
  
--- 78,186 ----
      public function getMapping($name, $viewsDir, $commandsDir, $baseURL, $arrayData = '')
      {
+         global $glConf;
+         
          if (!file_exists($arrayData) AND !is_array($this->arrayData)) {
              return false;
          }
          if (empty($this->arrayData)) {                
!             $xmlData = file_get_contents($arrayData); 
!         
!             $arrayFileName = $glConf['path'] . 'compiled_mvcconfig.php';
!             $needsCompile = false;
!             if (file_exists($arrayFileName)) {
!                 if (filemtime($arrayFileName) < filemtime($arrayData)) {
!                     $needsCompile = true;
!                 }
!             } else {
!                 $needsCompile = true;
!             }
! 
!             if ($needsCompile) {           
!         		$this->dom->loadXML($xmlData);		
!         		if (!empty($xmlData)) {
!                     $this->xmlToArray();
!         		}
!             } else {            
!                 require_once $glConf['path'] . 'compiled_mvcconfig.php';
!             }
          }
+         
          return parent::getMapping($name, $viewsDir, $commandsDir, $baseURL, $this->arrayData);
      }
      
      /**
!      * Converts the MVC XML configuration into an array
!      *
!      * @author Tony Bibbs <tony at geeklog.net>
!      * @access public
!      *
!      */
!     public function xmlToArray() 
      {
!         $arrayData = array();
!         $arrayData['views'] = $this->parseSection(MVCnPHP_XMLLoader::VIEWS);
!         $arrayData['commands'] = $this->parseSection(MVCnPHP_XMLLoader::COMMANDS);
!         
!         /*$fp = fopen($glConf['path'] . 'compiled_mvcconfig.php', 'w');
!         fwrite($fp, '<?php $this->arrayData = */
!         $this->arrayData = $arrayData;
!     }
!     
!     /**
!      * Parses a section of the XML configuration
!      *
!      * @author Tony Bibbs <tony at geeklog.net>
!      * @access private
!      * @param string $section Use one of the two class constants for this value
!      * @return array Array representation of the XML for the given section
!      *
!      */
!     private function parseSection($section)
!     {
!         $xpath = new DOMXPath($this->dom);
!         $tagList = $xpath->query("/MVC_CONFIGURATION/$section");
!         $tagArray = array();
!         foreach ($tagList as $curTag) {
!             $tagID = $curTag->getAttribute('ID');
!             $tagName = $curTag->getAttribute('NAME');
!             $tagDefault = $curTag->getAttribute('DEFAULT');
!             $queryStr = sprintf("/MVC_CONFIGURATION/%s[@ID='%s']/FORWARD", $section, $tagID);
!             $forwardList = $xpath->query($queryStr);
!             $forwardArray = array();
!             foreach ($forwardList as $curForward) {
!                 $forwardID = $curForward->getAttribute('ID');
!                 $forwardType = $curForward->getAttribute('TYPE');
!                 $forwardTarget = $curForward->textContent;
!                 $forwardArray[$forwardID] = array('target'=>$forwardTarget,'type'=>$forwardType);
!             }
!             if (strtolower($tagDefault) == 'true') {
!                 if (count($forwardArray) > 0) {
!                     $tagArray[$tagID] = array('name'=>$tagName, 'forwards'=>$forwardArray, 'default'=>1);
!                 } else {
!                     $tagArray[$tagID] = array('name'=>$tagName, 'default'=>1);
!                 }
!             } else {
!                 if (count($forwardArray) > 0) {
!                     $tagArray[$tagID] = array('name'=>$tagName, 'forwards'=>$forwardArray);
!                 } else {
!                     $tagArray[$tagID] = array('name'=>$tagName);
!                 }
              }
          }
!         return $tagArray;
!     }
!     
!     /**
!      * Gets the array representation of MVC XML configuration
!      *
!      * @author Tony Bibbs <tony at geeklog.net>
!      * @access pubic
!      * @return array Array representation of MVC configuration
!      *
!      */
!     public function getArrayData()
!     {
!         return $this->arrayData;
!     }
  }
  


Index: LoaderFactory.php
===================================================================
RCS file: /var/cvs/MVCnPHP/LoaderFactory.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** LoaderFactory.php	14 Dec 2004 20:53:36 -0000	1.1.1.1
--- LoaderFactory.php	2 Mar 2005 19:55:49 -0000	1.2
***************
*** 13,17 ****
  *
  * @author Tony Bibbs <tony at geeklog.net>
! * @copyright Tony Bibbs 2003
  * @package net.geeklog.mvc
  * @version $Id$
--- 13,17 ----
  *
  * @author Tony Bibbs <tony at geeklog.net>
! * @copyright Tony Bibbs 2003-2005
  * @package net.geeklog.mvc
  * @version $Id$


Index: Controller.php
===================================================================
RCS file: /var/cvs/MVCnPHP/Controller.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Controller.php	14 Dec 2004 20:53:36 -0000	1.1.1.1
--- Controller.php	2 Mar 2005 19:55:49 -0000	1.2
***************
*** 391,395 ****
          if (empty($this->mapLoader)) {
              $this->mapLoader = &MVCnPHP_LoaderFactory::getLoader($configType);
-             
          }
          $this->mapping = $this->mapLoader->getMapping($this->object, $this->viewDir, $this->commandDir, $this->baseURL, $configData);
--- 391,394 ----
***************
*** 404,407 ****
--- 403,409 ----
              $this->mapping = &$this->mapLoader->getMapping($this->object, $this->viewDir, $this->commandDir, $this->baseURL, $configData);
          }
+         if (is_null($this->mapping)) {
+             throw new Exception('Unabled to load a mapping in MVCnPHP_Controller::loadMapping');
+         }
      }
      


--- XMLParser.php DELETED ---





More information about the geeklog-cvs mailing list