[geeklog-cvs] geeklog-2/lib/MVCnPHP ArrayLoader.class.php,NONE,1.1 BaseCommand.class.php,NONE,1.1 BaseLoader.class.php,NONE,1.1 BaseView.class.php,NONE,1.1 CHANGELOG,NONE,1.1 CommandFactory.class.php,NONE,1.1 Constants.php,NONE,1.1 Controller.class.php,NONE,1.1 Form.class.php,NONE,1.1 LoaderFactory.class.php,NONE,1.1 MVC_Base.class.php,NONE,1.1 MVC_XMLParser.class.php,NONE,1.1 Mapping.class.php,NONE,1.1 QF_View.class.php,NONE,1.1 README.txt,NONE,1.1 Validator.class.php,NONE,1.1 ViewFactory.class.php,NONE,1.1 XMLLoader.class.php,NONE,1.1

geeklog-cvs-admin at lists.geeklog.net geeklog-cvs-admin at lists.geeklog.net
Thu May 15 15:10:23 EDT 2003


Update of /usr/cvs/geeklog/geeklog-2/lib/MVCnPHP
In directory internal.geeklog.net:/tmp/cvs-serv8975

Added Files:
	ArrayLoader.class.php BaseCommand.class.php 
	BaseLoader.class.php BaseView.class.php CHANGELOG 
	CommandFactory.class.php Constants.php Controller.class.php 
	Form.class.php LoaderFactory.class.php MVC_Base.class.php 
	MVC_XMLParser.class.php Mapping.class.php QF_View.class.php 
	README.txt Validator.class.php ViewFactory.class.php 
	XMLLoader.class.php 
Log Message:
Initial import of MVCnPHP into Geeklog 2


--- NEW FILE: ArrayLoader.class.php ---
<?php

/**
 * MVCnPHP - ArrayLoader.class.php
 *
 * This source file is subject to version 2.02 of the PHP license,
 * that is bundled with this package in the file LICENSE, and is
 * available at through the world-wide-web at
 * http://www.php.net/license/2_02.txt.
 * If you did not receive a copy of the PHP license and are unable to
 * obtain it through the world-wide-web, please send a note to
 * license at php.net so we can mail you a copy immediately.
 *
 * @author Tony Bibbs <tony at geeklog.net>
 * @copyright Tony Bibbs 2003
 * @package net.geeklog.mvc
 * @version $Id: ArrayLoader.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
 *
 */

/**
* Base Loader class which does most of the work
*/
require_once 'BaseLoader.class.php';

/**
* This loader creates a mapping from an PHP array
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
* @see LoaderFactory
*
*/
class ArrayLoader extends BaseLoader {
    /**
    * @access private
    * @var array
    */
    var $_arrayData = null;
    
    /**
    * Gets config data for given object in the form of
    * a mapping object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $name Name of object to get mapping for
    * @param string $viewsDir Directory where controllers views are stored
    * @param string $commandsDir DIrectory where controllers commands are stored
    * @param string $baseURL Base URL, all redirects are relative to this URL
    * @param array $arrayData Array of configuration data
    * @return object Mapping object
    *
    */
    function &getMapping($name, $viewsDir, $commandsDir, $baseURL, $arrayData = '')
    {
        if (!is_array($arrayData) AND !is_array($this->_arrayData)) {
            return false;
        }
        
        if (empty($this->_arrayData)) {
            $this->_arrayData = $arrayData;
        }
        return parent::getMapping($name, $viewsDir, $commandsDir, $baseURL, $this->_arrayData);
    }
}

?>
--- NEW FILE: BaseCommand.class.php ---
<?php

/**
* MVCnPHP - BaseCommand.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: BaseCommand.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Abstract class to be extended by all commands
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class BaseCommand extends MVC_Base {
    /**
    * Constructor
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function BaseCommand()
    {
    }
    
    /**
    * Executes this command
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Name of forward to send processing to
    *
    */
    function execute()
    {
    }
}

?>
--- NEW FILE: BaseLoader.class.php ---
<?php

/**
* MVCnPHP - BaseLoader.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: BaseLoader.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Mapping class which holds all data mapped to a given
* model or view
*/
require_once 'Mapping.class.php';

/**
* This is an abstract loader class which provides
* 90% of all functionality to the various loaders since
* we assume all config data will eventually be turned into
* a PHP array
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class BaseLoader {
    /**
    * Constructor
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function BaseLoader()
    {
    }
    
    /**
    * Gets config data for given object in the form of
    * a mapping object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $name Name of object to get mapping for
    * @param array $arrayData Array of configuration data
    * @return object Mapping object
    *
    */
    function &getMapping($name, $viewsDir, $commandsDir, $baseURL, $arrayData = '')
    {
        $mapping = new Mapping();
        if ($name == 'default') {
            $name = $this->_getDefaultMapping();
        }
        if (!empty($this->_arrayData[MVC_VIEWS][$name])) {
            $mapping->setName($this->_arrayData[MVC_VIEWS][$name][MVC_NAME]);
            $mapping->setType('view');
            $mapping->setTypePath($viewsDir);
        } else {
            $mapping->setName($this->_arrayData[MVC_MODELS][$name][MVC_NAME]);
            $mapping->setType('command');
            $mapping->setTypePath($commandsDir);
        }
        $mapping->setBaseURL($baseURL);
        $mapping->setForwards($this->_getForwards($name));
        
        return $mapping;
    }
    
    /**
    * If no object was specified in the request, this will return
    * the default mapping if one was specified in the configuration
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @return array Mapping data for given model or view
    *
    */
    function _getDefaultMapping()
    {
        foreach ($this->_arrayData[MVC_VIEWS] as $curView) {
            $curView = current($this->_arrayData[MVC_VIEWS]);
            if ($curView[MVC_DEFAULT] == true) {
                return key($this->_arrayData[MVC_VIEWS]);
            }
            next($this->_arrayData[MVC_VIEWS]);
        }
    }
    
    /**
    * Gets all forwards for a given object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param string $name Name of model to get forwards for
    * @return array Forwards for given model
    *
    */
    function _getForwards($name)
    {
        return $this->_arrayData[MVC_MODELS][$name][MVC_FORWARDS];
    }
    
}
--- NEW FILE: BaseView.class.php ---
<?php

/**
* MVCnPHP - BaseView.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: BaseView.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Abstract class to be extended by all views
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class BaseView extends MVC_Base {
    /**
    * @access private
    * @var int
    */
    var $_outputMethod = MVC_PRINT;
    
    /**
    * Returns if view should be printed
    *
    * View can be printed using echo or returned as a string.
    * This method is a tool used by the controller to determine
    * if it needs to return a string or not
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return boolean True if view is printed, otherwise false
    *
    */
    function printView()
    {
        if ($this->_outputMethod == MVC_PRINT) {
            return true;
        } else {
            return false;
        }
    }
    
    /**
    * Sets views output method
    *
    * View can either be printed immediately using PHP's
    * echo command or the view can be returned as a string
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param int $method One of two constanst, _PRINT or _STRING
    *
    */
    function setOutputMethod($method)
    {
        if ($method == MVC_PRINT) {
            $this->_outputMethod = MVC_PRINT;
        } else {
            $this->_outputMethod = MVC_STRING;
        }
    }
    
    /**
    * Renders a view in either printed HTML or
    * as an HTML string back to caller
    *
    * @author Tony Bibbs <tony AT geeklog DOT>
    * @access public
    * @return string OPTIONAL: not always returned
    *
    */
    function getView()
    {
    }
}

?>
--- NEW FILE: CHANGELOG ---
$Id: CHANGELOG,v 1.1 2003/05/15 19:10:20 tony Exp $

MVCnPHP Change Log
-------------------

- Added QF_View.class.php which adds support for PEAR::HTML_QuickForm.  This class is a unique child of
  the view.  MVCnPHP typically separates validation logic into a command whereas HTML_QuickForm couples
  both tasks.  This class allows you to do both but, then, requires you to put all your views and
  commands in the same directory. (08 April 2003)
- Fixed bug with QuickForm example that was caused because the Controller::ProcessRequest() method expects
  all commands. (02 May 2003)
--- NEW FILE: CommandFactory.class.php ---
<?php

/**
* MVCnPHP - CommandFactory.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: CommandFactory.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* This implements the factory design pattern and is
* responsible for building command objects
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class CommandFactory {
    /**
    * Builds the requested command object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $path Path to directory holding commands
    * @param string $name Name of command to create
    * @return object Command object
    *
    */
    function &getCommand($path, $name)
    {
        if (empty($name)) {
            trigger_error('No command name specified in CommandFactory::getCommand');
            exit;
        }
        $filename = $path . $name . '.class.php';
        if (file_exists($filename)) {
            require_once($filename);
            return new $name();
        } else {
            trigger_error('Bad set of parameters to CommandFactory::getCommand');
            exit;
        }
    }
}

?>
--- NEW FILE: Constants.php ---
<?php

/**
* MVCnPHP - Constants.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: Constants.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

// MVC configuration types
define('MVC_XML', 'XMLLoader');
define('MVC_ARRAY', 'ArrayLoader');

// FORM attributes
define('MVC_POST', 1);
define('MVC_GET', 2);
define('MVC_BOTH', 0);

// Security constants
define('MVC_TRUSTED', 1);
define('MVC_UNTRUSTED', 0);

// General configuration settings
define('MVC_BASE_URL', 'baseurl');
define('MVC_BASE', 'dirbase');
define('MVC_DIRS', 'dirs');

// Mapping constants
define('MVC_VIEWS', 'views');
define('MVC_MODELS', 'models');
define('MVC_FORWARDS', 'forwards');
define('MVC_NAME', 'name');
define('MVC_SECURE', 'secure');
define('MVC_DEFAULT', 'default');
define('MVC_TARGET', 'target');
define('MVC_TYPE', 'type');
define('MVC_MESSAGE', 'mvc_message');
define('MVC_ERRORS', 'mvc_errors');
define('MVC_PRINT', 1);
define('MVC_STRING', 2);

?>
--- NEW FILE: Controller.class.php ---
<?php

/**
* MVCnPHP - Controller.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: Controller.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* MVCnPHP constants
*/
require_once 'Constants.php';

/**
* Base object for models, views and controllers
*/
require_once 'MVC_Base.class.php';

/**
* Loader factory will create a configuration loader.
* Right now we only support PHP arrays and XML files
*/
require_once 'LoaderFactory.class.php';

/**
* Constants used within this MVC framework
*/
require_once 'Constants.php';

/**
* The controller part of the MVC
*
* This class controls processing for the program
* indiscriminately.  The focus is always on the underlying
* views or commands.  This class allows you to store application
* messages such as status messages (e.g. something was saved
* successfully) or error messages from failed validation or
* security reasons.  By default these are stored in the $_SESSION
* superglobal in $_SESSION['MVC_MESSAGE'] and $_SESSION['MVC_ERRORS']
* respectively (note: the later is an array).  If your application is
* not using PHP4 sessions you will want to follow the directions given
* in the documentation for Controller::_clearMessages
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class Controller extends MVC_Base {

    /**
    * @access private
    * @var int
    */
    var $_allowedFormMethod = null;
    
    /**
    * @access private
    * @var array
    */
    var $_request = null;
    
    /**
    * @access private
    * @var string
    */
    var $_object = null;
    
    /**
    * @access private
    * @var object
    */
    var $_mapLoader = null;
    
    /**
    * @access private
    * @var object
    */
    var $_mapping = null;
    
    /**
    * @access private
    * @var string
    */
    var $_mvcBase = null;
    
    /**
    * @access private
    * @var string
    */
    var $_viewDir = null;
    
    /**
    * @access private
    * @var string
    */
    var $_commandDir = null;
    
    /**
    * @access private
    * @var string
    */
    var $_baseURL = null;
    
    /**
    * @access private
    * @var int
    */
    var $_configType = null;
    
    /**
    * @access private
    * @var array
    */
    var $_configData = null;
    
    /**
    * Constructor
    *
    * Loads MVC configuration data and sets up data needed for
    * further processing
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param variant $configData Configuration data
    * @param string $configType Denotes type of config data structure, MVC_ARRAY or MVC_XML
    * @param string $allowedFormMethod Controller can accept MVC_GET, MVC_POST or MVC_BOTH
    *
    */
    function Controller($configData, $configType = MVC_XML, $allowedFormMethod = MVC_BOTH)
    {
        $this->_clearMessages();
        
        switch ($allowedFormMethod) {
            case MVC_GET:
                $this->_request = &$_GET;
                break;
            case MVC_POST:
                $this->_request = &$_POST;
                break;
            default:
                $this->_request = &$_REQUEST;
        }
        if (!empty($this->_request['cmd'])) {
            $this->_object = $this->_request['cmd'];
        } else {
            $this->_object = 'default';
        }
        $this->_configType = $configType;
        $this->_configData = $configData;
        $this->_allowedFormMethod = $allowedFormMethod;
    }
    
    /**
    * Sets location of the base MVC package so other MVC classes can be
    * loaded at a later time.
    *
    * @author Tony Bibbs
    * @access public
    * @param string $path Path to MVC base dir, must end with trailing slash
    * @return boolean True if view path is set, otherwise false
    *
    */
    function setMVCBase($path)
    {
        if (!is_dir($path)) {
            trigger_error('bad path in Controller::setMVCBase');
            exit;
        }
        $this->_mvcBase = $path;
        return true;
    }
    
    /**
    * Sets location of views for this controller
    *
    * @author Tony Bibbs
    * @access public
    * @param string $path Path to view dir, must end with trailing slash
    * @return boolean True if view path is set, otherwise false
    *
    */
    function setViewDir($path)
    {
        if (!is_dir($path)) {
            return false;
        }
        $this->_viewDir = $path;
        return true;
    }
    
    /**
    * Sets location of commands for this controller
    *
    * @author Tony Bibbs
    * @access public
    * @param string $path Path to command dir, must end with trailing slash
    * @return boolean True if view path is set, otherwise false
    *
    */
    function setCommandDir($path)
    {
        if (!is_dir($path)) {
            return false;
        }
        $this->_commandDir = $path;
        return true;
    }
    
    /**
    * Sets base URL for this controller
    *
    * The base url allows all subsequent references to URL's to be relative
    * to the URL specified here
    *
    * @author Tony Bibbs
    * @access public
    * @param string $url Base URL
    *
    */
    function setBaseURL($url)
    {
        $this->_baseURL = $url;
    }
    
    /**
    * Process a request (or forward)
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Optional, may return HTML string of view
    *
    */
    function processRequest()
    {
        // Ensure user isn't submitted data via an illegal method
        $this->_checkMethod();
        
        if (empty($this->_mapping)) {
            $this->_loadMapping($this->_configType, $this->_configData);
        }
        if ($this->_mapping->getType() == 'view') {
            require_once 'ViewFactory.class.php';
            $view = &ViewFactory::getView($this->_mapping->getPath(), $this->_mapping->getName());
            $retval = $view->getView();
            if ($this->_isForward($retval)) {
                $this->_forwardControl($retval);
            }
            if (!$view->printView()) {
                return $retval;
            }
        } else {
            require_once 'CommandFactory.class.php';
            $tmp = &CommandFactory::getCommand($this->_mapping->getPath(), $this->_mapping->getName());
            $strForward = $tmp->execute();
            // This IF is required to avoid errors using quickform
            if ($this->_isForward($strForward)) {
                $this->_forwardControl($strForward);
            }
        }
    }
  
    /**
    * Clears any existing errors or messages
    *
    * This method assumes the application is using PHP4 sessions
    * to store MVC errors and messages.  If that is not the case,
    * the application should create a new class that extends this
    * controller and override this function to clear the messages
    * in the way desired.
    *
    * @author Tony Bibs <tony at geeklog.net>
    * @access private
    *
    */
    function _clearMessages()
    {
        unset($_SESSION[MVC_MESSAGE]);
        unset($_SESSION[MVC_ERRORS]);
    }
    
    /**
    * Ensures only supported methods are used
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    *
    */
    function _checkMethod()
    {
        $errors = Array();
        switch ($this->_allowedFormMethod) {
            case MVC_GET:
                if (count($_POST) > 0) {
                    trigger_error('POST method is not supported by this controller');
                    exit;
                }
            case MVC_POST:
                if (count($_GET) > 0) {
                    trigger_error('GET method is not supported by this controller');
                    exit;
                }
        }
    }
    
    /**
    * Loads the mapping data for a model or view
    *
    * This will load only the mapping data needed by the
    * current object.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param string $configType Dontes the type of config data structure
    * @param variant $configData this is the data or file pointer for config data
    *
    */
    function _loadMapping($configType, $configData)
    {
        if (empty($this->_mvcBase)) {
            trigger_error('_mvcBase for Controller is empty in Controller::_loadMapping');
            exit;
        }
        if (empty($this->_mapLoader)) {
            $this->_mapLoader = &LoaderFactory::getLoader($this->_mvcBase, $configType);
        }
        $this->_mapping = &$this->_mapLoader->getMapping($this->_object, $this->_viewDir, $this->_commandDir, $this->_baseURL, $this->_configData);
    }
    
    /**
    * Determines if string is a name of an existing forward.
    *
    * Because views can return the HTML string it won't be obvious
    * if the call to the view's getView() is a forward or actually
    * HTML.  This function makes that determintation.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param string $name Name of forward to look for
    * @return boolean True if forward is found, otherwise false
    *
    */
    function _isForward($name)
    {
        if ($this->_mapping->getForward($name)) {
            return true;
        } else {
            return false;
        }
    }
    
    /**
    * Forwards control onto another command or view
    *
    * A model will typically try to forward control to a view
    * (less likely, but possible, another command) after processing.
    * This object handles that forwarding and can even handle forwarding
    * to a different URL if configured to do so.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param string $name Name of next model or view to go to
    *
    */
    function _forwardControl($name)
    {
        $forward = $this->_mapping->getForward($name);
        if ($forward[MVC_TYPE] == 'redirect') {
            $url = $this->_mapping->getBaseURL() . $forward[MVC_TARGET];
            header('Location: ' . $url);
        } else {
            $this->_object = $forward[MVC_TARGET];
            $this->_mapping = &$this->_mapLoader->getMapping($this->_object, $this->_viewDir, $this->_commandDir, $this->_baseURL);
            $this->processRequest();
        }
    }
    
}

?>
--- NEW FILE: Form.class.php ---
<?php

/**
* MVCnPHP - Form.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: Form.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* This is a basic form class that can aid in form validation and
* manipulation.
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class Form {
    /**
    * @access private
    * @var array
    */
    var $_values = null;
    
    /**
    * Constructor
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param array $formArray Array of form fieds (typical $_GET, $_POST or $_REQUEST)
    *
    */
    function Form($formArray)
    {
        $this->_values = $formArray;
    }
    
    /**
    * Returns if the given variable name exists in form
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable
    * @return boolean True if found, otherwise false
    *
    */
    function contains($varName)
    {
        return isset($this->_values[$varName]);
    }
    
    /**
    * Gets value for given variable name
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable to get value for
    * @return variant Value of form variable
    *
    */    
    function get($varName)
    {
        if (!$this->contains($varName)) {
            return null;
        }
        return $this->_values[$varName];
    } 
    
    /**
    * Deletes a form variable
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable to delete
    *
    */
    function remove($varName)
    {
        if ($this->contains($varName)) {
            unset($this->_values[$varName]);
        }
    }
    
    /**
    * Sets a field to given value
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of field to set
    * @param string $value Value to set field to
    *
    */
    function set($varName, $value)
    {
        $this->_values[$varName] = $value;
    }
    
    /**
    * Returns value array
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return array Values array
    *
    */
    function &getValues()
    {
        return $this->_values;
    }
}

?>
--- NEW FILE: LoaderFactory.class.php ---
<?php

/**
* MVCnPHP - LoaderFactory.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: LoaderFactory.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Builds MVC Config Loaders
*
* I doubt much more besides arrays and XML files
* will be used but just in case I used the factory
* pattern in here to enable easily adding new configuration
* data structures
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class LoaderFactory {
    /**
    * Builds requested MVC configuration loaders.
    *
    * Config loaders each represent one way of parsing
    * an MVC configuration data structure into the objects
    * needed by the controller.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $path Path to base MVC directory
    * @param int $configType Constant, either MVC_XML or MVC_ARRAY
    * @return object MVC config loader
    *
    */
    function &getLoader($path, $configType = MVC_XML)
    {
        if (empty($path)) {
            echo 'no MVC base dir specified in LoaderFactory::getLoader';
            exit;
        }
        $filename = $path . $configType . '.class.php';
        if (file_exists($filename)) {
            require_once $filename;
            return new $configType();
        } else {
            return;
        }
    }
}

?>
--- NEW FILE: MVC_Base.class.php ---
<?php

/**
* MVCnPHP - MVC_Base.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: MVC_Base.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Abstract MVC Base class that provides one place
* to add things like security to MVC objects if you
* so choose.  
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class MVC_Base {
    /**
    * Constructor
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function MVC_Base()
    {
    }
}

?>
--- NEW FILE: MVC_XMLParser.class.php ---
<?php

/**
* MVCnPHP - MVC_XMLParser.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: MVC_XMLParser.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* This class parses MVC configuration files
*
* NOTE: for you Java/Struts lovers out there, this is in now
* way deemed consistent with their implementation.
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class MVC_XMLParser {
    /**
    * @access private
    * @var array
    */
    var $_elements = null;
    
    /**
    * @access private
    * @var array
    */
    var $_attributes = null;
    
    /**
    * @access private
    * @var array
    */
    var $_values = null;
    
    /**
    * @access private
    * @var int
    */
    var $_curElement = null;
    
    /**
    * @access private
    * @var int
    */
    var $_level = 0;
    
    /**
    * 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
    *
    */
    function MVC_XMLParser($xmlString = '')
    {
        $this->_elements = Array();
        $this->_attributes = Array();
        $this->_values = Array();
        if (!empty($xmlString)) {
            $this->parseXML($xmlString);
        }
    }
    
    /**
    * Parses the given MVC XML file
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $xmlString XML to parse
    *
    */
    function parseXML($xmlString)
    {
        // Create Expat parser object
        $this->_parser = xml_parser_create();
        
        // Lets expat know this class will handle the parsing
        xml_set_object($this->_parser, &$this);
        xml_set_element_handler($this->_parser, '_handleStartElement', '_handleEndElement');
        xml_set_character_data_handler($this->_parser, '_handleData');
        
        // Actually parse the XML now.
        if (!xml_parse($this->_parser, $xmlString)) {
            trigger_error(sprintf("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($this->_parser)),
                xml_get_current_line_number($this->_parser)));
            exit;
        }
        xml_parser_free($this->_parser);
    }
    
    /**
    * Called by expat functions to handle a start tag in XML stream
    *
    * This grabs a reference to the parent tag and any pertinent data
    * such as the tag name and any associate XML attributes
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param object $parser Reference to Expat parser object
    * @param string $name Name of XML tag that was encountered
    * @param array $attributes Any associated XML attributes
    *
    */
    function _handleStartElement($parser, $name, $attributes)
    {
        // This tidbit of code grabs the index into _elements for
        // the parent and sets that as an attribute
        if ($this->_level > 1) {
            $attributes['PARENT'] = $this->_curElement;
        } else {
            $attributes['PARENT'] = $this->_level;
        }
        $this->_level++;
        $this->_elements[] = $name;
        $this->_curElement = count($this->_elements) - 1;
        $this->_attributes[$this->_curElement] = $attributes;
        
    }
    
    /**
    * Called by expat functions to handle an end tag in XML stream
    *
    * This adjusts some pointers that allow us to get handles to parent
    * XML tags
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * 
    */
    function _handleEndElement()
    {
        $this->_level--;
        $this->_curElement--;
    }
    
    /**
    * Called by expat functions to handle the data taken
    * from XML stream
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    * @param object $parser Expat parser object
    * @param string $data Data to handle
    *
    */
    function _handleData($parser, $data)
    {
        // NOTE: the use of trim() here is necessary as
        // empty() will not produce desired results
        if (empty($this->_curElement) OR !trim($data)) return;
        $this->_values[$this->_curElement] = $data;
    }
    
    /**
    * Gets the XML tag represented by given index
    *
    * @author TonyBibbs <tony at geeklog.net>
    * @access public
    * @return string XML Tag name
    *
    */
    function getTag($index)
    {
        return $this->_elements[$index];
    }
    
    /**
    * Gets all indexes for _elements array
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return array Keys for _elements array
    *
    */
    function getElementIndexes()
    {
        return array_keys($this->_elements);
    }
    
    /**
    * Gets an attribute for given index
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param int $index Index representing an XML tag in _elements array
    * @param string $attribute Name of attribute to get
    * @return string Requested attribute
    *
    */
    function getAttribute($index, $attribute)
    {
        return $this->_attributes[$index][strtoupper($attribute)];
    }
    
    /**
    * Returns value for given index
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param int $index Index into _elements array
    * @return string Value for given index
    *
    */
    function getValue($index)
    {
        return $this->_values[$index];
    }
}

?>
--- NEW FILE: Mapping.class.php ---
<?php

/**
* MVCnPHP - Mapping.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: Mapping.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* This is the mapping object.  This holds all pertinent mapping data for
* a specific model or view. NOTE: not all available mappings are loaded
* for each request, only those needed for the current request.
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class Mapping {
    /**
    * @access private
    * @var string
    */
    var $_name = null;
    
    /**
    * @access private
    * @var string
    */
    var $_type = null;
    
    /**
    * @access private
    * @var string
    */
    var $_typePath = null;
    
    /**
    * @access private
    * @var string
    */
    var $_forwards = null;
    
    /**
    * @access private
    * @var string
    */
    var $_baseURL = null;
    
    /**
    * Sets the base URL for any redirects
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $url Base url for all redirects
    *
    */
    function setBaseURL($url)
    {
        $this->_baseURL = $url;
    }
    
    /**
    * Gets the base URL for any redirects
    * Any forwards to other URL's must be relative to the
    * base URL provided
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Base url
    *
    */
    function getBaseURL()
    {
        return $this->_baseURL;
    }
    
    /**
    * Sets the name for the model or view this mapping
    * belongs to.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $name Name of model or view
    *
    */
    function setName($name)
    {
        $this->_name = $name;
    }
    
    /**
    * Gets the name for the model or view this mapping
    * belongs to.
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Name of the model or view
    *
    */
    function getName()
    {
        return $this->_name;
    }
    
    /**
    * Sets the type of object this mapping belongs to (model or view)
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $type Type of object (model or view)
    *
    */
    function setType($type)
    {
        $this->_type = $type;
    }
    
    /**
    * Gets the type of object this mapping belongs to (model or view)
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Type of object (model or view)
    *
    */
    function getType()
    {
        return $this->_type;
    }
    
    /**
    * Sets all forwards associated with this mapping.  Note
    * that you won't have forwards for any views
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param array $forwards Array of forwards tied to this object
    *
    */
    function setForwards($forwards)
    {
        $this->_forwards = $forwards;
    }
    
    /**
    * Retrieves the requested forward
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $name Name of forward to get
    * @return array|boolean The forward data or false if not found
    *
    */
    function getForward($name)
    {
        if (!empty($this->_forwards[$name])) {
            return $this->_forwards[$name];
        } else {
            return false;
        }
    }
    
    /**
    * Sets the path where the models or views can be found
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $path Absolute path ending with trailing slash
    *
    */
    function setTypePath($path)
    {
        $this->_typePath = $path;
    }

    /**
    * Gets the absolute path where the code for this model or view this
    * mapping belongs to can be found
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return string Path to model or view directory
    *
    */
    function getPath()
    {
        return $this->_typePath;
    }
}

?>
--- NEW FILE: QF_View.class.php ---
<?php

/**
* MVCnPHP - QF_View.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: QF_View.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Abstract view class
*/
require 'BaseView.class.php';

/**
* PEAR::HTML_QuickForm
*/
require 'HTML/QuickForm.php';

/**
* This view uses PEAR::HTML_QuickForm to show and validate
* HTML forms.
*
* NOTE: if you use this class you will need to set
* Controller::setViewDir() and Controller::setCommandDir()
* to the same directory lest you want to duplicate code. Also,
* it goes without saying you'll need to make sure you have installed
* PEAR::HTML_QuickForm prior to using this.
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class QF_View extends BaseView {
    /**
    * @access private
    * @var HTML_QuickForm
    */
    var $_QForm = null;
    
    /**
    * Constructor for QF_View class
    *
    * Instantiates an HTML_QuickForm object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function QF_View()
    {
        $this->_QForm = new HTML_QuickForm();
    }
    
    /**
    * This is a way to get around the fact you don't get to send arguments
    * to HTML_QuickForm's constructor.  You will probably call this from
    * getView()
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access private
    *
    */
    function _setQFormAttributes($formName='', $method='post', $action='')
    {
        $this->_QForm->HTML_QuickForm($formName, $method, $action);
    }
    
    /**
    * This method is where you would put the code to have HTML_QuickForm display
    * the form
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function getView()
    {
    }
    
    /**
    * This method fools MVC into thinking this view is also able to validate
    *
    * For PEAR::HTML_QuickForm, the display and valdation is tightly coupled so
    * both sets of code need to be put in the getView method.  This method simply
    * fools the controller into calling getView for validation.
    * 
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function execute()
    {
        $this->getView();
    }
}
--- NEW FILE: README.txt ---
$Id: README.txt,v 1.1 2003/05/15 19:10:20 tony Exp $

MVCnPHP README
--------------

Contents
--------

INTRODUCTION TO MVC
MVC FEATURES
MVC DRAWBACKS
ORGANIZATION OF MVCnPHP
INSTALLATION
    REQUIREMENTS
    INSTALLING THE CONTACT MANAGER EXAMPLE
    INSTALLING THE QUCKFORM EXAMPLE
    INSTALLING FOR GENERAL USE
TODO
KNOWN BUGS
SUPPORT
CREDITS

INTRODUCTION TO MVC
--------------------

MVCnPHP stands for the model-view-controller in PHP.

The model-view-controller design pattern is a popular pattern used primarily with
Java developers doing servlet programming.  PHP is maturing as a full-fledged, object
oriented, programming language and it can benefit by many of the software engineering
principles developed by more traditional OO languages.  The MVC design pattern takes
the common principle of separating business logic (models) from the user interfaces
(views) a step further by introducing the concept of a controller which is responsible
transferring execution to the models and views.  What you end up with is smaller, more
manageable code and, typically, more efficient use of server resources because with the 
MVC only the code needed to process a given request gets loaded.

This introduction doesn't begin adequately highlight all the benefits of the MVC design
pattern in PHP.  It is strongly recommended that you spend a little time on Google 
learning more about the MVC as well as many of the other design patterns out there.  With
that said, sometimes an example is better than words.  Within this package is included a
simplistic contact manager that uses most of the features of this MVC package.

NOTE: this is NOT an attempt to reimplement the MVC provided by Struts.  If
you are a Java purist and insist on a 100% Struts compatible version you may
feel welcome to rework what I have here OR check out the Phrame project at
http://phrame.itsd.ttu.edu/ 

MVC FEATURES
------------

Obviously using a framework package like MVCnPHP you would expect to see the benefits before
you invest.  Here is a run down of the benefits of implementing MVC in your applications:

- The MVC is a solution to the classic problem of separating the user interface, business
  logic and related data.
- Render views (user interfaces) via a variety of technologies like XHTML, XML/XSL, WML, 
  Web services, or any other 3rd party technology (e.g. PEAR::HTML_QuickForm).
- Have multiple views that rely upon a single model.  Thus your HTML and WML views can call
  on the same underlying business logic for processing.
- Ability to switch backend DBMS with little effort (e.g. MySQL -> PostgreSQL)
- Code ends up being in smaller, more manageable files.

MVC DRAWBACKS
--------------

In an effort to show two sides of the MVC fence here are a few drawbacks:

- MVC implementations time a fair amount of time to learn how to use them.
- Debugging between models and veiws can be more difficult
- Because MVC breaks tasks down to atomic parts, you end up with a lot of relatively small
  files you have to manage.
- Because of the associated ramp-up, MVC in smaller applications may not make much sense.

MVC RESOURCES
-------------

You are encouraged to learn as much about the MVC design pattern as possible.  Below are
a few sites related to the MVC pattern you may find useful.  Of course, spend time doing
a few Google searches if you desire more diverse information:

- http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
- http://phrame.itsd.ttu.edu/
- http://ootips.org/mvc-pattern.html
- http://www.phppatterns.com/index.php/article/articleview/19/1/1/
- http://www.google.com and http://groups.google.com for more information

ORGANIZATION OF MVCnPHP
-------------------------

MVCnPHP (holds base MVCnPHP code files)
    /contactmanager (folder for sample application)
        /commands (holds commands used in contact manager application)
        /views (holds views used in contact manager application)
    /quickform (folder for quick form example)
        /views (holds an example view that uses PEAR::HTML_QuickForm)
    /docs (phpDocumentor documentation)

INSTALLATION
-------------

REQUIREMENTS
-------------
1) PHP with PEAR::DB (Only needed if you want to run the contact manager 
   application)
2) MySQL 3.23.x or better (Only needed if you want to run the contact manager 
   application)
3) PEAR::HTML_QuickForm (Only needed if you require QuickForm integration

INSTALLING THE CONTACT MANAGER EXAMPLE
---------------------------------------

It is strongly recommended that you install the example before you begin using this MVC
package in any other programs.  Doing so will let you see this package in action.  You 
are encouraged to dig into the code and learn how this package works and how you might
leverage it to make your PHP applications better.

1) Uncompress the tarball *inside* your webtree
2) Create a new MySQL database name something logical like 'contactmanager'
3) import the mysql.sql file into your new database
3) Edit /path/to/MVC/contactmanager/config.php according to the comments
4) Point your browser to the location of the index.php page.

NOTE: this application is only a sample and is in no way meant for real world
use.  It is merely meant to show you that MVCnPHP works and give you a taste
at how you might you it in your PHP applications.

INSTALLING THE QUCKFORM EXAMPLE
-------------------------------

PEAR::HTML_QuickForm is a PEAR package that provides object oriented methods for creating
HTML forms and for doing data validation.  This example is provided to prove that MVCnPHP
can be easily extended to use other packages for the creation of views.  Furthermore, 
MVCnPHP includes QF_View.class.php as part of the base distribution so that you could begin
using HTML QuickForm right out-of-the-box.  

INSTALLATION FOR GENERAL USE
----------------------------

This installation procedure assumes you have already test drove the sample
contactmanager application and that you want to use this MVC framework in 
you PHP application.

1) Uncompress the tarball preferrably to a folder outside of your webtree but
   accessible to your web server.
2) It is likely you will have quite a few different controllers within your 
   application one for each functional area of your application.  Each 
   controller will require it's own configuration settings.
3) ...coming soon

TODO
----
1) Fill in holes in documentation
2) Remove dependence on $_SESSION superglobal since not all application may
   use it.

KNOWN BUGS
----------

There are currently no known bugs for MVCnPHP.  If you feel you have found a
bug please see the SUPPORT section.

SUPPORT
-------

This package is considered a release condidate and is unsupported.  Once it is deemed stable
we will release a supported package.  Until that time, send any bugs, comments or
questions to Tony Bibbs, tony at geeklog.net.

CREDITS
-------

This MVC framework was inspired by the great work done on the Phrame Project, 
http://phrame.itsd.ttu.edu/.  Many thanks is owed to Arnold Cano for managing that
project and a special shout-out to Jason Sweat who is a regular contributor to Phrame.

At the time of this writing no decision on the future of this project and Phrame has been
decided.  I am in constant communication with the Phrame developers hoping we can combine 
what I have built here into some of the Phrame principles that were omitted in this package. 
By doing so I hope to end up with *the* definitive PHP-MVC package and, at that time, we would
look at submitting this framework to PEAR.

--- NEW FILE: Validator.class.php ---
<?php

/**
* MVCnPHP - Validator.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: Validator.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* MVC base command object
*/
require_once dirname(__FILE__) . '/BaseCommand.class.php';

/**
* MVC form object
*/
require_once dirname(__FILE__) . '/Form.class.php';

/**
* This is a validator class meant to ease the tasks
* often done by validation logic
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class Validator extends BaseCommand {
    /**
    * @access private
    * @var object
    */
    var $_form = null;
    
    /**
    * Constructor
    *
    * Initializes form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    *
    */
    function Validator()
    {
        $this->_form = new Form($_REQUEST);
    }
    
    /**
    * Determines if the submitted form has a value for a given
    * variable name
    *
    * This is a simple pass thru to the form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable
    * @return boolean True if found, otherwise false
    *
    */
    function contains($varName)
    {
        return $this->_form->contains($varName);
    }
    
    /**
    * Gets value for given variable name
    *
    * This is a simple pass thru to the form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable to get value for
    * @return variant Value of form variable
    *
    */   
    function get($varName)
    {
        return $this->_form->get($varName);
    }
    
    /**
    * Deletes a form variable
    *
    * This is a simple pass thru to the form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of form variable to delete
    *
    */
    function remove($varName)
    {
        $this->_form->remove($varName);
    }
    
    /**
    * Sets a field to given value
    *
    * This is a simple pass thru to the form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $varName Name of field to set
    * @param string $value Value to set field to
    *
    */
    function set($varName, $value)
    {
        $this->_form->set($varName, $value);
    }
    
    /**
    * Returns value array
    *
    * This is a simple pass thru to the form object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @return array Values array
    *
    */
    function &getValues()
    {
        return $this->_form->getValues();
    }
}

?>
--- NEW FILE: ViewFactory.class.php ---
<?php

/**
* MVCnPHP - ViewFactory.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: ViewFactory.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* This implements the factory design pattern and is
* responsible for building view objects
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class ViewFactory {
    /**
    * Builds the requested view object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $path Path to directory holding views
    * @param string $name Name of view to create
    * @return object viewobject
    *
    */
    function &getView($path, $name)
    {
        $filename = $path . $name . '.class.php';
        if (file_exists($filename)) {
            require_once($filename);
            return new $name();
        } else {
            return;
        }
    }
}

?>
--- NEW FILE: XMLLoader.class.php ---
<?php

/**
* MVCnPHP - XMLLoader.class.php
*
* This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license at php.net so we can mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright Tony Bibbs 2003
* @package net.geeklog.mvc
* @version $Id: XMLLoader.class.php,v 1.1 2003/05/15 19:10:20 tony Exp $
*
*/

/**
* Base Loader class which does most of the work
*/
require_once 'BaseLoader.class.php';

/**
* MVC XML parser
*/
require_once 'MVC_XMLParser.class.php';

/**
* This loader creates a mapping from an XML file
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.mvc
*
*/
class XMLLoader extends BaseLoader {
    /**
    * @access private
    * @var array
    */
    var $_arrayData = null;
    
    /**
    * Gets config data for given object in the form of
    * a mapping object
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param string $name Name of object to get mapping for
    * @param array $arrayData Array of configuration data
    * @return object Mapping object
    *
    */
    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
    *
    */
    function _XMLToArray($xmlData)
    {
        $parser = new MVC_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 'MODEL':
                    $model = $parser->getAttribute($curIndex, 'id');
                    $default = $parser->getAttribute($curIndex, 'default');
                    $configData[MVC_MODELS][$model][MVC_NAME] = $parser->getAttribute($curIndex, 'name');
                    if ($default) {
                        $configData[MVC_MODELS][$model][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 == 'MODEL') {
                            $configData[MVC_MODELS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TARGET] = $parser->getValue($curIndex);
                            $configData[MVC_MODELS][$parentIDAttr][MVC_FORWARDS][$name][MVC_TYPE] = $parser->getAttribute($curIndex, 'type');
                        } else {
                            trigger_error('Hit unexpected XML tag in XMLLoader::_XMLToArray');
                            exit;
                        }    
                    }
                    break;
                default:
            }
        }
        return $configData;
    }    
}

?>




More information about the geeklog-cvs mailing list