【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了Front.php提供大家参考,希望对大家有所帮助!
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE, and
* is available through the world-wide-web at the following URL:
* http://www.zend.com/license/framework/1_0.txt. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-
web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @package Zend_Controller
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
/** Zend_Controller_Dispatcher_Interface */
require_once 'Zend/Controller/Dispatcher/Interface.php';
/** Zend_Controller_Router_Interface */
require_once 'Zend/Controller/Router/Interface.php';
/** Zend_Controller_Plugin_Broker */
require_once 'Zend/Controller/Plugin/Broker.php';
/**
* @package Zend_Controller
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
class Zend_Controller_Front
{
/**
* Instance of Zend_Controller_Front
* @var Zend_Controller_Front
*/
static private $_instance = null;
/**
* Instance of Zend_Controller_RouterInterface
* @var Zend_Controller_RouterInterface
*/
private $_router = null;
/**
* Instance of Zend_Controller_DispatcherInterface
* @var Zend_Controller_DispatcherInterface
*/
private $_dispatcher = null;
/**
* Instance of Zend_Controller_Plugin_Broker
* @var Zend_Controller_Plugin_Broker
*/
private $_plugins = null;
/**
* Singleton pattern
*
* Instantiate the plugin broker.
*/
private function __construct()
{
$this->_plugins = new Zend_Controller_Plugin_Broker();
}
/**
* Singleton pattern
*/
private function __clone()
{}
/**
* Return one and only one instance of the Zend_Controller_Front object
*
* @return Zend_Controller_Front
*/
static public function getInstance()
{
if (!self::$_instance instanceof self) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Convenience feature, calls getInstance()->setControllerDirectory()->dispatch()
*
* @param string $controllerDirectory
*/
static public function run($controllerDirectory)
{
self::getInstance()
->setControllerDirectory($controllerDirectory)
->dispatch();
}
/**
* Convenience method, passthru to Zend_Controller_Dispatcher::setControllerDirectory()
*
* @param string $directory
*/
public function setControllerDirectory($directory)
{
$dispatcher = $this->getDispatcher();
if (!method_exists($dispatcher, 'setControllerDirectory')) {
throw new Zend_Controller_Front_Exception('Custom dispatcher does not support setting controller directory.');
}
$dispatcher->setControllerDirectory($directory);
return $this;
}
/**
* Set the router object. The router is responsible for mapping
* the request to a Zend_Controller_Dispatcher_Token object for dispatch.
*
* @param Zend_Controller_RouterInterface $router
*/
public function setRouter(Zend_Controller_Router_Interface $router)
{
$this->_router = $router;
}
/**
* Return the router object.
*
* @return Zend_Controller_RouterInterface
*/
public function getRouter()
{
/**
* Instantiate the default router if one was not set.
*/
if (!$this->_router instanceof Zend_Controller_Router_Interface) {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Router.php';
$this->_router = new Zend_Controller_Router();
}
return $this->_router;
}
/**
* Set the dispatcher object. The dispatcher is responsible for
* taking a Zend_Controller_Dispatcher_Token object, instantiating the controller, and
* call the action method of the controller.
*
* @param Zend_Controller_DispatcherInterface $dispatcher
* @return Zend_Controller_Front
*/
public function setDispatcher(Zend_Controller_Dispatcher_Interface $dispatcher)
{
$this->_dispatcher = $dispatcher;
return $this;
}
/**
* Return the dispatcher object.
*
* @return Zend_Controller_DispatcherInteface
*/
public function getDispatcher()
{
/**
* Instantiate the default dispatcher if one was not set.
*/
if (!$this->_dispatcher instanceof Zend_Controller_