CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
688
airtime_mvc/library/Zend/Controller/Action.php
Normal file
688
airtime_mvc/library/Zend/Controller/Action.php
Normal file
|
@ -0,0 +1,688 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Action.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_HelperBroker
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/HelperBroker.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Interface
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Front
|
||||
*/
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Action implements Zend_Controller_Action_Interface
|
||||
{
|
||||
/**
|
||||
* @var array of existing class methods
|
||||
*/
|
||||
protected $_classMethods;
|
||||
|
||||
/**
|
||||
* Word delimiters (used for normalizing view script paths)
|
||||
* @var array
|
||||
*/
|
||||
protected $_delimiters;
|
||||
|
||||
/**
|
||||
* Array of arguments provided to the constructor, minus the
|
||||
* {@link $_request Request object}.
|
||||
* @var array
|
||||
*/
|
||||
protected $_invokeArgs = array();
|
||||
|
||||
/**
|
||||
* Front controller instance
|
||||
* @var Zend_Controller_Front
|
||||
*/
|
||||
protected $_frontController;
|
||||
|
||||
/**
|
||||
* Zend_Controller_Request_Abstract object wrapping the request environment
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
protected $_request = null;
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_Abstract object wrapping the response
|
||||
* @var Zend_Controller_Response_Abstract
|
||||
*/
|
||||
protected $_response = null;
|
||||
|
||||
/**
|
||||
* View script suffix; defaults to 'phtml'
|
||||
* @see {render()}
|
||||
* @var string
|
||||
*/
|
||||
public $viewSuffix = 'phtml';
|
||||
|
||||
/**
|
||||
* View object
|
||||
* @var Zend_View_Interface
|
||||
*/
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* Helper Broker to assist in routing help requests to the proper object
|
||||
*
|
||||
* @var Zend_Controller_Action_HelperBroker
|
||||
*/
|
||||
protected $_helper = null;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* The request and response objects should be registered with the
|
||||
* controller, as should be any additional optional arguments; these will be
|
||||
* available via {@link getRequest()}, {@link getResponse()}, and
|
||||
* {@link getInvokeArgs()}, respectively.
|
||||
*
|
||||
* When overriding the constructor, please consider this usage as a best
|
||||
* practice and ensure that each is registered appropriately; the easiest
|
||||
* way to do so is to simply call parent::__construct($request, $response,
|
||||
* $invokeArgs).
|
||||
*
|
||||
* After the request, response, and invokeArgs are set, the
|
||||
* {@link $_helper helper broker} is initialized.
|
||||
*
|
||||
* Finally, {@link init()} is called as the final action of
|
||||
* instantiation, and may be safely overridden to perform initialization
|
||||
* tasks; as a general rule, override {@link init()} instead of the
|
||||
* constructor to customize an action controller's instantiation.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @param array $invokeArgs Any additional invocation arguments
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
|
||||
{
|
||||
$this->setRequest($request)
|
||||
->setResponse($response)
|
||||
->_setInvokeArgs($invokeArgs);
|
||||
$this->_helper = new Zend_Controller_Action_HelperBroker($this);
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize object
|
||||
*
|
||||
* Called from {@link __construct()} as final step of object instantiation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize View object
|
||||
*
|
||||
* Initializes {@link $view} if not otherwise a Zend_View_Interface.
|
||||
*
|
||||
* If {@link $view} is not otherwise set, instantiates a new Zend_View
|
||||
* object, using the 'views' subdirectory at the same level as the
|
||||
* controller directory for the current module as the base directory.
|
||||
* It uses this to set the following:
|
||||
* - script path = views/scripts/
|
||||
* - helper path = views/helpers/
|
||||
* - filter path = views/filters/
|
||||
*
|
||||
* @return Zend_View_Interface
|
||||
* @throws Zend_Controller_Exception if base view directory does not exist
|
||||
*/
|
||||
public function initView()
|
||||
{
|
||||
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
require_once 'Zend/View/Interface.php';
|
||||
if (isset($this->view) && ($this->view instanceof Zend_View_Interface)) {
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
$module = $request->getModuleName();
|
||||
$dirs = $this->getFrontController()->getControllerDirectory();
|
||||
if (empty($module) || !isset($dirs[$module])) {
|
||||
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
|
||||
}
|
||||
$baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views';
|
||||
if (!file_exists($baseDir) || !is_dir($baseDir)) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Missing base view directory ("' . $baseDir . '")');
|
||||
}
|
||||
|
||||
require_once 'Zend/View.php';
|
||||
$this->view = new Zend_View(array('basePath' => $baseDir));
|
||||
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a view
|
||||
*
|
||||
* Renders a view. By default, views are found in the view script path as
|
||||
* <controller>/<action>.phtml. You may change the script suffix by
|
||||
* resetting {@link $viewSuffix}. You may omit the controller directory
|
||||
* prefix by specifying boolean true for $noController.
|
||||
*
|
||||
* By default, the rendered contents are appended to the response. You may
|
||||
* specify the named body content segment to set by specifying a $name.
|
||||
*
|
||||
* @see Zend_Controller_Response_Abstract::appendBody()
|
||||
* @param string|null $action Defaults to action registered in request object
|
||||
* @param string|null $name Response object named path segment to use; defaults to null
|
||||
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
|
||||
* @return void
|
||||
*/
|
||||
public function render($action = null, $name = null, $noController = false)
|
||||
{
|
||||
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
|
||||
return $this->_helper->viewRenderer->render($action, $name, $noController);
|
||||
}
|
||||
|
||||
$view = $this->initView();
|
||||
$script = $this->getViewScript($action, $noController);
|
||||
|
||||
$this->getResponse()->appendBody(
|
||||
$view->render($script),
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a given view script
|
||||
*
|
||||
* Similar to {@link render()}, this method renders a view script. Unlike render(),
|
||||
* however, it does not autodetermine the view script via {@link getViewScript()},
|
||||
* but instead renders the script passed to it. Use this if you know the
|
||||
* exact view script name and path you wish to use, or if using paths that do not
|
||||
* conform to the spec defined with getViewScript().
|
||||
*
|
||||
* By default, the rendered contents are appended to the response. You may
|
||||
* specify the named body content segment to set by specifying a $name.
|
||||
*
|
||||
* @param string $script
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function renderScript($script, $name = null)
|
||||
{
|
||||
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
|
||||
return $this->_helper->viewRenderer->renderScript($script, $name);
|
||||
}
|
||||
|
||||
$view = $this->initView();
|
||||
$this->getResponse()->appendBody(
|
||||
$view->render($script),
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct view script path
|
||||
*
|
||||
* Used by render() to determine the path to the view script.
|
||||
*
|
||||
* @param string $action Defaults to action registered in request object
|
||||
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
|
||||
* @return string
|
||||
* @throws Zend_Controller_Exception with bad $action
|
||||
*/
|
||||
public function getViewScript($action = null, $noController = null)
|
||||
{
|
||||
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
|
||||
$viewRenderer = $this->_helper->getHelper('viewRenderer');
|
||||
if (null !== $noController) {
|
||||
$viewRenderer->setNoController($noController);
|
||||
}
|
||||
return $viewRenderer->getViewScript($action);
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
if (null === $action) {
|
||||
$action = $request->getActionName();
|
||||
} elseif (!is_string($action)) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Invalid action specifier for view render');
|
||||
}
|
||||
|
||||
if (null === $this->_delimiters) {
|
||||
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
|
||||
$wordDelimiters = $dispatcher->getWordDelimiter();
|
||||
$pathDelimiters = $dispatcher->getPathDelimiter();
|
||||
$this->_delimiters = array_unique(array_merge($wordDelimiters, (array) $pathDelimiters));
|
||||
}
|
||||
|
||||
$action = str_replace($this->_delimiters, '-', $action);
|
||||
$script = $action . '.' . $this->viewSuffix;
|
||||
|
||||
if (!$noController) {
|
||||
$controller = $request->getControllerName();
|
||||
$controller = str_replace($this->_delimiters, '-', $controller);
|
||||
$script = $controller . DIRECTORY_SEPARATOR . $script;
|
||||
}
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Request object
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$this->_request = $request;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Response object
|
||||
*
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Abstract $response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set invocation arguments
|
||||
*
|
||||
* @param array $args
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
protected function _setInvokeArgs(array $args = array())
|
||||
{
|
||||
$this->_invokeArgs = $args;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the array of constructor arguments (minus the Request object)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInvokeArgs()
|
||||
{
|
||||
return $this->_invokeArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single invocation argument
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getInvokeArg($key)
|
||||
{
|
||||
if (isset($this->_invokeArgs[$key])) {
|
||||
return $this->_invokeArgs[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a helper by name
|
||||
*
|
||||
* @param string $helperName
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function getHelper($helperName)
|
||||
{
|
||||
return $this->_helper->{$helperName};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a clone of a helper by name
|
||||
*
|
||||
* @param string $helperName
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function getHelperCopy($helperName)
|
||||
{
|
||||
return clone $this->_helper->{$helperName};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the front controller instance
|
||||
*
|
||||
* @param Zend_Controller_Front $front
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
public function setFrontController(Zend_Controller_Front $front)
|
||||
{
|
||||
$this->_frontController = $front;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Front Controller
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController()
|
||||
{
|
||||
// Used cache version if found
|
||||
if (null !== $this->_frontController) {
|
||||
return $this->_frontController;
|
||||
}
|
||||
|
||||
// Grab singleton instance, if class has been loaded
|
||||
if (class_exists('Zend_Controller_Front')) {
|
||||
$this->_frontController = Zend_Controller_Front::getInstance();
|
||||
return $this->_frontController;
|
||||
}
|
||||
|
||||
// Throw exception in all other cases
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Front controller class has not been loaded');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-dispatch routines
|
||||
*
|
||||
* Called before action method. If using class with
|
||||
* {@link Zend_Controller_Front}, it may modify the
|
||||
* {@link $_request Request object} and reset its dispatched flag in order
|
||||
* to skip processing the current action.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-dispatch routines
|
||||
*
|
||||
* Called after action method execution. If using class with
|
||||
* {@link Zend_Controller_Front}, it may modify the
|
||||
* {@link $_request Request object} and reset its dispatched flag in order
|
||||
* to process an additional action.
|
||||
*
|
||||
* Common usages for postDispatch() include rendering content in a sitewide
|
||||
* template, link url correction, setting headers, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy for undefined methods. Default behavior is to throw an
|
||||
* exception on undefined methods, however this function can be
|
||||
* overridden to implement magic (dynamic) actions, or provide run-time
|
||||
* dispatching.
|
||||
*
|
||||
* @param string $methodName
|
||||
* @param array $args
|
||||
* @return void
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
*/
|
||||
public function __call($methodName, $args)
|
||||
{
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
if ('Action' == substr($methodName, -6)) {
|
||||
$action = substr($methodName, 0, strlen($methodName) - 6);
|
||||
throw new Zend_Controller_Action_Exception(sprintf('Action "%s" does not exist and was not trapped in __call()', $action), 404);
|
||||
}
|
||||
|
||||
throw new Zend_Controller_Action_Exception(sprintf('Method "%s" does not exist and was not trapped in __call()', $methodName), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the requested action
|
||||
*
|
||||
* @param string $action Method name of action
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch($action)
|
||||
{
|
||||
// Notify helpers of action preDispatch state
|
||||
$this->_helper->notifyPreDispatch();
|
||||
|
||||
$this->preDispatch();
|
||||
if ($this->getRequest()->isDispatched()) {
|
||||
if (null === $this->_classMethods) {
|
||||
$this->_classMethods = get_class_methods($this);
|
||||
}
|
||||
|
||||
// preDispatch() didn't change the action, so we can continue
|
||||
if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
|
||||
if ($this->getInvokeArg('useCaseSensitiveActions')) {
|
||||
trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
|
||||
}
|
||||
$this->$action();
|
||||
} else {
|
||||
$this->__call($action, array());
|
||||
}
|
||||
$this->postDispatch();
|
||||
}
|
||||
|
||||
// whats actually important here is that this action controller is
|
||||
// shutting down, regardless of dispatching; notify the helpers of this
|
||||
// state
|
||||
$this->_helper->notifyPostDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the action specified in the request object, and return a response
|
||||
*
|
||||
* Not used in the Action Controller implementation, but left for usage in
|
||||
* Page Controller implementations. Dispatches a method based on the
|
||||
* request.
|
||||
*
|
||||
* Returns a Zend_Controller_Response_Abstract object, instantiating one
|
||||
* prior to execution if none exists in the controller.
|
||||
*
|
||||
* {@link preDispatch()} is called prior to the action,
|
||||
* {@link postDispatch()} is called following it.
|
||||
*
|
||||
* @param null|Zend_Controller_Request_Abstract $request Optional request
|
||||
* object to use
|
||||
* @param null|Zend_Controller_Response_Abstract $response Optional response
|
||||
* object to use
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
|
||||
{
|
||||
if (null !== $request) {
|
||||
$this->setRequest($request);
|
||||
} else {
|
||||
$request = $this->getRequest();
|
||||
}
|
||||
|
||||
if (null !== $response) {
|
||||
$this->setResponse($response);
|
||||
}
|
||||
|
||||
$action = $request->getActionName();
|
||||
if (empty($action)) {
|
||||
$action = 'index';
|
||||
}
|
||||
$action = $action . 'Action';
|
||||
|
||||
$request->setDispatched(true);
|
||||
$this->dispatch($action);
|
||||
|
||||
return $this->getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a parameter from the {@link $_request Request object}. If the
|
||||
* parameter does not exist, NULL will be returned.
|
||||
*
|
||||
* If the parameter does not exist and $default is set, then
|
||||
* $default will be returned instead of NULL.
|
||||
*
|
||||
* @param string $paramName
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _getParam($paramName, $default = null)
|
||||
{
|
||||
$value = $this->getRequest()->getParam($paramName);
|
||||
if ((null === $value) && (null !== $default)) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter in the {@link $_request Request object}.
|
||||
*
|
||||
* @param string $paramName
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
protected function _setParam($paramName, $value)
|
||||
{
|
||||
$this->getRequest()->setParam($paramName, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a given parameter exists in the
|
||||
* {@link $_request Request object}.
|
||||
*
|
||||
* @param string $paramName
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _hasParam($paramName)
|
||||
{
|
||||
return null !== $this->getRequest()->getParam($paramName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all parameters in the {@link $_request Request object}
|
||||
* as an associative array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getAllParams()
|
||||
{
|
||||
return $this->getRequest()->getParams();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Forward to another controller/action.
|
||||
*
|
||||
* It is important to supply the unformatted names, i.e. "article"
|
||||
* rather than "ArticleController". The dispatcher will do the
|
||||
* appropriate formatting when the request is received.
|
||||
*
|
||||
* If only an action name is provided, forwards to that action in this
|
||||
* controller.
|
||||
*
|
||||
* If an action and controller are specified, forwards to that action and
|
||||
* controller in this module.
|
||||
*
|
||||
* Specifying an action, controller, and module is the most specific way to
|
||||
* forward.
|
||||
*
|
||||
* A fourth argument, $params, will be used to set the request parameters.
|
||||
* If either the controller or module are unnecessary for forwarding,
|
||||
* simply pass null values for them before specifying the parameters.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
final protected function _forward($action, $controller = null, $module = null, array $params = null)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if (null !== $params) {
|
||||
$request->setParams($params);
|
||||
}
|
||||
|
||||
if (null !== $controller) {
|
||||
$request->setControllerName($controller);
|
||||
|
||||
// Module should only be reset if controller has been specified
|
||||
if (null !== $module) {
|
||||
$request->setModuleName($module);
|
||||
}
|
||||
}
|
||||
|
||||
$request->setActionName($action)
|
||||
->setDispatched(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to another URL
|
||||
*
|
||||
* Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options Options to be used when redirecting
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect($url, array $options = array())
|
||||
{
|
||||
$this->_helper->redirector->gotoUrl($url, $options);
|
||||
}
|
||||
}
|
38
airtime_mvc/library/Zend/Controller/Action/Exception.php
Normal file
38
airtime_mvc/library/Zend/Controller/Action/Exception.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Exception extends Zend_Controller_Exception
|
||||
{}
|
154
airtime_mvc/library/Zend/Controller/Action/Helper/Abstract.php
Normal file
154
airtime_mvc/library/Zend/Controller/Action/Helper/Abstract.php
Normal file
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20261 2010-01-13 18:55:25Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action
|
||||
*/
|
||||
require_once 'Zend/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* $_actionController
|
||||
*
|
||||
* @var Zend_Controller_Action $_actionController
|
||||
*/
|
||||
protected $_actionController = null;
|
||||
|
||||
/**
|
||||
* @var mixed $_frontController
|
||||
*/
|
||||
protected $_frontController = null;
|
||||
|
||||
/**
|
||||
* setActionController()
|
||||
*
|
||||
* @param Zend_Controller_Action $actionController
|
||||
* @return Zend_Controller_ActionHelper_Abstract Provides a fluent interface
|
||||
*/
|
||||
public function setActionController(Zend_Controller_Action $actionController = null)
|
||||
{
|
||||
$this->_actionController = $actionController;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve current action controller
|
||||
*
|
||||
* @return Zend_Controller_Action
|
||||
*/
|
||||
public function getActionController()
|
||||
{
|
||||
return $this->_actionController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve front controller instance
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController()
|
||||
{
|
||||
return Zend_Controller_Front::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into action controller initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into action controller preDispatch() workflow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into action controller postDispatch() workflow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* getRequest() -
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
$controller = $this->getActionController();
|
||||
if (null === $controller) {
|
||||
$controller = $this->getFrontController();
|
||||
}
|
||||
|
||||
return $controller->getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* getResponse() -
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract $response
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
$controller = $this->getActionController();
|
||||
if (null === $controller) {
|
||||
$controller = $this->getFrontController();
|
||||
}
|
||||
|
||||
return $controller->getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* getName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
$full_class_name = get_class($this);
|
||||
|
||||
if (strpos($full_class_name, '_') !== false) {
|
||||
$helper_name = strrchr($full_class_name, '_');
|
||||
return ltrim($helper_name, '_');
|
||||
} else {
|
||||
return $full_class_name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ActionStack.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Add to action stack
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_ActionStack extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
protected $_actionStack;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Register action stack plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$front = Zend_Controller_Front::getInstance();
|
||||
if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
|
||||
/**
|
||||
* @see Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
require_once 'Zend/Controller/Plugin/ActionStack.php';
|
||||
$this->_actionStack = new Zend_Controller_Plugin_ActionStack();
|
||||
$front->registerPlugin($this->_actionStack, 97);
|
||||
} else {
|
||||
$this->_actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Push onto the stack
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $next
|
||||
* @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface
|
||||
*/
|
||||
public function pushStack(Zend_Controller_Request_Abstract $next)
|
||||
{
|
||||
$this->_actionStack->pushStack($next);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new action onto the stack
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @return Zend_Controller_Action_Helper_ActionStack
|
||||
*/
|
||||
public function actionToStack($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
if ($action instanceof Zend_Controller_Request_Abstract) {
|
||||
return $this->pushStack($action);
|
||||
} elseif (!is_string($action)) {
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('ActionStack requires either a request object or minimally a string action');
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request instanceof Zend_Controller_Request_Abstract === false){
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Request object not set yet');
|
||||
}
|
||||
|
||||
$controller = (null === $controller) ? $request->getControllerName() : $controller;
|
||||
$module = (null === $module) ? $request->getModuleName() : $module;
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Request_Simple
|
||||
*/
|
||||
require_once 'Zend/Controller/Request/Simple.php';
|
||||
$newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params);
|
||||
|
||||
return $this->pushStack($newRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform helper when called as $this->_helper->actionStack() from an action controller
|
||||
*
|
||||
* Proxies to {@link simple()}
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function direct($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
return $this->actionToStack($action, $controller, $module, $params);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: AjaxContext.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_ContextSwitch
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/ContextSwitch.php';
|
||||
|
||||
/**
|
||||
* Simplify AJAX context switching based on requested format
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_AjaxContext extends Zend_Controller_Action_Helper_ContextSwitch
|
||||
{
|
||||
/**
|
||||
* Controller property to utilize for context switching
|
||||
* @var string
|
||||
*/
|
||||
protected $_contextKey = 'ajaxable';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Add HTML context
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->addContext('html', array('suffix' => 'ajax'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize AJAX context switching
|
||||
*
|
||||
* Checks for XHR requests; if detected, attempts to perform context switch.
|
||||
*
|
||||
* @param string $format
|
||||
* @return void
|
||||
*/
|
||||
public function initContext($format = null)
|
||||
{
|
||||
$this->_currentContext = null;
|
||||
|
||||
if (!$this->getRequest()->isXmlHttpRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::initContext($format);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Create and send autocompletion lists
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Action_Helper_AutoComplete_Abstract extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Suppress exit when sendJson() called
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $suppressExit = false;
|
||||
|
||||
/**
|
||||
* Validate autocompletion data
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return boolean
|
||||
*/
|
||||
abstract public function validateData($data);
|
||||
|
||||
/**
|
||||
* Prepare autocompletion data
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean $keepLayouts
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function prepareAutoCompletion($data, $keepLayouts = false);
|
||||
|
||||
/**
|
||||
* Disable layouts and view renderer
|
||||
*
|
||||
* @return Zend_Controller_Action_Helper_AutoComplete_Abstract Provides a fluent interface
|
||||
*/
|
||||
public function disableLayouts()
|
||||
{
|
||||
/**
|
||||
* @see Zend_Layout
|
||||
*/
|
||||
require_once 'Zend/Layout.php';
|
||||
if (null !== ($layout = Zend_Layout::getMvcInstance())) {
|
||||
$layout->disableLayout();
|
||||
}
|
||||
|
||||
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode data to JSON
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $keepLayouts
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @return string
|
||||
*/
|
||||
public function encodeJson($data, $keepLayouts = false)
|
||||
{
|
||||
if ($this->validateData($data)) {
|
||||
return Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send autocompletion data
|
||||
*
|
||||
* Calls prepareAutoCompletion, populates response body with this
|
||||
* information, and sends response.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $keepLayouts
|
||||
* @return string|void
|
||||
*/
|
||||
public function sendAutoCompletion($data, $keepLayouts = false)
|
||||
{
|
||||
$data = $this->prepareAutoCompletion($data, $keepLayouts);
|
||||
|
||||
$response = $this->getResponse();
|
||||
$response->setBody($data);
|
||||
|
||||
if (!$this->suppressExit) {
|
||||
$response->sendResponse();
|
||||
exit;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy pattern: allow calling helper as broker method
|
||||
*
|
||||
* Prepares autocompletion data and, if $sendNow is true, immediately sends
|
||||
* response.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $sendNow
|
||||
* @param bool $keepLayouts
|
||||
* @return string|void
|
||||
*/
|
||||
public function direct($data, $sendNow = true, $keepLayouts = false)
|
||||
{
|
||||
if ($sendNow) {
|
||||
return $this->sendAutoCompletion($data, $keepLayouts);
|
||||
}
|
||||
|
||||
return $this->prepareAutoCompletion($data, $keepLayouts);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: AutoCompleteDojo.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
|
||||
|
||||
/**
|
||||
* Create and send Dojo-compatible autocompletion lists
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
{
|
||||
/**
|
||||
* Validate data for autocompletion
|
||||
*
|
||||
* Stub; unused
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return boolean
|
||||
*/
|
||||
public function validateData($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data for autocompletion
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean $keepLayouts
|
||||
* @return string
|
||||
*/
|
||||
public function prepareAutoCompletion($data, $keepLayouts = false)
|
||||
{
|
||||
if (!$data instanceof Zend_Dojo_Data) {
|
||||
require_once 'Zend/Dojo/Data.php';
|
||||
$items = array();
|
||||
foreach ($data as $key => $value) {
|
||||
$items[] = array('label' => $value, 'name' => $value);
|
||||
}
|
||||
$data = new Zend_Dojo_Data('name', $items);
|
||||
}
|
||||
|
||||
if (!$keepLayouts) {
|
||||
require_once 'Zend/Controller/Action/HelperBroker.php';
|
||||
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
|
||||
|
||||
require_once 'Zend/Layout.php';
|
||||
$layout = Zend_Layout::getMvcInstance();
|
||||
if ($layout instanceof Zend_Layout) {
|
||||
$layout->disableLayout();
|
||||
}
|
||||
}
|
||||
|
||||
$response = Zend_Controller_Front::getInstance()->getResponse();
|
||||
$response->setHeader('Content-Type', 'application/json');
|
||||
|
||||
return $data->toJson();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: AutoCompleteScriptaculous.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
|
||||
|
||||
/**
|
||||
* Create and send Scriptaculous-compatible autocompletion lists
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
|
||||
{
|
||||
/**
|
||||
* Validate data for autocompletion
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return bool
|
||||
*/
|
||||
public function validateData($data)
|
||||
{
|
||||
if (!is_array($data) && !is_scalar($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data for autocompletion
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean $keepLayouts
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @return string
|
||||
*/
|
||||
public function prepareAutoCompletion($data, $keepLayouts = false)
|
||||
{
|
||||
if (!$this->validateData($data)) {
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
|
||||
}
|
||||
|
||||
$data = (array) $data;
|
||||
$data = '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
|
||||
|
||||
if (!$keepLayouts) {
|
||||
$this->disableLayouts();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
279
airtime_mvc/library/Zend/Controller/Action/Helper/Cache.php
Normal file
279
airtime_mvc/library/Zend/Controller/Action/Helper/Cache.php
Normal file
|
@ -0,0 +1,279 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Manager
|
||||
*/
|
||||
require_once 'Zend/Cache/Manager.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_Cache
|
||||
extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Local Cache Manager object used by Helper
|
||||
*
|
||||
* @var Zend_Cache_Manager
|
||||
*/
|
||||
protected $_manager = null;
|
||||
|
||||
/**
|
||||
* Indexed map of Actions to attempt Page caching on by Controller
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_caching = array();
|
||||
|
||||
/**
|
||||
* Indexed map of Tags by Controller and Action
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags = array();
|
||||
|
||||
/**
|
||||
* Indexed map of Extensions by Controller and Action
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_extensions = array();
|
||||
|
||||
/**
|
||||
* Track output buffering condition
|
||||
*/
|
||||
protected $_obStarted = false;
|
||||
|
||||
/**
|
||||
* Tell the helper which actions are cacheable and under which
|
||||
* tags (if applicable) they should be recorded with
|
||||
*
|
||||
* @param array $actions
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function direct(array $actions, array $tags = array(), $extension = null)
|
||||
{
|
||||
$controller = $this->getRequest()->getControllerName();
|
||||
$actions = array_unique($actions);
|
||||
if (!isset($this->_caching[$controller])) {
|
||||
$this->_caching[$controller] = array();
|
||||
}
|
||||
if (!empty($tags)) {
|
||||
$tags = array_unique($tags);
|
||||
if (!isset($this->_tags[$controller])) {
|
||||
$this->_tags[$controller] = array();
|
||||
}
|
||||
}
|
||||
foreach ($actions as $action) {
|
||||
$this->_caching[$controller][] = $action;
|
||||
if (!empty($tags)) {
|
||||
$this->_tags[$controller][$action] = array();
|
||||
foreach ($tags as $tag) {
|
||||
$this->_tags[$controller][$action][] = $tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($extension) {
|
||||
if (!isset($this->_extensions[$controller])) {
|
||||
$this->_extensions[$controller] = array();
|
||||
}
|
||||
foreach ($actions as $action) {
|
||||
$this->_extensions[$controller][$action] = $extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specific page cache static file based on its
|
||||
* relative URL from the application's public directory.
|
||||
* The file extension is not required here; usually matches
|
||||
* the original REQUEST_URI that was cached.
|
||||
*
|
||||
* @param string $relativeUrl
|
||||
* @param bool $recursive
|
||||
* @return mixed
|
||||
*/
|
||||
public function removePage($relativeUrl, $recursive = false)
|
||||
{
|
||||
$cache = $this->getCache(Zend_Cache_Manager::PAGECACHE);
|
||||
if ($recursive) {
|
||||
$backend = $cache->getBackend();
|
||||
if (($backend instanceof Zend_Cache_Backend)
|
||||
&& method_exists($backend, 'removeRecursively')
|
||||
) {
|
||||
return $backend->removeRecursively($relativeUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return $cache->remove($relativeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specific page cache static file based on its
|
||||
* relative URL from the application's public directory.
|
||||
* The file extension is not required here; usually matches
|
||||
* the original REQUEST_URI that was cached.
|
||||
*
|
||||
* @param array $tags
|
||||
* @return mixed
|
||||
*/
|
||||
public function removePagesTagged(array $tags)
|
||||
{
|
||||
return $this->getCache(Zend_Cache_Manager::PAGECACHE)
|
||||
->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commence page caching for any cacheable actions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch()
|
||||
{
|
||||
$controller = $this->getRequest()->getControllerName();
|
||||
$action = $this->getRequest()->getActionName();
|
||||
$stats = ob_get_status(true);
|
||||
foreach ($stats as $status) {
|
||||
if ($status['name'] == 'Zend_Cache_Frontend_Page::_flush'
|
||||
|| $status['name'] == 'Zend_Cache_Frontend_Capture::_flush') {
|
||||
$obStarted = true;
|
||||
}
|
||||
}
|
||||
if (!isset($obStarted) && isset($this->_caching[$controller]) &&
|
||||
in_array($action, $this->_caching[$controller])) {
|
||||
$reqUri = $this->getRequest()->getRequestUri();
|
||||
$tags = array();
|
||||
if (isset($this->_tags[$controller][$action])
|
||||
&& !empty($this->_tags[$controller][$action])) {
|
||||
$tags = array_unique($this->_tags[$controller][$action]);
|
||||
}
|
||||
$extension = null;
|
||||
if (isset($this->_extensions[$controller][$action])) {
|
||||
$extension = $this->_extensions[$controller][$action];
|
||||
}
|
||||
$this->getCache(Zend_Cache_Manager::PAGECACHE)
|
||||
->start($this->_encodeCacheId($reqUri), $tags, $extension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a Cache ID as hexadecimal. This is a workaround because Backend ID validation
|
||||
* is trapped in the Frontend classes. Will try to get this reversed for ZF 2.0
|
||||
* because it's a major annoyance to have IDs so restricted!
|
||||
*
|
||||
* @return string
|
||||
* @param string $requestUri
|
||||
*/
|
||||
protected function _encodeCacheId($requestUri)
|
||||
{
|
||||
return bin2hex($requestUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an instance of the Cache Manager for this helper
|
||||
*
|
||||
* @param Zend_Cache_Manager $manager
|
||||
* @return void
|
||||
*/
|
||||
public function setManager(Zend_Cache_Manager $manager)
|
||||
{
|
||||
$this->_manager = $manager;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cache Manager instance or instantiate the object if not
|
||||
* exists. Attempts to load from bootstrap if available.
|
||||
*
|
||||
* @return Zend_Cache_Manager
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
if (!is_null($this->_manager)) {
|
||||
return $this->_manager;
|
||||
}
|
||||
$front = Zend_Controller_Front::getInstance();
|
||||
if ($front->getParam('bootstrap')
|
||||
&& $front->getParam('bootstrap')->getResource('CacheManager')) {
|
||||
return $front->getParam('bootstrap')
|
||||
->getResource('CacheManager');
|
||||
}
|
||||
$this->_manager = new Zend_Cache_Manager;
|
||||
return $this->_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of actions for the current Controller marked for
|
||||
* caching
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCacheableActions()
|
||||
{
|
||||
return $this->_caching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of tags set for all cacheable actions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCacheableTags()
|
||||
{
|
||||
return $this->_tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy non-matched methods back to Zend_Cache_Manager where
|
||||
* appropriate
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (method_exists($this->getManager(), $method)) {
|
||||
return call_user_func_array(
|
||||
array($this->getManager(), $method), $args
|
||||
);
|
||||
}
|
||||
throw new Zend_Controller_Action_Exception('Method does not exist:'
|
||||
. $method);
|
||||
}
|
||||
|
||||
}
|
1394
airtime_mvc/library/Zend/Controller/Action/Helper/ContextSwitch.php
Normal file
1394
airtime_mvc/library/Zend/Controller/Action/Helper/ContextSwitch.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Session
|
||||
*/
|
||||
require_once 'Zend/Session.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Flash Messenger - implement session-based messages
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FlashMessenger.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Action_Helper_Abstract implements IteratorAggregate, Countable
|
||||
{
|
||||
/**
|
||||
* $_messages - Messages from previous request
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static protected $_messages = array();
|
||||
|
||||
/**
|
||||
* $_session - Zend_Session storage object
|
||||
*
|
||||
* @var Zend_Session
|
||||
*/
|
||||
static protected $_session = null;
|
||||
|
||||
/**
|
||||
* $_messageAdded - Wether a message has been previously added
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static protected $_messageAdded = false;
|
||||
|
||||
/**
|
||||
* $_namespace - Instance namespace, default is 'default'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_namespace = 'default';
|
||||
|
||||
/**
|
||||
* __construct() - Instance constructor, needed to get iterators, etc
|
||||
*
|
||||
* @param string $namespace
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!self::$_session instanceof Zend_Session_Namespace) {
|
||||
self::$_session = new Zend_Session_Namespace($this->getName());
|
||||
foreach (self::$_session as $namespace => $messages) {
|
||||
self::$_messages[$namespace] = $messages;
|
||||
unset(self::$_session->{$namespace});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* postDispatch() - runs after action is dispatched, in this
|
||||
* case, it is resetting the namespace in case we have forwarded to a different
|
||||
* action, Flashmessage will be 'clean' (default namespace)
|
||||
*
|
||||
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
|
||||
*/
|
||||
public function postDispatch()
|
||||
{
|
||||
$this->resetNamespace();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setNamespace() - change the namespace messages are added to, useful for
|
||||
* per action controller messaging between requests
|
||||
*
|
||||
* @param string $namespace
|
||||
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
|
||||
*/
|
||||
public function setNamespace($namespace = 'default')
|
||||
{
|
||||
$this->_namespace = $namespace;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* resetNamespace() - reset the namespace to the default
|
||||
*
|
||||
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
|
||||
*/
|
||||
public function resetNamespace()
|
||||
{
|
||||
$this->setNamespace();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* addMessage() - Add a message to flash message
|
||||
*
|
||||
* @param string $message
|
||||
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
|
||||
*/
|
||||
public function addMessage($message)
|
||||
{
|
||||
if (self::$_messageAdded === false) {
|
||||
self::$_session->setExpirationHops(1, null, true);
|
||||
}
|
||||
|
||||
if (!is_array(self::$_session->{$this->_namespace})) {
|
||||
self::$_session->{$this->_namespace} = array();
|
||||
}
|
||||
|
||||
self::$_session->{$this->_namespace}[] = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasMessages() - Wether a specific namespace has messages
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasMessages()
|
||||
{
|
||||
return isset(self::$_messages[$this->_namespace]);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessages() - Get messages from a specific namespace
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
if ($this->hasMessages()) {
|
||||
return self::$_messages[$this->_namespace];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all messages from the previous request & current namespace
|
||||
*
|
||||
* @return boolean True if messages were cleared, false if none existed
|
||||
*/
|
||||
public function clearMessages()
|
||||
{
|
||||
if ($this->hasMessages()) {
|
||||
unset(self::$_messages[$this->_namespace]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasCurrentMessages() - check to see if messages have been added to current
|
||||
* namespace within this request
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasCurrentMessages()
|
||||
{
|
||||
return isset(self::$_session->{$this->_namespace});
|
||||
}
|
||||
|
||||
/**
|
||||
* getCurrentMessages() - get messages that have been added to the current
|
||||
* namespace within this request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrentMessages()
|
||||
{
|
||||
if ($this->hasCurrentMessages()) {
|
||||
return self::$_session->{$this->_namespace};
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* clear messages from the current request & current namespace
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clearCurrentMessages()
|
||||
{
|
||||
if ($this->hasCurrentMessages()) {
|
||||
unset(self::$_session->{$this->_namespace});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* getIterator() - complete the IteratorAggregate interface, for iterating
|
||||
*
|
||||
* @return ArrayObject
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
if ($this->hasMessages()) {
|
||||
return new ArrayObject($this->getMessages());
|
||||
}
|
||||
|
||||
return new ArrayObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* count() - Complete the countable interface
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
if ($this->hasMessages()) {
|
||||
return count($this->getMessages());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy pattern: proxy to addMessage()
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public function direct($message)
|
||||
{
|
||||
return $this->addMessage($message);
|
||||
}
|
||||
}
|
130
airtime_mvc/library/Zend/Controller/Action/Helper/Json.php
Normal file
130
airtime_mvc/library/Zend/Controller/Action/Helper/Json.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Json.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Simplify AJAX context switching based on requested format
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_Json extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Suppress exit when sendJson() called
|
||||
* @var boolean
|
||||
*/
|
||||
public $suppressExit = false;
|
||||
|
||||
/**
|
||||
* Create JSON response
|
||||
*
|
||||
* Encodes and returns data to JSON. Content-Type header set to
|
||||
* 'application/json', and disables layouts and viewRenderer (if being
|
||||
* used).
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean $keepLayouts
|
||||
* @param boolean|array $keepLayouts
|
||||
* NOTE: if boolean, establish $keepLayouts to true|false
|
||||
* if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
|
||||
* if $keepLayouts and parmas for Zend_Json::encode are required
|
||||
* then, the array can contains a 'keepLayout'=>true|false
|
||||
* that will not be passed to Zend_Json::encode method but will be passed
|
||||
* to Zend_View_Helper_Json
|
||||
* @throws Zend_Controller_Action_Helper_Json
|
||||
* @return string
|
||||
*/
|
||||
public function encodeJson($data, $keepLayouts = false)
|
||||
{
|
||||
/**
|
||||
* @see Zend_View_Helper_Json
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Json.php';
|
||||
$jsonHelper = new Zend_View_Helper_Json();
|
||||
$data = $jsonHelper->json($data, $keepLayouts);
|
||||
|
||||
if (!$keepLayouts) {
|
||||
/**
|
||||
* @see Zend_Controller_Action_HelperBroker
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/HelperBroker.php';
|
||||
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode JSON response and immediately send
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean|array $keepLayouts
|
||||
* NOTE: if boolean, establish $keepLayouts to true|false
|
||||
* if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
|
||||
* if $keepLayouts and parmas for Zend_Json::encode are required
|
||||
* then, the array can contains a 'keepLayout'=>true|false
|
||||
* that will not be passed to Zend_Json::encode method but will be passed
|
||||
* to Zend_View_Helper_Json
|
||||
* @return string|void
|
||||
*/
|
||||
public function sendJson($data, $keepLayouts = false)
|
||||
{
|
||||
$data = $this->encodeJson($data, $keepLayouts);
|
||||
$response = $this->getResponse();
|
||||
$response->setBody($data);
|
||||
|
||||
if (!$this->suppressExit) {
|
||||
$response->sendResponse();
|
||||
exit;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy pattern: call helper as helper broker method
|
||||
*
|
||||
* Allows encoding JSON. If $sendNow is true, immediately sends JSON
|
||||
* response.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param boolean $sendNow
|
||||
* @param boolean $keepLayouts
|
||||
* @return string|void
|
||||
*/
|
||||
public function direct($data, $sendNow = true, $keepLayouts = false)
|
||||
{
|
||||
if ($sendNow) {
|
||||
return $this->sendJson($data, $keepLayouts);
|
||||
}
|
||||
return $this->encodeJson($data, $keepLayouts);
|
||||
}
|
||||
}
|
531
airtime_mvc/library/Zend/Controller/Action/Helper/Redirector.php
Normal file
531
airtime_mvc/library/Zend/Controller/Action/Helper/Redirector.php
Normal file
|
@ -0,0 +1,531 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Redirector.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* HTTP status code for redirects
|
||||
* @var int
|
||||
*/
|
||||
protected $_code = 302;
|
||||
|
||||
/**
|
||||
* Whether or not calls to _redirect() should exit script execution
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_exit = true;
|
||||
|
||||
/**
|
||||
* Whether or not _redirect() should attempt to prepend the base URL to the
|
||||
* passed URL (if it's a relative URL)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_prependBase = true;
|
||||
|
||||
/**
|
||||
* Url to which to redirect
|
||||
* @var string
|
||||
*/
|
||||
protected $_redirectUrl = null;
|
||||
|
||||
/**
|
||||
* Whether or not to use an absolute URI when redirecting
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useAbsoluteUri = false;
|
||||
|
||||
/**
|
||||
* Whether or not to close the session before exiting
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_closeSessionOnExit = true;
|
||||
|
||||
/**
|
||||
* Retrieve HTTP status code to emit on {@link _redirect()} call
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate HTTP status redirect code
|
||||
*
|
||||
* @param int $code
|
||||
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
|
||||
* @return true
|
||||
*/
|
||||
protected function _checkCode($code)
|
||||
{
|
||||
$code = (int)$code;
|
||||
if ((300 > $code) || (307 < $code) || (304 == $code) || (306 == $code)) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve HTTP status code for {@link _redirect()} behaviour
|
||||
*
|
||||
* @param int $code
|
||||
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->_checkCode($code);
|
||||
$this->_code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve flag for whether or not {@link _redirect()} will exit when finished.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getExit()
|
||||
{
|
||||
return $this->_exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve exit flag for {@link _redirect()} behaviour
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
|
||||
*/
|
||||
public function setExit($flag)
|
||||
{
|
||||
$this->_exit = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve flag for whether or not {@link _redirect()} will prepend the
|
||||
* base URL on relative URLs
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPrependBase()
|
||||
{
|
||||
return $this->_prependBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve 'prepend base' flag for {@link _redirect()} behaviour
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
|
||||
*/
|
||||
public function setPrependBase($flag)
|
||||
{
|
||||
$this->_prependBase = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve flag for whether or not {@link redirectAndExit()} shall close the session before
|
||||
* exiting.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCloseSessionOnExit()
|
||||
{
|
||||
return $this->_closeSessionOnExit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag for whether or not {@link redirectAndExit()} shall close the session before exiting.
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
|
||||
*/
|
||||
public function setCloseSessionOnExit($flag)
|
||||
{
|
||||
$this->_closeSessionOnExit = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return use absolute URI flag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseAbsoluteUri()
|
||||
{
|
||||
return $this->_useAbsoluteUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set use absolute URI flag
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
|
||||
*/
|
||||
public function setUseAbsoluteUri($flag = true)
|
||||
{
|
||||
$this->_useAbsoluteUri = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set redirect in response object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect($url)
|
||||
{
|
||||
if ($this->getUseAbsoluteUri() && !preg_match('#^(https?|ftp)://#', $url)) {
|
||||
$host = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
|
||||
$proto = (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=="off") ? 'https' : 'http';
|
||||
$port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
|
||||
$uri = $proto . '://' . $host;
|
||||
if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
|
||||
$uri .= ':' . $port;
|
||||
}
|
||||
$url = $uri . '/' . ltrim($url, '/');
|
||||
}
|
||||
$this->_redirectUrl = $url;
|
||||
$this->getResponse()->setRedirect($url, $this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve currently set URL for redirect
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirectUrl()
|
||||
{
|
||||
return $this->_redirectUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the baseUrl should be prepended, and prepend if necessary
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
protected function _prependBase($url)
|
||||
{
|
||||
if ($this->getPrependBase()) {
|
||||
$request = $this->getRequest();
|
||||
if ($request instanceof Zend_Controller_Request_Http) {
|
||||
$base = rtrim($request->getBaseUrl(), '/');
|
||||
if (!empty($base) && ('/' != $base)) {
|
||||
$url = $base . '/' . ltrim($url, '/');
|
||||
} else {
|
||||
$url = '/' . ltrim($url, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a redirect URL of the form /module/controller/action/params
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function setGotoSimple($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
$dispatcher = $this->getFrontController()->getDispatcher();
|
||||
$request = $this->getRequest();
|
||||
$curModule = $request->getModuleName();
|
||||
$useDefaultController = false;
|
||||
|
||||
if (null === $controller && null !== $module) {
|
||||
$useDefaultController = true;
|
||||
}
|
||||
|
||||
if (null === $module) {
|
||||
$module = $curModule;
|
||||
}
|
||||
|
||||
if ($module == $dispatcher->getDefaultModule()) {
|
||||
$module = '';
|
||||
}
|
||||
|
||||
if (null === $controller && !$useDefaultController) {
|
||||
$controller = $request->getControllerName();
|
||||
if (empty($controller)) {
|
||||
$controller = $dispatcher->getDefaultControllerName();
|
||||
}
|
||||
}
|
||||
|
||||
$params['module'] = $module;
|
||||
$params['controller'] = $controller;
|
||||
$params['action'] = $action;
|
||||
|
||||
$router = $this->getFrontController()->getRouter();
|
||||
$url = $router->assemble($params, 'default', true);
|
||||
|
||||
$this->_redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a URL based on a route
|
||||
*
|
||||
* @param array $urlOptions
|
||||
* @param string $name Route name
|
||||
* @param boolean $reset
|
||||
* @param boolean $encode
|
||||
* @return void
|
||||
*/
|
||||
public function setGotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
|
||||
{
|
||||
$router = $this->getFrontController()->getRouter();
|
||||
$url = $router->assemble($urlOptions, $name, $reset, $encode);
|
||||
|
||||
$this->_redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a redirect URL string
|
||||
*
|
||||
* By default, emits a 302 HTTP status header, prepends base URL as defined
|
||||
* in request object if url is relative, and halts script execution by
|
||||
* calling exit().
|
||||
*
|
||||
* $options is an optional associative array that can be used to control
|
||||
* redirect behaviour. The available option keys are:
|
||||
* - exit: boolean flag indicating whether or not to halt script execution when done
|
||||
* - prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
|
||||
* - code: integer HTTP status code to use with redirect. Should be between 300 and 307.
|
||||
*
|
||||
* _redirect() sets the Location header in the response object. If you set
|
||||
* the exit flag to false, you can override this header later in code
|
||||
* execution.
|
||||
*
|
||||
* If the exit flag is true (true by default), _redirect() will write and
|
||||
* close the current session, if any.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function setGotoUrl($url, array $options = array())
|
||||
{
|
||||
// prevent header injections
|
||||
$url = str_replace(array("\n", "\r"), '', $url);
|
||||
|
||||
if (null !== $options) {
|
||||
if (isset($options['exit'])) {
|
||||
$this->setExit(($options['exit']) ? true : false);
|
||||
}
|
||||
if (isset($options['prependBase'])) {
|
||||
$this->setPrependBase(($options['prependBase']) ? true : false);
|
||||
}
|
||||
if (isset($options['code'])) {
|
||||
$this->setCode($options['code']);
|
||||
}
|
||||
}
|
||||
|
||||
// If relative URL, decide if we should prepend base URL
|
||||
if (!preg_match('|^[a-z]+://|', $url)) {
|
||||
$url = $this->_prependBase($url);
|
||||
}
|
||||
|
||||
$this->_redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a redirect to an action/controller/module with params
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function gotoSimple($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
$this->setGotoSimple($action, $controller, $module, $params);
|
||||
|
||||
if ($this->getExit()) {
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a redirect to an action/controller/module with params, forcing an immdiate exit
|
||||
*
|
||||
* @param mixed $action
|
||||
* @param mixed $controller
|
||||
* @param mixed $module
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function gotoSimpleAndExit($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
$this->setGotoSimple($action, $controller, $module, $params);
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a route-based URL
|
||||
*
|
||||
* Uses route's assemble method tobuild the URL; route is specified by $name;
|
||||
* default route is used if none provided.
|
||||
*
|
||||
* @param array $urlOptions Array of key/value pairs used to assemble URL
|
||||
* @param string $name
|
||||
* @param boolean $reset
|
||||
* @param boolean $encode
|
||||
* @return void
|
||||
*/
|
||||
public function gotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
|
||||
{
|
||||
$this->setGotoRoute($urlOptions, $name, $reset, $encode);
|
||||
|
||||
if ($this->getExit()) {
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a route-based URL, and immediately exit
|
||||
*
|
||||
* Uses route's assemble method tobuild the URL; route is specified by $name;
|
||||
* default route is used if none provided.
|
||||
*
|
||||
* @param array $urlOptions Array of key/value pairs used to assemble URL
|
||||
* @param string $name
|
||||
* @param boolean $reset
|
||||
* @return void
|
||||
*/
|
||||
public function gotoRouteAndExit(array $urlOptions = array(), $name = null, $reset = false)
|
||||
{
|
||||
$this->setGotoRoute($urlOptions, $name, $reset);
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a redirect to a url
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function gotoUrl($url, array $options = array())
|
||||
{
|
||||
$this->setGotoUrl($url, $options);
|
||||
|
||||
if ($this->getExit()) {
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a URL string for a redirect, perform redirect, and immediately exit
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function gotoUrlAndExit($url, array $options = array())
|
||||
{
|
||||
$this->gotoUrl($url, $options);
|
||||
$this->redirectAndExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* exit(): Perform exit for redirector
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function redirectAndExit()
|
||||
{
|
||||
if ($this->getCloseSessionOnExit()) {
|
||||
// Close session, if started
|
||||
if (class_exists('Zend_Session', false) && Zend_Session::isStarted()) {
|
||||
Zend_Session::writeClose();
|
||||
} elseif (isset($_SESSION)) {
|
||||
session_write_close();
|
||||
}
|
||||
}
|
||||
|
||||
$this->getResponse()->sendHeaders();
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* direct(): Perform helper when called as
|
||||
* $this->_helper->redirector($action, $controller, $module, $params)
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function direct($action, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
$this->gotoSimple($action, $controller, $module, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading
|
||||
*
|
||||
* Overloading for old 'goto', 'setGoto', and 'gotoAndExit' methods
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
* @throws Zend_Controller_Action_Exception for invalid methods
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$method = strtolower($method);
|
||||
if ('goto' == $method) {
|
||||
return call_user_func_array(array($this, 'gotoSimple'), $args);
|
||||
}
|
||||
if ('setgoto' == $method) {
|
||||
return call_user_func_array(array($this, 'setGotoSimple'), $args);
|
||||
}
|
||||
if ('gotoandexit' == $method) {
|
||||
return call_user_func_array(array($this, 'gotoSimpleAndExit'), $args);
|
||||
}
|
||||
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception(sprintf('Invalid method "%s" called on redirector', $method));
|
||||
}
|
||||
}
|
117
airtime_mvc/library/Zend/Controller/Action/Helper/Url.php
Normal file
117
airtime_mvc/library/Zend/Controller/Action/Helper/Url.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Url.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for creating URLs for redirects and other tasks
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_Url extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Create URL based on default route
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function simple($action, $controller = null, $module = null, array $params = null)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if (null === $controller) {
|
||||
$controller = $request->getControllerName();
|
||||
}
|
||||
|
||||
if (null === $module) {
|
||||
$module = $request->getModuleName();
|
||||
}
|
||||
|
||||
$url = $controller . '/' . $action;
|
||||
if ($module != $this->getFrontController()->getDispatcher()->getDefaultModule()) {
|
||||
$url = $module . '/' . $url;
|
||||
}
|
||||
|
||||
if ('' !== ($baseUrl = $this->getFrontController()->getBaseUrl())) {
|
||||
$url = $baseUrl . '/' . $url;
|
||||
}
|
||||
|
||||
if (null !== $params) {
|
||||
$paramPairs = array();
|
||||
foreach ($params as $key => $value) {
|
||||
$paramPairs[] = urlencode($key) . '/' . urlencode($value);
|
||||
}
|
||||
$paramString = implode('/', $paramPairs);
|
||||
$url .= '/' . $paramString;
|
||||
}
|
||||
|
||||
$url = '/' . ltrim($url, '/');
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a URL based on a given route
|
||||
*
|
||||
* This method will typically be used for more complex operations, as it
|
||||
* ties into the route objects registered with the router.
|
||||
*
|
||||
* @param array $urlOptions Options passed to the assemble method of the Route object.
|
||||
* @param mixed $name The name of a Route to use. If null it will use the current Route
|
||||
* @param boolean $reset
|
||||
* @param boolean $encode
|
||||
* @return string Url for the link href attribute.
|
||||
*/
|
||||
public function url($urlOptions = array(), $name = null, $reset = false, $encode = true)
|
||||
{
|
||||
$router = $this->getFrontController()->getRouter();
|
||||
return $router->assemble($urlOptions, $name, $reset, $encode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform helper when called as $this->_helper->url() from an action controller
|
||||
*
|
||||
* Proxies to {@link simple()}
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function direct($action, $controller = null, $module = null, array $params = null)
|
||||
{
|
||||
return $this->simple($action, $controller, $module, $params);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,989 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ViewRenderer.php 20261 2010-01-13 18:55:25Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_View
|
||||
*/
|
||||
require_once 'Zend/View.php';
|
||||
|
||||
/**
|
||||
* View script integration
|
||||
*
|
||||
* Zend_Controller_Action_Helper_ViewRenderer provides transparent view
|
||||
* integration for action controllers. It allows you to create a view object
|
||||
* once, and populate it throughout all actions. Several global options may be
|
||||
* set:
|
||||
*
|
||||
* - noController: if set true, render() will not look for view scripts in
|
||||
* subdirectories named after the controller
|
||||
* - viewSuffix: what view script filename suffix to use
|
||||
*
|
||||
* The helper autoinitializes the action controller view preDispatch(). It
|
||||
* determines the path to the class file, and then determines the view base
|
||||
* directory from there. It also uses the module name as a class prefix for
|
||||
* helpers and views such that if your module name is 'Search', it will set the
|
||||
* helper class prefix to 'Search_View_Helper' and the filter class prefix to ;
|
||||
* 'Search_View_Filter'.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* // In your bootstrap:
|
||||
* Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
|
||||
*
|
||||
* // In your action controller methods:
|
||||
* $viewHelper = $this->_helper->getHelper('view');
|
||||
*
|
||||
* // Don't use controller subdirectories
|
||||
* $viewHelper->setNoController(true);
|
||||
*
|
||||
* // Specify a different script to render:
|
||||
* $this->_helper->viewRenderer('form');
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @uses Zend_Controller_Action_Helper_Abstract
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action_Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_View_Interface
|
||||
*/
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* Word delimiters
|
||||
* @var array
|
||||
*/
|
||||
protected $_delimiters;
|
||||
|
||||
/**
|
||||
* @var Zend_Filter_Inflector
|
||||
*/
|
||||
protected $_inflector;
|
||||
|
||||
/**
|
||||
* Inflector target
|
||||
* @var string
|
||||
*/
|
||||
protected $_inflectorTarget = '';
|
||||
|
||||
/**
|
||||
* Current module directory
|
||||
* @var string
|
||||
*/
|
||||
protected $_moduleDir = '';
|
||||
|
||||
/**
|
||||
* Whether or not to autorender using controller name as subdirectory;
|
||||
* global setting (not reset at next invocation)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_neverController = false;
|
||||
|
||||
/**
|
||||
* Whether or not to autorender postDispatch; global setting (not reset at
|
||||
* next invocation)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_neverRender = false;
|
||||
|
||||
/**
|
||||
* Whether or not to use a controller name as a subdirectory when rendering
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_noController = false;
|
||||
|
||||
/**
|
||||
* Whether or not to autorender postDispatch; per controller/action setting (reset
|
||||
* at next invocation)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_noRender = false;
|
||||
|
||||
/**
|
||||
* Characters representing path delimiters in the controller
|
||||
* @var string|array
|
||||
*/
|
||||
protected $_pathDelimiters;
|
||||
|
||||
/**
|
||||
* Which named segment of the response to utilize
|
||||
* @var string
|
||||
*/
|
||||
protected $_responseSegment = null;
|
||||
|
||||
/**
|
||||
* Which action view script to render
|
||||
* @var string
|
||||
*/
|
||||
protected $_scriptAction = null;
|
||||
|
||||
/**
|
||||
* View object basePath
|
||||
* @var string
|
||||
*/
|
||||
protected $_viewBasePathSpec = ':moduleDir/views';
|
||||
|
||||
/**
|
||||
* View script path specification string
|
||||
* @var string
|
||||
*/
|
||||
protected $_viewScriptPathSpec = ':controller/:action.:suffix';
|
||||
|
||||
/**
|
||||
* View script path specification string, minus controller segment
|
||||
* @var string
|
||||
*/
|
||||
protected $_viewScriptPathNoControllerSpec = ':action.:suffix';
|
||||
|
||||
/**
|
||||
* View script suffix
|
||||
* @var string
|
||||
*/
|
||||
protected $_viewSuffix = 'phtml';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Optionally set view object and options.
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_View_Interface $view = null, array $options = array())
|
||||
{
|
||||
if (null !== $view) {
|
||||
$this->setView($view);
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
$this->_setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone - also make sure the view is cloned.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
if (isset($this->view) && $this->view instanceof Zend_View_Interface) {
|
||||
$this->view = clone $this->view;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view object
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setView(Zend_View_Interface $view)
|
||||
{
|
||||
$this->view = $view;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current module name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModule()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$module = $request->getModuleName();
|
||||
if (null === $module) {
|
||||
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
|
||||
}
|
||||
|
||||
return $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module directory
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleDirectory()
|
||||
{
|
||||
$module = $this->getModule();
|
||||
$moduleDir = $this->getFrontController()->getControllerDirectory($module);
|
||||
if ((null === $moduleDir) || is_array($moduleDir)) {
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('ViewRenderer cannot locate module directory for module "' . $module . '"');
|
||||
}
|
||||
$this->_moduleDir = dirname($moduleDir);
|
||||
return $this->_moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get inflector
|
||||
*
|
||||
* @return Zend_Filter_Inflector
|
||||
*/
|
||||
public function getInflector()
|
||||
{
|
||||
if (null === $this->_inflector) {
|
||||
/**
|
||||
* @see Zend_Filter_Inflector
|
||||
*/
|
||||
require_once 'Zend/Filter/Inflector.php';
|
||||
/**
|
||||
* @see Zend_Filter_PregReplace
|
||||
*/
|
||||
require_once 'Zend/Filter/PregReplace.php';
|
||||
/**
|
||||
* @see Zend_Filter_Word_UnderscoreToSeparator
|
||||
*/
|
||||
require_once 'Zend/Filter/Word/UnderscoreToSeparator.php';
|
||||
$this->_inflector = new Zend_Filter_Inflector();
|
||||
$this->_inflector->setStaticRuleReference('moduleDir', $this->_moduleDir) // moduleDir must be specified before the less specific 'module'
|
||||
->addRules(array(
|
||||
':module' => array('Word_CamelCaseToDash', 'StringToLower'),
|
||||
':controller' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator('/'), 'StringToLower', new Zend_Filter_PregReplace('/\./', '-')),
|
||||
':action' => array('Word_CamelCaseToDash', new Zend_Filter_PregReplace('#[^a-z0-9' . preg_quote('/', '#') . ']+#i', '-'), 'StringToLower'),
|
||||
))
|
||||
->setStaticRuleReference('suffix', $this->_viewSuffix)
|
||||
->setTargetReference($this->_inflectorTarget);
|
||||
}
|
||||
|
||||
// Ensure that module directory is current
|
||||
$this->getModuleDirectory();
|
||||
|
||||
return $this->_inflector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set inflector
|
||||
*
|
||||
* @param Zend_Filter_Inflector $inflector
|
||||
* @param boolean $reference Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setInflector(Zend_Filter_Inflector $inflector, $reference = false)
|
||||
{
|
||||
$this->_inflector = $inflector;
|
||||
if ($reference) {
|
||||
$this->_inflector->setStaticRuleReference('suffix', $this->_viewSuffix)
|
||||
->setStaticRuleReference('moduleDir', $this->_moduleDir)
|
||||
->setTargetReference($this->_inflectorTarget);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set inflector target
|
||||
*
|
||||
* @param string $target
|
||||
* @return void
|
||||
*/
|
||||
protected function _setInflectorTarget($target)
|
||||
{
|
||||
$this->_inflectorTarget = (string) $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set internal module directory representation
|
||||
*
|
||||
* @param string $dir
|
||||
* @return void
|
||||
*/
|
||||
protected function _setModuleDir($dir)
|
||||
{
|
||||
$this->_moduleDir = (string) $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal module directory representation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getModuleDir()
|
||||
{
|
||||
return $this->_moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a class prefix for helper and filter classes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generateDefaultPrefix()
|
||||
{
|
||||
$default = 'Zend_View';
|
||||
if (null === $this->_actionController) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$class = get_class($this->_actionController);
|
||||
|
||||
if (!strstr($class, '_')) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$module = $this->getModule();
|
||||
if ('default' == $module) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$prefix = substr($class, 0, strpos($class, '_')) . '_View';
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve base path based on location of current action controller
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getBasePath()
|
||||
{
|
||||
if (null === $this->_actionController) {
|
||||
return './views';
|
||||
}
|
||||
|
||||
$inflector = $this->getInflector();
|
||||
$this->_setInflectorTarget($this->getViewBasePathSpec());
|
||||
|
||||
$dispatcher = $this->getFrontController()->getDispatcher();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$parts = array(
|
||||
'module' => (($moduleName = $request->getModuleName()) != '') ? $dispatcher->formatModuleName($moduleName) : $moduleName,
|
||||
'controller' => $request->getControllerName(),
|
||||
'action' => $dispatcher->formatActionName($request->getActionName())
|
||||
);
|
||||
|
||||
$path = $inflector->filter($parts);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
protected function _setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'neverRender':
|
||||
case 'neverController':
|
||||
case 'noController':
|
||||
case 'noRender':
|
||||
$property = '_' . $key;
|
||||
$this->{$property} = ($value) ? true : false;
|
||||
break;
|
||||
case 'responseSegment':
|
||||
case 'scriptAction':
|
||||
case 'viewBasePathSpec':
|
||||
case 'viewScriptPathSpec':
|
||||
case 'viewScriptPathNoControllerSpec':
|
||||
case 'viewSuffix':
|
||||
$property = '_' . $key;
|
||||
$this->{$property} = (string) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the view object
|
||||
*
|
||||
* $options may contain the following keys:
|
||||
* - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls)
|
||||
* - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller
|
||||
* - noRender - flag indicating whether or not to autorender postDispatch()
|
||||
* - responseSegment - which named response segment to render a view script to
|
||||
* - scriptAction - what action script to render
|
||||
* - viewBasePathSpec - specification to use for determining view base path
|
||||
* - viewScriptPathSpec - specification to use for determining view script paths
|
||||
* - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set
|
||||
* - viewSuffix - what view script filename suffix to use
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $prefix
|
||||
* @param array $options
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function initView($path = null, $prefix = null, array $options = array())
|
||||
{
|
||||
if (null === $this->view) {
|
||||
$this->setView(new Zend_View());
|
||||
}
|
||||
|
||||
// Reset some flags every time
|
||||
$options['noController'] = (isset($options['noController'])) ? $options['noController'] : false;
|
||||
$options['noRender'] = (isset($options['noRender'])) ? $options['noRender'] : false;
|
||||
$this->_scriptAction = null;
|
||||
$this->_responseSegment = null;
|
||||
|
||||
// Set options first; may be used to determine other initializations
|
||||
$this->_setOptions($options);
|
||||
|
||||
// Get base view path
|
||||
if (empty($path)) {
|
||||
$path = $this->_getBasePath();
|
||||
if (empty($path)) {
|
||||
/**
|
||||
* @see Zend_Controller_Action_Exception
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('ViewRenderer initialization failed: retrieved view base path is empty');
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $prefix) {
|
||||
$prefix = $this->_generateDefaultPrefix();
|
||||
}
|
||||
|
||||
// Determine if this path has already been registered
|
||||
$currentPaths = $this->view->getScriptPaths();
|
||||
$path = str_replace(array('/', '\\'), '/', $path);
|
||||
$pathExists = false;
|
||||
foreach ($currentPaths as $tmpPath) {
|
||||
$tmpPath = str_replace(array('/', '\\'), '/', $tmpPath);
|
||||
if (strstr($tmpPath, $path)) {
|
||||
$pathExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$pathExists) {
|
||||
$this->view->addBasePath($path, $prefix);
|
||||
}
|
||||
|
||||
// Register view with action controller (unless already registered)
|
||||
if ((null !== $this->_actionController) && (null === $this->_actionController->view)) {
|
||||
$this->_actionController->view = $this->view;
|
||||
$this->_actionController->viewSuffix = $this->_viewSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init - initialize view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($this->getFrontController()->getParam('noViewRenderer')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->initView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set view basePath specification
|
||||
*
|
||||
* Specification can contain one or more of the following:
|
||||
* - :moduleDir - current module directory
|
||||
* - :controller - name of current controller in the request
|
||||
* - :action - name of current action in the request
|
||||
* - :module - name of current module in the request
|
||||
*
|
||||
* @param string $path
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setViewBasePathSpec($path)
|
||||
{
|
||||
$this->_viewBasePathSpec = (string) $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current view basePath specification string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewBasePathSpec()
|
||||
{
|
||||
return $this->_viewBasePathSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set view script path specification
|
||||
*
|
||||
* Specification can contain one or more of the following:
|
||||
* - :moduleDir - current module directory
|
||||
* - :controller - name of current controller in the request
|
||||
* - :action - name of current action in the request
|
||||
* - :module - name of current module in the request
|
||||
*
|
||||
* @param string $path
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setViewScriptPathSpec($path)
|
||||
{
|
||||
$this->_viewScriptPathSpec = (string) $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current view script path specification string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewScriptPathSpec()
|
||||
{
|
||||
return $this->_viewScriptPathSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set view script path specification (no controller variant)
|
||||
*
|
||||
* Specification can contain one or more of the following:
|
||||
* - :moduleDir - current module directory
|
||||
* - :controller - name of current controller in the request
|
||||
* - :action - name of current action in the request
|
||||
* - :module - name of current module in the request
|
||||
*
|
||||
* :controller will likely be ignored in this variant.
|
||||
*
|
||||
* @param string $path
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setViewScriptPathNoControllerSpec($path)
|
||||
{
|
||||
$this->_viewScriptPathNoControllerSpec = (string) $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current view script path specification string (no controller variant)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewScriptPathNoControllerSpec()
|
||||
{
|
||||
return $this->_viewScriptPathNoControllerSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a view script based on an action and/or other variables
|
||||
*
|
||||
* Uses values found in current request if no values passed in $vars.
|
||||
*
|
||||
* If {@link $_noController} is set, uses {@link $_viewScriptPathNoControllerSpec};
|
||||
* otherwise, uses {@link $_viewScriptPathSpec}.
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $vars
|
||||
* @return string
|
||||
*/
|
||||
public function getViewScript($action = null, array $vars = array())
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if ((null === $action) && (!isset($vars['action']))) {
|
||||
$action = $this->getScriptAction();
|
||||
if (null === $action) {
|
||||
$action = $request->getActionName();
|
||||
}
|
||||
$vars['action'] = $action;
|
||||
} elseif (null !== $action) {
|
||||
$vars['action'] = $action;
|
||||
}
|
||||
|
||||
$inflector = $this->getInflector();
|
||||
if ($this->getNoController() || $this->getNeverController()) {
|
||||
$this->_setInflectorTarget($this->getViewScriptPathNoControllerSpec());
|
||||
} else {
|
||||
$this->_setInflectorTarget($this->getViewScriptPathSpec());
|
||||
}
|
||||
return $this->_translateSpec($vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the neverRender flag (i.e., globally dis/enable autorendering)
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setNeverRender($flag = true)
|
||||
{
|
||||
$this->_neverRender = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve neverRender flag value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getNeverRender()
|
||||
{
|
||||
return $this->_neverRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the noRender flag (i.e., whether or not to autorender)
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setNoRender($flag = true)
|
||||
{
|
||||
$this->_noRender = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve noRender flag value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getNoRender()
|
||||
{
|
||||
return $this->_noRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view script to use
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setScriptAction($name)
|
||||
{
|
||||
$this->_scriptAction = (string) $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve view script name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScriptAction()
|
||||
{
|
||||
return $this->_scriptAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response segment name
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setResponseSegment($name)
|
||||
{
|
||||
if (null === $name) {
|
||||
$this->_responseSegment = null;
|
||||
} else {
|
||||
$this->_responseSegment = (string) $name;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve named response segment name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseSegment()
|
||||
{
|
||||
return $this->_responseSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the noController flag (i.e., whether or not to render into controller subdirectories)
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setNoController($flag = true)
|
||||
{
|
||||
$this->_noController = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve noController flag value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getNoController()
|
||||
{
|
||||
return $this->_noController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the neverController flag (i.e., whether or not to render into controller subdirectories)
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setNeverController($flag = true)
|
||||
{
|
||||
$this->_neverController = ($flag) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve neverController flag value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getNeverController()
|
||||
{
|
||||
return $this->_neverController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set view script suffix
|
||||
*
|
||||
* @param string $suffix
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setViewSuffix($suffix)
|
||||
{
|
||||
$this->_viewSuffix = (string) $suffix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view script suffix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewSuffix()
|
||||
{
|
||||
return $this->_viewSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options for rendering a view script
|
||||
*
|
||||
* @param string $action View script to render
|
||||
* @param string $name Response named segment to render to
|
||||
* @param boolean $noController Whether or not to render within a subdirectory named after the controller
|
||||
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
|
||||
*/
|
||||
public function setRender($action = null, $name = null, $noController = null)
|
||||
{
|
||||
if (null !== $action) {
|
||||
$this->setScriptAction($action);
|
||||
}
|
||||
|
||||
if (null !== $name) {
|
||||
$this->setResponseSegment($name);
|
||||
}
|
||||
|
||||
if (null !== $noController) {
|
||||
$this->setNoController($noController);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inflect based on provided vars
|
||||
*
|
||||
* Allowed variables are:
|
||||
* - :moduleDir - current module directory
|
||||
* - :module - current module name
|
||||
* - :controller - current controller name
|
||||
* - :action - current action name
|
||||
* - :suffix - view script file suffix
|
||||
*
|
||||
* @param array $vars
|
||||
* @return string
|
||||
*/
|
||||
protected function _translateSpec(array $vars = array())
|
||||
{
|
||||
$inflector = $this->getInflector();
|
||||
$request = $this->getRequest();
|
||||
$dispatcher = $this->getFrontController()->getDispatcher();
|
||||
$module = $dispatcher->formatModuleName($request->getModuleName());
|
||||
$controller = $request->getControllerName();
|
||||
$action = $dispatcher->formatActionName($request->getActionName());
|
||||
|
||||
$params = compact('module', 'controller', 'action');
|
||||
foreach ($vars as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'module':
|
||||
case 'controller':
|
||||
case 'action':
|
||||
case 'moduleDir':
|
||||
case 'suffix':
|
||||
$params[$key] = (string) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['suffix'])) {
|
||||
$origSuffix = $this->getViewSuffix();
|
||||
$this->setViewSuffix($params['suffix']);
|
||||
}
|
||||
if (isset($params['moduleDir'])) {
|
||||
$origModuleDir = $this->_getModuleDir();
|
||||
$this->_setModuleDir($params['moduleDir']);
|
||||
}
|
||||
|
||||
$filtered = $inflector->filter($params);
|
||||
|
||||
if (isset($params['suffix'])) {
|
||||
$this->setViewSuffix($origSuffix);
|
||||
}
|
||||
if (isset($params['moduleDir'])) {
|
||||
$this->_setModuleDir($origModuleDir);
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a view script (optionally to a named response segment)
|
||||
*
|
||||
* Sets the noRender flag to true when called.
|
||||
*
|
||||
* @param string $script
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function renderScript($script, $name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$name = $this->getResponseSegment();
|
||||
}
|
||||
|
||||
$this->getResponse()->appendBody(
|
||||
$this->view->render($script),
|
||||
$name
|
||||
);
|
||||
|
||||
$this->setNoRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a view based on path specifications
|
||||
*
|
||||
* Renders a view based on the view script path specifications.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $name
|
||||
* @param boolean $noController
|
||||
* @return void
|
||||
*/
|
||||
public function render($action = null, $name = null, $noController = null)
|
||||
{
|
||||
$this->setRender($action, $name, $noController);
|
||||
$path = $this->getViewScript();
|
||||
$this->renderScript($path, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a script based on specification variables
|
||||
*
|
||||
* Pass an action, and one or more specification variables (view script suffix)
|
||||
* to determine the view script path, and render that script.
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $vars
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function renderBySpec($action = null, array $vars = array(), $name = null)
|
||||
{
|
||||
if (null !== $name) {
|
||||
$this->setResponseSegment($name);
|
||||
}
|
||||
|
||||
$path = $this->getViewScript($action, $vars);
|
||||
|
||||
$this->renderScript($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* postDispatch - auto render a view
|
||||
*
|
||||
* Only autorenders if:
|
||||
* - _noRender is false
|
||||
* - action controller is present
|
||||
* - request has not been re-dispatched (i.e., _forward() has not been called)
|
||||
* - response is not a redirect
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch()
|
||||
{
|
||||
if ($this->_shouldRender()) {
|
||||
$this->render();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the ViewRenderer render a view script?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _shouldRender()
|
||||
{
|
||||
return (!$this->getFrontController()->getParam('noViewRenderer')
|
||||
&& !$this->_neverRender
|
||||
&& !$this->_noRender
|
||||
&& (null !== $this->_actionController)
|
||||
&& $this->getRequest()->isDispatched()
|
||||
&& !$this->getResponse()->isRedirect()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this helper as a method; proxies to setRender()
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $name
|
||||
* @param boolean $noController
|
||||
* @return void
|
||||
*/
|
||||
public function direct($action = null, $name = null, $noController = null)
|
||||
{
|
||||
$this->setRender($action, $name, $noController);
|
||||
}
|
||||
}
|
381
airtime_mvc/library/Zend/Controller/Action/HelperBroker.php
Normal file
381
airtime_mvc/library/Zend/Controller/Action/HelperBroker.php
Normal file
|
@ -0,0 +1,381 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HelperBroker.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
require_once 'Zend/Controller/Action/HelperBroker/PriorityStack.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_HelperBroker
|
||||
{
|
||||
/**
|
||||
* $_actionController - ActionController reference
|
||||
*
|
||||
* @var Zend_Controller_Action
|
||||
*/
|
||||
protected $_actionController;
|
||||
|
||||
/**
|
||||
* @var Zend_Loader_PluginLoader_Interface
|
||||
*/
|
||||
protected static $_pluginLoader;
|
||||
|
||||
/**
|
||||
* $_helpers - Helper array
|
||||
*
|
||||
* @var Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
protected static $_stack = null;
|
||||
|
||||
/**
|
||||
* Set PluginLoader for use with broker
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface $loader
|
||||
* @return void
|
||||
*/
|
||||
public static function setPluginLoader($loader)
|
||||
{
|
||||
if ((null !== $loader) && (!$loader instanceof Zend_Loader_PluginLoader_Interface)) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Invalid plugin loader provided to HelperBroker');
|
||||
}
|
||||
self::$_pluginLoader = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve PluginLoader
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader
|
||||
*/
|
||||
public static function getPluginLoader()
|
||||
{
|
||||
if (null === self::$_pluginLoader) {
|
||||
require_once 'Zend/Loader/PluginLoader.php';
|
||||
self::$_pluginLoader = new Zend_Loader_PluginLoader(array(
|
||||
'Zend_Controller_Action_Helper' => 'Zend/Controller/Action/Helper/',
|
||||
));
|
||||
}
|
||||
return self::$_pluginLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* addPrefix() - Add repository of helpers by prefix
|
||||
*
|
||||
* @param string $prefix
|
||||
*/
|
||||
static public function addPrefix($prefix)
|
||||
{
|
||||
$prefix = rtrim($prefix, '_');
|
||||
$path = str_replace('_', DIRECTORY_SEPARATOR, $prefix);
|
||||
self::getPluginLoader()->addPrefixPath($prefix, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* addPath() - Add path to repositories where Action_Helpers could be found.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $prefix Optional; defaults to 'Zend_Controller_Action_Helper'
|
||||
* @return void
|
||||
*/
|
||||
static public function addPath($path, $prefix = 'Zend_Controller_Action_Helper')
|
||||
{
|
||||
self::getPluginLoader()->addPrefixPath($prefix, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* addHelper() - Add helper objects
|
||||
*
|
||||
* @param Zend_Controller_Action_Helper_Abstract $helper
|
||||
* @return void
|
||||
*/
|
||||
static public function addHelper(Zend_Controller_Action_Helper_Abstract $helper)
|
||||
{
|
||||
self::getStack()->push($helper);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* resetHelpers()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function resetHelpers()
|
||||
{
|
||||
self::$_stack = null;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve or initialize a helper statically
|
||||
*
|
||||
* Retrieves a helper object statically, loading on-demand if the helper
|
||||
* does not already exist in the stack. Always returns a helper, unless
|
||||
* the helper class cannot be found.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public static function getStaticHelper($name)
|
||||
{
|
||||
$name = self::_normalizeHelperName($name);
|
||||
$stack = self::getStack();
|
||||
|
||||
if (!isset($stack->{$name})) {
|
||||
self::_loadHelper($name);
|
||||
}
|
||||
|
||||
return $stack->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* getExistingHelper() - get helper by name
|
||||
*
|
||||
* Static method to retrieve helper object. Only retrieves helpers already
|
||||
* initialized with the broker (either via addHelper() or on-demand loading
|
||||
* via getHelper()).
|
||||
*
|
||||
* Throws an exception if the referenced helper does not exist in the
|
||||
* stack; use {@link hasHelper()} to check if the helper is registered
|
||||
* prior to retrieving it.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
*/
|
||||
public static function getExistingHelper($name)
|
||||
{
|
||||
$name = self::_normalizeHelperName($name);
|
||||
$stack = self::getStack();
|
||||
|
||||
if (!isset($stack->{$name})) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Action helper "' . $name . '" has not been registered with the helper broker');
|
||||
}
|
||||
|
||||
return $stack->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all registered helpers as helper => object pairs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getExistingHelpers()
|
||||
{
|
||||
return self::getStack()->getHelpersByName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a particular helper loaded in the broker?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasHelper($name)
|
||||
{
|
||||
$name = self::_normalizeHelperName($name);
|
||||
return isset(self::getStack()->{$name});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a particular helper from the broker
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public static function removeHelper($name)
|
||||
{
|
||||
$name = self::_normalizeHelperName($name);
|
||||
$stack = self::getStack();
|
||||
if (isset($stack->{$name})) {
|
||||
unset($stack->{$name});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy load the priority stack and return it
|
||||
*
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public static function getStack()
|
||||
{
|
||||
if (self::$_stack == null) {
|
||||
self::$_stack = new Zend_Controller_Action_HelperBroker_PriorityStack();
|
||||
}
|
||||
|
||||
return self::$_stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Controller_Action $actionController
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Controller_Action $actionController)
|
||||
{
|
||||
$this->_actionController = $actionController;
|
||||
foreach (self::getStack() as $helper) {
|
||||
$helper->setActionController($actionController);
|
||||
$helper->init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* notifyPreDispatch() - called by action controller dispatch method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notifyPreDispatch()
|
||||
{
|
||||
foreach (self::getStack() as $helper) {
|
||||
$helper->preDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* notifyPostDispatch() - called by action controller dispatch method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notifyPostDispatch()
|
||||
{
|
||||
foreach (self::getStack() as $helper) {
|
||||
$helper->postDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getHelper() - get helper by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function getHelper($name)
|
||||
{
|
||||
$name = self::_normalizeHelperName($name);
|
||||
$stack = self::getStack();
|
||||
|
||||
if (!isset($stack->{$name})) {
|
||||
self::_loadHelper($name);
|
||||
}
|
||||
|
||||
$helper = $stack->{$name};
|
||||
|
||||
$initialize = false;
|
||||
if (null === ($actionController = $helper->getActionController())) {
|
||||
$initialize = true;
|
||||
} elseif ($actionController !== $this->_actionController) {
|
||||
$initialize = true;
|
||||
}
|
||||
|
||||
if ($initialize) {
|
||||
$helper->setActionController($this->_actionController)
|
||||
->init();
|
||||
}
|
||||
|
||||
return $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method overloading
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
* @throws Zend_Controller_Action_Exception if helper does not have a direct() method
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$helper = $this->getHelper($method);
|
||||
if (!method_exists($helper, 'direct')) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Helper "' . $method . '" does not support overloading via direct()');
|
||||
}
|
||||
return call_user_func_array(array($helper, 'direct'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve helper by name as object property
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->getHelper($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize helper name for lookups
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected static function _normalizeHelperName($name)
|
||||
{
|
||||
if (strpos($name, '_') !== false) {
|
||||
$name = str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
|
||||
}
|
||||
|
||||
return ucfirst($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a helper
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
protected static function _loadHelper($name)
|
||||
{
|
||||
try {
|
||||
$class = self::getPluginLoader()->load($name);
|
||||
} catch (Zend_Loader_PluginLoader_Exception $e) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Action Helper by name ' . $name . ' not found', 0, $e);
|
||||
}
|
||||
|
||||
$helper = new $class();
|
||||
|
||||
if (!$helper instanceof Zend_Controller_Action_Helper_Abstract) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('Helper name ' . $name . ' -> class ' . $class . ' is not of type Zend_Controller_Action_Helper_Abstract');
|
||||
}
|
||||
|
||||
self::getStack()->push($helper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: PriorityStack.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Action_HelperBroker_PriorityStack implements IteratorAggregate, ArrayAccess, Countable
|
||||
{
|
||||
|
||||
protected $_helpersByPriority = array();
|
||||
protected $_helpersByNameRef = array();
|
||||
protected $_nextDefaultPriority = 1;
|
||||
|
||||
/**
|
||||
* Magic property overloading for returning helper by name
|
||||
*
|
||||
* @param string $helperName The helper name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function __get($helperName)
|
||||
{
|
||||
if (!array_key_exists($helperName, $this->_helpersByNameRef)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_helpersByNameRef[$helperName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic property overloading for returning if helper is set by name
|
||||
*
|
||||
* @param string $helperName The helper name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function __isset($helperName)
|
||||
{
|
||||
return array_key_exists($helperName, $this->_helpersByNameRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic property overloading for unsetting if helper is exists by name
|
||||
*
|
||||
* @param string $helperName The helper name
|
||||
* @return Zend_Controller_Action_Helper_Abstract
|
||||
*/
|
||||
public function __unset($helperName)
|
||||
{
|
||||
return $this->offsetUnset($helperName);
|
||||
}
|
||||
|
||||
/**
|
||||
* push helper onto the stack
|
||||
*
|
||||
* @param Zend_Controller_Action_Helper_Abstract $helper
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public function push(Zend_Controller_Action_Helper_Abstract $helper)
|
||||
{
|
||||
$this->offsetSet($this->getNextFreeHigherPriority(), $helper);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return something iterable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayObject($this->_helpersByPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* offsetExists()
|
||||
*
|
||||
* @param int|string $priorityOrHelperName
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public function offsetExists($priorityOrHelperName)
|
||||
{
|
||||
if (is_string($priorityOrHelperName)) {
|
||||
return array_key_exists($priorityOrHelperName, $this->_helpersByNameRef);
|
||||
} else {
|
||||
return array_key_exists($priorityOrHelperName, $this->_helpersByPriority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* offsetGet()
|
||||
*
|
||||
* @param int|string $priorityOrHelperName
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public function offsetGet($priorityOrHelperName)
|
||||
{
|
||||
if (!$this->offsetExists($priorityOrHelperName)) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('A helper with priority ' . $priorityOrHelperName . ' does not exist.');
|
||||
}
|
||||
|
||||
if (is_string($priorityOrHelperName)) {
|
||||
return $this->_helpersByNameRef[$priorityOrHelperName];
|
||||
} else {
|
||||
return $this->_helpersByPriority[$priorityOrHelperName];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* offsetSet()
|
||||
*
|
||||
* @param int $priority
|
||||
* @param Zend_Controller_Action_Helper_Abstract $helper
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public function offsetSet($priority, $helper)
|
||||
{
|
||||
$priority = (int) $priority;
|
||||
|
||||
if (!$helper instanceof Zend_Controller_Action_Helper_Abstract) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('$helper must extend Zend_Controller_Action_Helper_Abstract.');
|
||||
}
|
||||
|
||||
if (array_key_exists($helper->getName(), $this->_helpersByNameRef)) {
|
||||
// remove any object with the same name to retain BC compailitbility
|
||||
// @todo At ZF 2.0 time throw an exception here.
|
||||
$this->offsetUnset($helper->getName());
|
||||
}
|
||||
|
||||
if (array_key_exists($priority, $this->_helpersByPriority)) {
|
||||
$priority = $this->getNextFreeHigherPriority($priority); // ensures LIFO
|
||||
trigger_error("A helper with the same priority already exists, reassigning to $priority", E_USER_WARNING);
|
||||
}
|
||||
|
||||
$this->_helpersByPriority[$priority] = $helper;
|
||||
$this->_helpersByNameRef[$helper->getName()] = $helper;
|
||||
|
||||
if ($priority == ($nextFreeDefault = $this->getNextFreeHigherPriority($this->_nextDefaultPriority))) {
|
||||
$this->_nextDefaultPriority = $nextFreeDefault;
|
||||
}
|
||||
|
||||
krsort($this->_helpersByPriority); // always make sure priority and LIFO are both enforced
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* offsetUnset()
|
||||
*
|
||||
* @param int|string $priorityOrHelperName Priority integer or the helper name
|
||||
* @return Zend_Controller_Action_HelperBroker_PriorityStack
|
||||
*/
|
||||
public function offsetUnset($priorityOrHelperName)
|
||||
{
|
||||
if (!$this->offsetExists($priorityOrHelperName)) {
|
||||
require_once 'Zend/Controller/Action/Exception.php';
|
||||
throw new Zend_Controller_Action_Exception('A helper with priority or name ' . $priorityOrHelperName . ' does not exist.');
|
||||
}
|
||||
|
||||
if (is_string($priorityOrHelperName)) {
|
||||
$helperName = $priorityOrHelperName;
|
||||
$helper = $this->_helpersByNameRef[$helperName];
|
||||
$priority = array_search($helper, $this->_helpersByPriority, true);
|
||||
} else {
|
||||
$priority = $priorityOrHelperName;
|
||||
$helperName = $this->_helpersByPriority[$priorityOrHelperName]->getName();
|
||||
}
|
||||
|
||||
unset($this->_helpersByNameRef[$helperName]);
|
||||
unset($this->_helpersByPriority[$priority]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the count of helpers
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->_helpersByPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next free higher priority. If an index is given, it will
|
||||
* find the next free highest priority after it.
|
||||
*
|
||||
* @param int $indexPriority OPTIONAL
|
||||
* @return int
|
||||
*/
|
||||
public function getNextFreeHigherPriority($indexPriority = null)
|
||||
{
|
||||
if ($indexPriority == null) {
|
||||
$indexPriority = $this->_nextDefaultPriority;
|
||||
}
|
||||
|
||||
$priorities = array_keys($this->_helpersByPriority);
|
||||
|
||||
while (in_array($indexPriority, $priorities)) {
|
||||
$indexPriority++;
|
||||
}
|
||||
|
||||
return $indexPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next free lower priority. If an index is given, it will
|
||||
* find the next free lower priority before it.
|
||||
*
|
||||
* @param int $indexPriority
|
||||
* @return int
|
||||
*/
|
||||
public function getNextFreeLowerPriority($indexPriority = null)
|
||||
{
|
||||
if ($indexPriority == null) {
|
||||
$indexPriority = $this->_nextDefaultPriority;
|
||||
}
|
||||
|
||||
$priorities = array_keys($this->_helpersByPriority);
|
||||
|
||||
while (in_array($indexPriority, $priorities)) {
|
||||
$indexPriority--;
|
||||
}
|
||||
|
||||
return $indexPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the highest priority
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHighestPriority()
|
||||
{
|
||||
return max(array_keys($this->_helpersByPriority));
|
||||
}
|
||||
|
||||
/**
|
||||
* return the lowest priority
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLowestPriority()
|
||||
{
|
||||
return min(array_keys($this->_helpersByPriority));
|
||||
}
|
||||
|
||||
/**
|
||||
* return the helpers referenced by name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHelpersByName()
|
||||
{
|
||||
return $this->_helpersByNameRef;
|
||||
}
|
||||
|
||||
}
|
69
airtime_mvc/library/Zend/Controller/Action/Interface.php
Normal file
69
airtime_mvc/library/Zend/Controller/Action/Interface.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Action
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Controller_Action_Interface
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* The request and response objects should be registered with the
|
||||
* controller, as should be any additional optional arguments; these will be
|
||||
* available via {@link getRequest()}, {@link getResponse()}, and
|
||||
* {@link getInvokeArgs()}, respectively.
|
||||
*
|
||||
* When overriding the constructor, please consider this usage as a best
|
||||
* practice and ensure that each is registered appropriately; the easiest
|
||||
* way to do so is to simply call parent::__construct($request, $response,
|
||||
* $invokeArgs).
|
||||
*
|
||||
* After the request, response, and invokeArgs are set, the
|
||||
* {@link $_helper helper broker} is initialized.
|
||||
*
|
||||
* Finally, {@link init()} is called as the final action of
|
||||
* instantiation, and may be safely overridden to perform initialization
|
||||
* tasks; as a general rule, override {@link init()} instead of the
|
||||
* constructor to customize an action controller's instantiation.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @param array $invokeArgs Any additional invocation arguments
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Controller_Request_Abstract $request,
|
||||
Zend_Controller_Response_Abstract $response,
|
||||
array $invokeArgs = array());
|
||||
|
||||
/**
|
||||
* Dispatch the requested action
|
||||
*
|
||||
* @param string $action Method name of action
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch($action);
|
||||
}
|
440
airtime_mvc/library/Zend/Controller/Dispatcher/Abstract.php
Normal file
440
airtime_mvc/library/Zend/Controller/Dispatcher/Abstract.php
Normal file
|
@ -0,0 +1,440 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Dispatcher_Interface */
|
||||
require_once 'Zend/Controller/Dispatcher/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Dispatcher_Abstract implements Zend_Controller_Dispatcher_Interface
|
||||
{
|
||||
/**
|
||||
* Default action
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultAction = 'index';
|
||||
|
||||
/**
|
||||
* Default controller
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultController = 'index';
|
||||
|
||||
/**
|
||||
* Default module
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultModule = 'default';
|
||||
|
||||
/**
|
||||
* Front Controller instance
|
||||
* @var Zend_Controller_Front
|
||||
*/
|
||||
protected $_frontController;
|
||||
|
||||
/**
|
||||
* Array of invocation parameters to use when instantiating action
|
||||
* controllers
|
||||
* @var array
|
||||
*/
|
||||
protected $_invokeParams = array();
|
||||
|
||||
/**
|
||||
* Path delimiter character
|
||||
* @var string
|
||||
*/
|
||||
protected $_pathDelimiter = '_';
|
||||
|
||||
/**
|
||||
* Response object to pass to action controllers, if any
|
||||
* @var Zend_Controller_Response_Abstract|null
|
||||
*/
|
||||
protected $_response = null;
|
||||
|
||||
/**
|
||||
* Word delimiter characters
|
||||
* @var array
|
||||
*/
|
||||
protected $_wordDelimiter = array('-', '.');
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $params = array())
|
||||
{
|
||||
$this->setParams($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string into a controller name. This is used to take a raw
|
||||
* controller name, such as one stored inside a Zend_Controller_Request_Abstract
|
||||
* object, and reformat it to a proper class name that a class extending
|
||||
* Zend_Controller_Action would use.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatControllerName($unformatted)
|
||||
{
|
||||
return ucfirst($this->_formatName($unformatted)) . 'Controller';
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string into an action name. This is used to take a raw
|
||||
* action name, such as one that would be stored inside a Zend_Controller_Request_Abstract
|
||||
* object, and reformat into a proper method name that would be found
|
||||
* inside a class extending Zend_Controller_Action.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatActionName($unformatted)
|
||||
{
|
||||
$formatted = $this->_formatName($unformatted, true);
|
||||
return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action';
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify delimiter
|
||||
*
|
||||
* Verify a delimiter to use in controllers or actions. May be a single
|
||||
* string or an array of strings.
|
||||
*
|
||||
* @param string|array $spec
|
||||
* @return array
|
||||
* @throws Zend_Controller_Dispatcher_Exception with invalid delimiters
|
||||
*/
|
||||
public function _verifyDelimiter($spec)
|
||||
{
|
||||
if (is_string($spec)) {
|
||||
return (array) $spec;
|
||||
} elseif (is_array($spec)) {
|
||||
$allStrings = true;
|
||||
foreach ($spec as $delim) {
|
||||
if (!is_string($delim)) {
|
||||
$allStrings = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allStrings) {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Word delimiter array must contain only strings');
|
||||
}
|
||||
|
||||
return $spec;
|
||||
}
|
||||
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Invalid word delimiter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the word delimiter character(s) used in
|
||||
* controller or action names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWordDelimiter()
|
||||
{
|
||||
return $this->_wordDelimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set word delimiter
|
||||
*
|
||||
* Set the word delimiter to use in controllers and actions. May be a
|
||||
* single string or an array of strings.
|
||||
*
|
||||
* @param string|array $spec
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setWordDelimiter($spec)
|
||||
{
|
||||
$spec = $this->_verifyDelimiter($spec);
|
||||
$this->_wordDelimiter = $spec;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the path delimiter character(s) used in
|
||||
* controller names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPathDelimiter()
|
||||
{
|
||||
return $this->_pathDelimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path delimiter
|
||||
*
|
||||
* Set the path delimiter to use in controllers. May be a single string or
|
||||
* an array of strings.
|
||||
*
|
||||
* @param string $spec
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setPathDelimiter($spec)
|
||||
{
|
||||
if (!is_string($spec)) {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Invalid path delimiter');
|
||||
}
|
||||
$this->_pathDelimiter = $spec;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string from a URI into a PHP-friendly name.
|
||||
*
|
||||
* By default, replaces words separated by the word separator character(s)
|
||||
* with camelCaps. If $isAction is false, it also preserves replaces words
|
||||
* separated by the path separation character with an underscore, making
|
||||
* the following word Title cased. All non-alphanumeric characters are
|
||||
* removed.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @param boolean $isAction Defaults to false
|
||||
* @return string
|
||||
*/
|
||||
protected function _formatName($unformatted, $isAction = false)
|
||||
{
|
||||
// preserve directories
|
||||
if (!$isAction) {
|
||||
$segments = explode($this->getPathDelimiter(), $unformatted);
|
||||
} else {
|
||||
$segments = (array) $unformatted;
|
||||
}
|
||||
|
||||
foreach ($segments as $key => $segment) {
|
||||
$segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment));
|
||||
$segment = preg_replace('/[^a-z0-9 ]/', '', $segment);
|
||||
$segments[$key] = str_replace(' ', '', ucwords($segment));
|
||||
}
|
||||
|
||||
return implode('_', $segments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve front controller instance
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController()
|
||||
{
|
||||
if (null === $this->_frontController) {
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
$this->_frontController = Zend_Controller_Front::getInstance();
|
||||
}
|
||||
|
||||
return $this->_frontController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set front controller instance
|
||||
*
|
||||
* @param Zend_Controller_Front $controller
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setFrontController(Zend_Controller_Front $controller)
|
||||
{
|
||||
$this->_frontController = $controller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or modify a parameter to use when instantiating an action controller
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
$name = (string) $name;
|
||||
$this->_invokeParams[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameters to pass to action controller constructors
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
$this->_invokeParams = array_merge($this->_invokeParams, $params);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single parameter from the controller parameter stack
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name)
|
||||
{
|
||||
if(isset($this->_invokeParams[$name])) {
|
||||
return $this->_invokeParams[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve action controller instantiation parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_invokeParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the controller parameter stack
|
||||
*
|
||||
* By default, clears all parameters. If a parameter name is given, clears
|
||||
* only that parameter; if an array of parameter names is provided, clears
|
||||
* each.
|
||||
*
|
||||
* @param null|string|array single key or array of keys for params to clear
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function clearParams($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$this->_invokeParams = array();
|
||||
} elseif (is_string($name) && isset($this->_invokeParams[$name])) {
|
||||
unset($this->_invokeParams[$name]);
|
||||
} elseif (is_array($name)) {
|
||||
foreach ($name as $key) {
|
||||
if (is_string($key) && isset($this->_invokeParams[$key])) {
|
||||
unset($this->_invokeParams[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response object to pass to action controllers
|
||||
*
|
||||
* @param Zend_Controller_Response_Abstract|null $response
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Abstract $response = null)
|
||||
{
|
||||
$this->_response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract|null
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default controller (minus any formatting)
|
||||
*
|
||||
* @param string $controller
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setDefaultControllerName($controller)
|
||||
{
|
||||
$this->_defaultController = (string) $controller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default controller name (minus formatting)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultControllerName()
|
||||
{
|
||||
return $this->_defaultController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default action (minus any formatting)
|
||||
*
|
||||
* @param string $action
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setDefaultAction($action)
|
||||
{
|
||||
$this->_defaultAction = (string) $action;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default action name (minus formatting)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultAction()
|
||||
{
|
||||
return $this->_defaultAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default module
|
||||
*
|
||||
* @param string $module
|
||||
* @return Zend_Controller_Dispatcher_Abstract
|
||||
*/
|
||||
public function setDefaultModule($module)
|
||||
{
|
||||
$this->_defaultModule = (string) $module;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default module
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultModule()
|
||||
{
|
||||
return $this->_defaultModule;
|
||||
}
|
||||
}
|
37
airtime_mvc/library/Zend/Controller/Dispatcher/Exception.php
Normal file
37
airtime_mvc/library/Zend/Controller/Dispatcher/Exception.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Exception */
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Dispatcher_Exception extends Zend_Controller_Exception
|
||||
{}
|
||||
|
206
airtime_mvc/library/Zend/Controller/Dispatcher/Interface.php
Normal file
206
airtime_mvc/library/Zend/Controller/Dispatcher/Interface.php
Normal file
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Controller_Request_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Request/Abstract.php';
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Response/Abstract.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Controller_Dispatcher_Interface
|
||||
{
|
||||
/**
|
||||
* Formats a string into a controller name. This is used to take a raw
|
||||
* controller name, such as one that would be packaged inside a request
|
||||
* object, and reformat it to a proper class name that a class extending
|
||||
* Zend_Controller_Action would use.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatControllerName($unformatted);
|
||||
|
||||
/**
|
||||
* Formats a string into a module name. This is used to take a raw
|
||||
* module name, such as one that would be packaged inside a request
|
||||
* object, and reformat it to a proper directory/class name that a class extending
|
||||
* Zend_Controller_Action would use.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatModuleName($unformatted);
|
||||
|
||||
/**
|
||||
* Formats a string into an action name. This is used to take a raw
|
||||
* action name, such as one that would be packaged inside a request
|
||||
* object, and reformat into a proper method name that would be found
|
||||
* inside a class extending Zend_Controller_Action.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatActionName($unformatted);
|
||||
|
||||
/**
|
||||
* Returns TRUE if an action can be dispatched, or FALSE otherwise.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDispatchable(Zend_Controller_Request_Abstract $request);
|
||||
|
||||
/**
|
||||
* Add or modify a parameter with which to instantiate an Action Controller
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public function setParam($name, $value);
|
||||
|
||||
/**
|
||||
* Set an array of a parameters to pass to the Action Controller constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public function setParams(array $params);
|
||||
|
||||
/**
|
||||
* Retrieve a single parameter from the controller parameter stack
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name);
|
||||
|
||||
/**
|
||||
* Retrieve the parameters to pass to the Action Controller constructor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams();
|
||||
|
||||
/**
|
||||
* Clear the controller parameter stack
|
||||
*
|
||||
* By default, clears all parameters. If a parameter name is given, clears
|
||||
* only that parameter; if an array of parameter names is provided, clears
|
||||
* each.
|
||||
*
|
||||
* @param null|string|array single key or array of keys for params to clear
|
||||
* @return Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public function clearParams($name = null);
|
||||
|
||||
/**
|
||||
* Set the response object to use, if any
|
||||
*
|
||||
* @param Zend_Controller_Response_Abstract|null $response
|
||||
* @return void
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Abstract $response = null);
|
||||
|
||||
/**
|
||||
* Retrieve the response object, if any
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract|null
|
||||
*/
|
||||
public function getResponse();
|
||||
|
||||
/**
|
||||
* Add a controller directory to the controller directory stack
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $args
|
||||
* @return Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public function addControllerDirectory($path, $args = null);
|
||||
|
||||
/**
|
||||
* Set the directory where controller files are stored
|
||||
*
|
||||
* Specify a string or an array; if an array is specified, all paths will be
|
||||
* added.
|
||||
*
|
||||
* @param string|array $dir
|
||||
* @return Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public function setControllerDirectory($path);
|
||||
|
||||
/**
|
||||
* Return the currently set directory(ies) for controller file lookup
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getControllerDirectory();
|
||||
|
||||
/**
|
||||
* Dispatches a request object to a controller/action. If the action
|
||||
* requests a forward to another action, a new request will be returned.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response);
|
||||
|
||||
/**
|
||||
* Whether or not a given module is valid
|
||||
*
|
||||
* @param string $module
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValidModule($module);
|
||||
|
||||
/**
|
||||
* Retrieve the default module name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultModule();
|
||||
|
||||
/**
|
||||
* Retrieve the default controller name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultControllerName();
|
||||
|
||||
/**
|
||||
* Retrieve the default action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultAction();
|
||||
}
|
493
airtime_mvc/library/Zend/Controller/Dispatcher/Standard.php
Normal file
493
airtime_mvc/library/Zend/Controller/Dispatcher/Standard.php
Normal file
|
@ -0,0 +1,493 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Standard.php 20244 2010-01-12 21:12:56Z matthew $
|
||||
*/
|
||||
|
||||
/** Zend_Loader */
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/** Zend_Controller_Dispatcher_Abstract */
|
||||
require_once 'Zend/Controller/Dispatcher/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Dispatcher
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abstract
|
||||
{
|
||||
/**
|
||||
* Current dispatchable directory
|
||||
* @var string
|
||||
*/
|
||||
protected $_curDirectory;
|
||||
|
||||
/**
|
||||
* Current module (formatted)
|
||||
* @var string
|
||||
*/
|
||||
protected $_curModule;
|
||||
|
||||
/**
|
||||
* Controller directory(ies)
|
||||
* @var array
|
||||
*/
|
||||
protected $_controllerDirectory = array();
|
||||
|
||||
/**
|
||||
* Constructor: Set current module to default value
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $params = array())
|
||||
{
|
||||
parent::__construct($params);
|
||||
$this->_curModule = $this->getDefaultModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single path to the controller directory stack
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $module
|
||||
* @return Zend_Controller_Dispatcher_Standard
|
||||
*/
|
||||
public function addControllerDirectory($path, $module = null)
|
||||
{
|
||||
if (null === $module) {
|
||||
$module = $this->_defaultModule;
|
||||
}
|
||||
|
||||
$module = (string) $module;
|
||||
$path = rtrim((string) $path, '/\\');
|
||||
|
||||
$this->_controllerDirectory[$module] = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set controller directory
|
||||
*
|
||||
* @param array|string $directory
|
||||
* @return Zend_Controller_Dispatcher_Standard
|
||||
*/
|
||||
public function setControllerDirectory($directory, $module = null)
|
||||
{
|
||||
$this->_controllerDirectory = array();
|
||||
|
||||
if (is_string($directory)) {
|
||||
$this->addControllerDirectory($directory, $module);
|
||||
} elseif (is_array($directory)) {
|
||||
foreach ((array) $directory as $module => $path) {
|
||||
$this->addControllerDirectory($path, $module);
|
||||
}
|
||||
} else {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Controller directory spec must be either a string or an array');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set directories for Zend_Controller_Action class
|
||||
* lookup
|
||||
*
|
||||
* If a module is specified, returns just that directory.
|
||||
*
|
||||
* @param string $module Module name
|
||||
* @return array|string Returns array of all directories by default, single
|
||||
* module directory if module argument provided
|
||||
*/
|
||||
public function getControllerDirectory($module = null)
|
||||
{
|
||||
if (null === $module) {
|
||||
return $this->_controllerDirectory;
|
||||
}
|
||||
|
||||
$module = (string) $module;
|
||||
if (array_key_exists($module, $this->_controllerDirectory)) {
|
||||
return $this->_controllerDirectory[$module];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a controller directory by module name
|
||||
*
|
||||
* @param string $module
|
||||
* @return bool
|
||||
*/
|
||||
public function removeControllerDirectory($module)
|
||||
{
|
||||
$module = (string) $module;
|
||||
if (array_key_exists($module, $this->_controllerDirectory)) {
|
||||
unset($this->_controllerDirectory[$module]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the module name.
|
||||
*
|
||||
* @param string $unformatted
|
||||
* @return string
|
||||
*/
|
||||
public function formatModuleName($unformatted)
|
||||
{
|
||||
if (($this->_defaultModule == $unformatted) && !$this->getParam('prefixDefaultModule')) {
|
||||
return $unformatted;
|
||||
}
|
||||
|
||||
return ucfirst($this->_formatName($unformatted));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format action class name
|
||||
*
|
||||
* @param string $moduleName Name of the current module
|
||||
* @param string $className Name of the action class
|
||||
* @return string Formatted class name
|
||||
*/
|
||||
public function formatClassName($moduleName, $className)
|
||||
{
|
||||
return $this->formatModuleName($moduleName) . '_' . $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a class name to a filename
|
||||
*
|
||||
* @param string $class
|
||||
* @return string
|
||||
*/
|
||||
public function classToFilename($class)
|
||||
{
|
||||
return str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the Zend_Controller_Request_Abstract object can be
|
||||
* dispatched to a controller.
|
||||
*
|
||||
* Use this method wisely. By default, the dispatcher will fall back to the
|
||||
* default controller (either in the module specified or the global default)
|
||||
* if a given controller does not exist. This method returning false does
|
||||
* not necessarily indicate the dispatcher will not still dispatch the call.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $action
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDispatchable(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$className = $this->getControllerClass($request);
|
||||
if (!$className) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (class_exists($className, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$fileSpec = $this->classToFilename($className);
|
||||
$dispatchDir = $this->getDispatchDirectory();
|
||||
$test = $dispatchDir . DIRECTORY_SEPARATOR . $fileSpec;
|
||||
return Zend_Loader::isReadable($test);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch to a controller/action
|
||||
*
|
||||
* By default, if a controller is not dispatchable, dispatch() will throw
|
||||
* an exception. If you wish to use the default controller instead, set the
|
||||
* param 'useDefaultControllerAlways' via {@link setParam()}.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @return void
|
||||
* @throws Zend_Controller_Dispatcher_Exception
|
||||
*/
|
||||
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
|
||||
{
|
||||
$this->setResponse($response);
|
||||
|
||||
/**
|
||||
* Get controller class
|
||||
*/
|
||||
if (!$this->isDispatchable($request)) {
|
||||
$controller = $request->getControllerName();
|
||||
if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
|
||||
}
|
||||
|
||||
$className = $this->getDefaultControllerClass($request);
|
||||
} else {
|
||||
$className = $this->getControllerClass($request);
|
||||
if (!$className) {
|
||||
$className = $this->getDefaultControllerClass($request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the controller class file
|
||||
*/
|
||||
$className = $this->loadClass($className);
|
||||
|
||||
/**
|
||||
* Instantiate controller with request, response, and invocation
|
||||
* arguments; throw exception if it's not an action controller
|
||||
*/
|
||||
$controller = new $className($request, $this->getResponse(), $this->getParams());
|
||||
if (!($controller instanceof Zend_Controller_Action_Interface) &&
|
||||
!($controller instanceof Zend_Controller_Action)) {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception(
|
||||
'Controller "' . $className . '" is not an instance of Zend_Controller_Action_Interface'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the action name
|
||||
*/
|
||||
$action = $this->getActionMethod($request);
|
||||
|
||||
/**
|
||||
* Dispatch the method call
|
||||
*/
|
||||
$request->setDispatched(true);
|
||||
|
||||
// by default, buffer output
|
||||
$disableOb = $this->getParam('disableOutputBuffering');
|
||||
$obLevel = ob_get_level();
|
||||
if (empty($disableOb)) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
try {
|
||||
$controller->dispatch($action);
|
||||
} catch (Exception $e) {
|
||||
// Clean output buffer on error
|
||||
$curObLevel = ob_get_level();
|
||||
if ($curObLevel > $obLevel) {
|
||||
do {
|
||||
ob_get_clean();
|
||||
$curObLevel = ob_get_level();
|
||||
} while ($curObLevel > $obLevel);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (empty($disableOb)) {
|
||||
$content = ob_get_clean();
|
||||
$response->appendBody($content);
|
||||
}
|
||||
|
||||
// Destroy the page controller instance and reflection objects
|
||||
$controller = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a controller class
|
||||
*
|
||||
* Attempts to load the controller class file from
|
||||
* {@link getControllerDirectory()}. If the controller belongs to a
|
||||
* module, looks for the module prefix to the controller class.
|
||||
*
|
||||
* @param string $className
|
||||
* @return string Class name loaded
|
||||
* @throws Zend_Controller_Dispatcher_Exception if class not loaded
|
||||
*/
|
||||
public function loadClass($className)
|
||||
{
|
||||
$finalClass = $className;
|
||||
if (($this->_defaultModule != $this->_curModule)
|
||||
|| $this->getParam('prefixDefaultModule'))
|
||||
{
|
||||
$finalClass = $this->formatClassName($this->_curModule, $className);
|
||||
}
|
||||
if (class_exists($finalClass, false)) {
|
||||
return $finalClass;
|
||||
}
|
||||
|
||||
$dispatchDir = $this->getDispatchDirectory();
|
||||
$loadFile = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);
|
||||
|
||||
if (Zend_Loader::isReadable($loadFile)) {
|
||||
include_once $loadFile;
|
||||
} else {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $loadFile . "'");
|
||||
}
|
||||
|
||||
if (!class_exists($finalClass, false)) {
|
||||
require_once 'Zend/Controller/Dispatcher/Exception.php';
|
||||
throw new Zend_Controller_Dispatcher_Exception('Invalid controller class ("' . $finalClass . '")');
|
||||
}
|
||||
|
||||
return $finalClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get controller class name
|
||||
*
|
||||
* Try request first; if not found, try pulling from request parameter;
|
||||
* if still not found, fallback to default
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return string|false Returns class name on success
|
||||
*/
|
||||
public function getControllerClass(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$controllerName = $request->getControllerName();
|
||||
if (empty($controllerName)) {
|
||||
if (!$this->getParam('useDefaultControllerAlways')) {
|
||||
return false;
|
||||
}
|
||||
$controllerName = $this->getDefaultControllerName();
|
||||
$request->setControllerName($controllerName);
|
||||
}
|
||||
|
||||
$className = $this->formatControllerName($controllerName);
|
||||
|
||||
$controllerDirs = $this->getControllerDirectory();
|
||||
$module = $request->getModuleName();
|
||||
if ($this->isValidModule($module)) {
|
||||
$this->_curModule = $module;
|
||||
$this->_curDirectory = $controllerDirs[$module];
|
||||
} elseif ($this->isValidModule($this->_defaultModule)) {
|
||||
$request->setModuleName($this->_defaultModule);
|
||||
$this->_curModule = $this->_defaultModule;
|
||||
$this->_curDirectory = $controllerDirs[$this->_defaultModule];
|
||||
} else {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('No default module defined for this application');
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given module is valid
|
||||
*
|
||||
* @param string $module
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidModule($module)
|
||||
{
|
||||
if (!is_string($module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$module = strtolower($module);
|
||||
$controllerDir = $this->getControllerDirectory();
|
||||
foreach (array_keys($controllerDir) as $moduleName) {
|
||||
if ($module == strtolower($moduleName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default controller class
|
||||
*
|
||||
* Determines whether the default controller to use lies within the
|
||||
* requested module, or if the global default should be used.
|
||||
*
|
||||
* By default, will only use the module default unless that controller does
|
||||
* not exist; if this is the case, it falls back to the default controller
|
||||
* in the default module.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultControllerClass(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$controller = $this->getDefaultControllerName();
|
||||
$default = $this->formatControllerName($controller);
|
||||
$request->setControllerName($controller)
|
||||
->setActionName(null);
|
||||
|
||||
$module = $request->getModuleName();
|
||||
$controllerDirs = $this->getControllerDirectory();
|
||||
$this->_curModule = $this->_defaultModule;
|
||||
$this->_curDirectory = $controllerDirs[$this->_defaultModule];
|
||||
if ($this->isValidModule($module)) {
|
||||
$found = false;
|
||||
if (class_exists($default, false)) {
|
||||
$found = true;
|
||||
} else {
|
||||
$moduleDir = $controllerDirs[$module];
|
||||
$fileSpec = $moduleDir . DIRECTORY_SEPARATOR . $this->classToFilename($default);
|
||||
if (Zend_Loader::isReadable($fileSpec)) {
|
||||
$found = true;
|
||||
$this->_curDirectory = $moduleDir;
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
$request->setModuleName($module);
|
||||
$this->_curModule = $this->formatModuleName($module);
|
||||
}
|
||||
} else {
|
||||
$request->setModuleName($this->_defaultModule);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the currently selected dispatch directory (as set by
|
||||
* {@link getController()})
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDispatchDirectory()
|
||||
{
|
||||
return $this->_curDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the action name
|
||||
*
|
||||
* First attempt to retrieve from request; then from request params
|
||||
* using action key; default to default action
|
||||
*
|
||||
* Returns formatted action name
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return string
|
||||
*/
|
||||
public function getActionMethod(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$action = $request->getActionName();
|
||||
if (empty($action)) {
|
||||
$action = $this->getDefaultAction();
|
||||
$request->setActionName($action);
|
||||
}
|
||||
|
||||
return $this->formatActionName($action);
|
||||
}
|
||||
}
|
35
airtime_mvc/library/Zend/Controller/Exception.php
Normal file
35
airtime_mvc/library/Zend/Controller/Exception.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Exception */
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Exception extends Zend_Exception
|
||||
{}
|
||||
|
994
airtime_mvc/library/Zend/Controller/Front.php
Normal file
994
airtime_mvc/library/Zend/Controller/Front.php
Normal file
|
@ -0,0 +1,994 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Front.php 20246 2010-01-12 21:36:08Z dasprid $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Loader */
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/** Zend_Controller_Action_HelperBroker */
|
||||
require_once 'Zend/Controller/Action/HelperBroker.php';
|
||||
|
||||
/** Zend_Controller_Plugin_Broker */
|
||||
require_once 'Zend/Controller/Plugin/Broker.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Front
|
||||
{
|
||||
/**
|
||||
* Base URL
|
||||
* @var string
|
||||
*/
|
||||
protected $_baseUrl = null;
|
||||
|
||||
/**
|
||||
* Directory|ies where controllers are stored
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $_controllerDir = null;
|
||||
|
||||
/**
|
||||
* Instance of Zend_Controller_Dispatcher_Interface
|
||||
* @var Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
protected $_dispatcher = null;
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* Marked only as protected to allow extension of the class. To extend,
|
||||
* simply override {@link getInstance()}.
|
||||
*
|
||||
* @var Zend_Controller_Front
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Array of invocation parameters to use when instantiating action
|
||||
* controllers
|
||||
* @var array
|
||||
*/
|
||||
protected $_invokeParams = array();
|
||||
|
||||
/**
|
||||
* Subdirectory within a module containing controllers; defaults to 'controllers'
|
||||
* @var string
|
||||
*/
|
||||
protected $_moduleControllerDirectoryName = 'controllers';
|
||||
|
||||
/**
|
||||
* Instance of Zend_Controller_Plugin_Broker
|
||||
* @var Zend_Controller_Plugin_Broker
|
||||
*/
|
||||
protected $_plugins = null;
|
||||
|
||||
/**
|
||||
* Instance of Zend_Controller_Request_Abstract
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
protected $_request = null;
|
||||
|
||||
/**
|
||||
* Instance of Zend_Controller_Response_Abstract
|
||||
* @var Zend_Controller_Response_Abstract
|
||||
*/
|
||||
protected $_response = null;
|
||||
|
||||
/**
|
||||
* Whether or not to return the response prior to rendering output while in
|
||||
* {@link dispatch()}; default is to send headers and render output.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_returnResponse = false;
|
||||
|
||||
/**
|
||||
* Instance of Zend_Controller_Router_Interface
|
||||
* @var Zend_Controller_Router_Interface
|
||||
*/
|
||||
protected $_router = null;
|
||||
|
||||
/**
|
||||
* Whether or not exceptions encountered in {@link dispatch()} should be
|
||||
* thrown or trapped in the response object
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_throwExceptions = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Instantiate using {@link getInstance()}; front controller is a singleton
|
||||
* object.
|
||||
*
|
||||
* Instantiates the plugin broker.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$this->_plugins = new Zend_Controller_Plugin_Broker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforce singleton; disallow cloning
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === self::$_instance) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all object properties of the singleton instance
|
||||
*
|
||||
* Primarily used for testing; could be used to chain front controllers.
|
||||
*
|
||||
* Also resets action helper broker, clearing all registered helpers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetInstance()
|
||||
{
|
||||
$reflection = new ReflectionObject($this);
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
$name = $property->getName();
|
||||
switch ($name) {
|
||||
case '_instance':
|
||||
break;
|
||||
case '_controllerDir':
|
||||
case '_invokeParams':
|
||||
$this->{$name} = array();
|
||||
break;
|
||||
case '_plugins':
|
||||
$this->{$name} = new Zend_Controller_Plugin_Broker();
|
||||
break;
|
||||
case '_throwExceptions':
|
||||
case '_returnResponse':
|
||||
$this->{$name} = false;
|
||||
break;
|
||||
case '_moduleControllerDirectoryName':
|
||||
$this->{$name} = 'controllers';
|
||||
break;
|
||||
default:
|
||||
$this->{$name} = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Zend_Controller_Action_HelperBroker::resetHelpers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()
|
||||
*
|
||||
* In PHP 5.1.x, a call to a static method never populates $this -- so run()
|
||||
* may actually be called after setting up your front controller.
|
||||
*
|
||||
* @param string|array $controllerDirectory Path to Zend_Controller_Action
|
||||
* controller classes or array of such paths
|
||||
* @return void
|
||||
* @throws Zend_Controller_Exception if called from an object instance
|
||||
*/
|
||||
public static function run($controllerDirectory)
|
||||
{
|
||||
self::getInstance()
|
||||
->setControllerDirectory($controllerDirectory)
|
||||
->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a controller directory to the controller directory stack
|
||||
*
|
||||
* If $args is presented and is a string, uses it for the array key mapping
|
||||
* to the directory specified.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param string $module Optional argument; module with which to associate directory. If none provided, assumes 'default'
|
||||
* @return Zend_Controller_Front
|
||||
* @throws Zend_Controller_Exception if directory not found or readable
|
||||
*/
|
||||
public function addControllerDirectory($directory, $module = null)
|
||||
{
|
||||
$this->getDispatcher()->addControllerDirectory($directory, $module);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set controller directory
|
||||
*
|
||||
* Stores controller directory(ies) in dispatcher. May be an array of
|
||||
* directories or a string containing a single directory.
|
||||
*
|
||||
* @param string|array $directory Path to Zend_Controller_Action controller
|
||||
* classes or array of such paths
|
||||
* @param string $module Optional module name to use with string $directory
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setControllerDirectory($directory, $module = null)
|
||||
{
|
||||
$this->getDispatcher()->setControllerDirectory($directory, $module);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve controller directory
|
||||
*
|
||||
* Retrieves:
|
||||
* - Array of all controller directories if no $name passed
|
||||
* - String path if $name passed and exists as a key in controller directory array
|
||||
* - null if $name passed but does not exist in controller directory keys
|
||||
*
|
||||
* @param string $name Default null
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function getControllerDirectory($name = null)
|
||||
{
|
||||
return $this->getDispatcher()->getControllerDirectory($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a controller directory by module name
|
||||
*
|
||||
* @param string $module
|
||||
* @return bool
|
||||
*/
|
||||
public function removeControllerDirectory($module)
|
||||
{
|
||||
return $this->getDispatcher()->removeControllerDirectory($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a directory as containing modules
|
||||
*
|
||||
* Iterates through the directory, adding any subdirectories as modules;
|
||||
* the subdirectory within each module named after {@link $_moduleControllerDirectoryName}
|
||||
* will be used as the controller directory path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function addModuleDirectory($path)
|
||||
{
|
||||
try{
|
||||
$dir = new DirectoryIterator($path);
|
||||
} catch(Exception $e) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception("Directory $path not readable", 0, $e);
|
||||
}
|
||||
foreach ($dir as $file) {
|
||||
if ($file->isDot() || !$file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$module = $file->getFilename();
|
||||
|
||||
// Don't use SCCS directories as modules
|
||||
if (preg_match('/^[^a-z]/i', $module) || ('CVS' == $module)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$moduleDir = $file->getPathname() . DIRECTORY_SEPARATOR . $this->getModuleControllerDirectoryName();
|
||||
$this->addControllerDirectory($moduleDir, $module);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to a module directory (but not the controllers directory within)
|
||||
*
|
||||
* @param string $module
|
||||
* @return string|null
|
||||
*/
|
||||
public function getModuleDirectory($module = null)
|
||||
{
|
||||
if (null === $module) {
|
||||
$request = $this->getRequest();
|
||||
if (null !== $request) {
|
||||
$module = $this->getRequest()->getModuleName();
|
||||
}
|
||||
if (empty($module)) {
|
||||
$module = $this->getDispatcher()->getDefaultModule();
|
||||
}
|
||||
}
|
||||
|
||||
$controllerDir = $this->getControllerDirectory($module);
|
||||
|
||||
if ((null === $controllerDir) || !is_string($controllerDir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dirname($controllerDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory name within a module containing controllers
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setModuleControllerDirectoryName($name = 'controllers')
|
||||
{
|
||||
$this->_moduleControllerDirectoryName = (string) $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the directory name within a module containing controllers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleControllerDirectoryName()
|
||||
{
|
||||
return $this->_moduleControllerDirectoryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default controller (unformatted string)
|
||||
*
|
||||
* @param string $controller
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setDefaultControllerName($controller)
|
||||
{
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->setDefaultControllerName($controller);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default controller (unformatted string)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultControllerName()
|
||||
{
|
||||
return $this->getDispatcher()->getDefaultControllerName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default action (unformatted string)
|
||||
*
|
||||
* @param string $action
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setDefaultAction($action)
|
||||
{
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->setDefaultAction($action);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default action (unformatted string)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultAction()
|
||||
{
|
||||
return $this->getDispatcher()->getDefaultAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default module name
|
||||
*
|
||||
* @param string $module
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setDefaultModule($module)
|
||||
{
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->setDefaultModule($module);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default module
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultModule()
|
||||
{
|
||||
return $this->getDispatcher()->getDefaultModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request class/object
|
||||
*
|
||||
* Set the request object. The request holds the request environment.
|
||||
*
|
||||
* If a class name is provided, it will instantiate it
|
||||
*
|
||||
* @param string|Zend_Controller_Request_Abstract $request
|
||||
* @throws Zend_Controller_Exception if invalid request class
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
if (is_string($request)) {
|
||||
if (!class_exists($request)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($request);
|
||||
}
|
||||
$request = new $request();
|
||||
}
|
||||
if (!$request instanceof Zend_Controller_Request_Abstract) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Invalid request class');
|
||||
}
|
||||
|
||||
$this->_request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the request object.
|
||||
*
|
||||
* @return null|Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set router class/object
|
||||
*
|
||||
* Set the router object. The router is responsible for mapping
|
||||
* the request to a controller and action.
|
||||
*
|
||||
* If a class name is provided, instantiates router with any parameters
|
||||
* registered via {@link setParam()} or {@link setParams()}.
|
||||
*
|
||||
* @param string|Zend_Controller_Router_Interface $router
|
||||
* @throws Zend_Controller_Exception if invalid router class
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setRouter($router)
|
||||
{
|
||||
if (is_string($router)) {
|
||||
if (!class_exists($router)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($router);
|
||||
}
|
||||
$router = new $router();
|
||||
}
|
||||
|
||||
if (!$router instanceof Zend_Controller_Router_Interface) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Invalid router class');
|
||||
}
|
||||
|
||||
$router->setFrontController($this);
|
||||
$this->_router = $router;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the router object.
|
||||
*
|
||||
* Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.
|
||||
*
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function getRouter()
|
||||
{
|
||||
if (null == $this->_router) {
|
||||
require_once 'Zend/Controller/Router/Rewrite.php';
|
||||
$this->setRouter(new Zend_Controller_Router_Rewrite());
|
||||
}
|
||||
|
||||
return $this->_router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base URL used for requests
|
||||
*
|
||||
* Use to set the base URL segment of the REQUEST_URI to use when
|
||||
* determining PATH_INFO, etc. Examples:
|
||||
* - /admin
|
||||
* - /myapp
|
||||
* - /subdir/index.php
|
||||
*
|
||||
* Note that the URL should not include the full URI. Do not use:
|
||||
* - http://example.com/admin
|
||||
* - http://example.com/myapp
|
||||
* - http://example.com/subdir/index.php
|
||||
*
|
||||
* If a null value is passed, this can be used as well for autodiscovery (default).
|
||||
*
|
||||
* @param string $base
|
||||
* @return Zend_Controller_Front
|
||||
* @throws Zend_Controller_Exception for non-string $base
|
||||
*/
|
||||
public function setBaseUrl($base = null)
|
||||
{
|
||||
if (!is_string($base) && (null !== $base)) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Rewrite base must be a string');
|
||||
}
|
||||
|
||||
$this->_baseUrl = $base;
|
||||
|
||||
if ((null !== ($request = $this->getRequest())) && (method_exists($request, 'setBaseUrl'))) {
|
||||
$request->setBaseUrl($base);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the currently set base URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if ((null !== $request) && method_exists($request, 'getBaseUrl')) {
|
||||
return $request->getBaseUrl();
|
||||
}
|
||||
|
||||
return $this->_baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_Dispatcher_Interface $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_Dispatcher_Interface
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
/**
|
||||
* Instantiate the default dispatcher if one was not set.
|
||||
*/
|
||||
if (!$this->_dispatcher instanceof Zend_Controller_Dispatcher_Interface) {
|
||||
require_once 'Zend/Controller/Dispatcher/Standard.php';
|
||||
$this->_dispatcher = new Zend_Controller_Dispatcher_Standard();
|
||||
}
|
||||
return $this->_dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response class/object
|
||||
*
|
||||
* Set the response object. The response is a container for action
|
||||
* responses and headers. Usage is optional.
|
||||
*
|
||||
* If a class name is provided, instantiates a response object.
|
||||
*
|
||||
* @param string|Zend_Controller_Response_Abstract $response
|
||||
* @throws Zend_Controller_Exception if invalid response class
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setResponse($response)
|
||||
{
|
||||
if (is_string($response)) {
|
||||
if (!class_exists($response)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($response);
|
||||
}
|
||||
$response = new $response();
|
||||
}
|
||||
if (!$response instanceof Zend_Controller_Response_Abstract) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Invalid response class');
|
||||
}
|
||||
|
||||
$this->_response = $response;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the response object.
|
||||
*
|
||||
* @return null|Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or modify a parameter to use when instantiating an action controller
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
$name = (string) $name;
|
||||
$this->_invokeParams[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameters to pass to action controller constructors
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
$this->_invokeParams = array_merge($this->_invokeParams, $params);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single parameter from the controller parameter stack
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name)
|
||||
{
|
||||
if(isset($this->_invokeParams[$name])) {
|
||||
return $this->_invokeParams[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve action controller instantiation parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_invokeParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the controller parameter stack
|
||||
*
|
||||
* By default, clears all parameters. If a parameter name is given, clears
|
||||
* only that parameter; if an array of parameter names is provided, clears
|
||||
* each.
|
||||
*
|
||||
* @param null|string|array single key or array of keys for params to clear
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function clearParams($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$this->_invokeParams = array();
|
||||
} elseif (is_string($name) && isset($this->_invokeParams[$name])) {
|
||||
unset($this->_invokeParams[$name]);
|
||||
} elseif (is_array($name)) {
|
||||
foreach ($name as $key) {
|
||||
if (is_string($key) && isset($this->_invokeParams[$key])) {
|
||||
unset($this->_invokeParams[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin.
|
||||
*
|
||||
* @param Zend_Controller_Plugin_Abstract $plugin
|
||||
* @param int $stackIndex Optional; stack index for plugin
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null)
|
||||
{
|
||||
$this->_plugins->registerPlugin($plugin, $stackIndex);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a plugin.
|
||||
*
|
||||
* @param string|Zend_Controller_Plugin_Abstract $plugin Plugin class or object to unregister
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function unregisterPlugin($plugin)
|
||||
{
|
||||
$this->_plugins->unregisterPlugin($plugin);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a particular plugin registered?
|
||||
*
|
||||
* @param string $class
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlugin($class)
|
||||
{
|
||||
return $this->_plugins->hasPlugin($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a plugin or plugins by class
|
||||
*
|
||||
* @param string $class
|
||||
* @return false|Zend_Controller_Plugin_Abstract|array
|
||||
*/
|
||||
public function getPlugin($class)
|
||||
{
|
||||
return $this->_plugins->getPlugin($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPlugins()
|
||||
{
|
||||
return $this->_plugins->getPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the throwExceptions flag and retrieve current status
|
||||
*
|
||||
* Set whether exceptions encounted in the dispatch loop should be thrown
|
||||
* or caught and trapped in the response object.
|
||||
*
|
||||
* Default behaviour is to trap them in the response object; call this
|
||||
* method to have them thrown.
|
||||
*
|
||||
* Passing no value will return the current value of the flag; passing a
|
||||
* boolean true or false value will set the flag and return the current
|
||||
* object instance.
|
||||
*
|
||||
* @param boolean $flag Defaults to null (return flag state)
|
||||
* @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
|
||||
*/
|
||||
public function throwExceptions($flag = null)
|
||||
{
|
||||
if ($flag !== null) {
|
||||
$this->_throwExceptions = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->_throwExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether {@link dispatch()} should return the response without first
|
||||
* rendering output. By default, output is rendered and dispatch() returns
|
||||
* nothing.
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
|
||||
*/
|
||||
public function returnResponse($flag = null)
|
||||
{
|
||||
if (true === $flag) {
|
||||
$this->_returnResponse = true;
|
||||
return $this;
|
||||
} elseif (false === $flag) {
|
||||
$this->_returnResponse = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->_returnResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an HTTP request to a controller/action.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract|null $request
|
||||
* @param Zend_Controller_Response_Abstract|null $response
|
||||
* @return void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
|
||||
*/
|
||||
public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
|
||||
{
|
||||
if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
|
||||
// Register with stack index of 100
|
||||
require_once 'Zend/Controller/Plugin/ErrorHandler.php';
|
||||
$this->_plugins->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
|
||||
}
|
||||
|
||||
if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
|
||||
require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
|
||||
Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new Zend_Controller_Action_Helper_ViewRenderer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate default request object (HTTP version) if none provided
|
||||
*/
|
||||
if (null !== $request) {
|
||||
$this->setRequest($request);
|
||||
} elseif ((null === $request) && (null === ($request = $this->getRequest()))) {
|
||||
require_once 'Zend/Controller/Request/Http.php';
|
||||
$request = new Zend_Controller_Request_Http();
|
||||
$this->setRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set base URL of request object, if available
|
||||
*/
|
||||
if (is_callable(array($this->_request, 'setBaseUrl'))) {
|
||||
if (null !== $this->_baseUrl) {
|
||||
$this->_request->setBaseUrl($this->_baseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate default response object (HTTP version) if none provided
|
||||
*/
|
||||
if (null !== $response) {
|
||||
$this->setResponse($response);
|
||||
} elseif ((null === $this->_response) && (null === ($this->_response = $this->getResponse()))) {
|
||||
require_once 'Zend/Controller/Response/Http.php';
|
||||
$response = new Zend_Controller_Response_Http();
|
||||
$this->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register request and response objects with plugin broker
|
||||
*/
|
||||
$this->_plugins
|
||||
->setRequest($this->_request)
|
||||
->setResponse($this->_response);
|
||||
|
||||
/**
|
||||
* Initialize router
|
||||
*/
|
||||
$router = $this->getRouter();
|
||||
$router->setParams($this->getParams());
|
||||
|
||||
/**
|
||||
* Initialize dispatcher
|
||||
*/
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->setParams($this->getParams())
|
||||
->setResponse($this->_response);
|
||||
|
||||
// Begin dispatch
|
||||
try {
|
||||
/**
|
||||
* Route request to controller/action, if a router is provided
|
||||
*/
|
||||
|
||||
/**
|
||||
* Notify plugins of router startup
|
||||
*/
|
||||
$this->_plugins->routeStartup($this->_request);
|
||||
|
||||
try {
|
||||
$router->route($this->_request);
|
||||
} catch (Exception $e) {
|
||||
if ($this->throwExceptions()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_response->setException($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify plugins of router completion
|
||||
*/
|
||||
$this->_plugins->routeShutdown($this->_request);
|
||||
|
||||
/**
|
||||
* Notify plugins of dispatch loop startup
|
||||
*/
|
||||
$this->_plugins->dispatchLoopStartup($this->_request);
|
||||
|
||||
/**
|
||||
* Attempt to dispatch the controller/action. If the $this->_request
|
||||
* indicates that it needs to be dispatched, move to the next
|
||||
* action in the request.
|
||||
*/
|
||||
do {
|
||||
$this->_request->setDispatched(true);
|
||||
|
||||
/**
|
||||
* Notify plugins of dispatch startup
|
||||
*/
|
||||
$this->_plugins->preDispatch($this->_request);
|
||||
|
||||
/**
|
||||
* Skip requested action if preDispatch() has reset it
|
||||
*/
|
||||
if (!$this->_request->isDispatched()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch request
|
||||
*/
|
||||
try {
|
||||
$dispatcher->dispatch($this->_request, $this->_response);
|
||||
} catch (Exception $e) {
|
||||
if ($this->throwExceptions()) {
|
||||
throw $e;
|
||||
}
|
||||
$this->_response->setException($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify plugins of dispatch completion
|
||||
*/
|
||||
$this->_plugins->postDispatch($this->_request);
|
||||
} while (!$this->_request->isDispatched());
|
||||
} catch (Exception $e) {
|
||||
if ($this->throwExceptions()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_response->setException($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify plugins of dispatch loop completion
|
||||
*/
|
||||
try {
|
||||
$this->_plugins->dispatchLoopShutdown();
|
||||
} catch (Exception $e) {
|
||||
if ($this->throwExceptions()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_response->setException($e);
|
||||
}
|
||||
|
||||
if ($this->returnResponse()) {
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
$this->_response->sendResponse();
|
||||
}
|
||||
}
|
151
airtime_mvc/library/Zend/Controller/Plugin/Abstract.php
Normal file
151
airtime_mvc/library/Zend/Controller/Plugin/Abstract.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Response_Abstract
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* Set request object
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return Zend_Controller_Plugin_Abstract
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$this->_request = $request;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response object
|
||||
*
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @return Zend_Controller_Plugin_Abstract
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Abstract $response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract $response
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front begins evaluating the
|
||||
* request against its routes.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function routeStartup(Zend_Controller_Request_Abstract $request)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Called after Zend_Controller_Router exits.
|
||||
*
|
||||
* Called after Zend_Controller_Front exits from the router.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function routeShutdown(Zend_Controller_Request_Abstract $request)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front enters its dispatch loop.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Called before an action is dispatched by Zend_Controller_Dispatcher.
|
||||
*
|
||||
* This callback allows for proxy or filter behavior. By altering the
|
||||
* request and resetting its dispatched flag (via
|
||||
* {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
|
||||
* the current action may be skipped.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Called after an action is dispatched by Zend_Controller_Dispatcher.
|
||||
*
|
||||
* This callback allows for proxy or filter behavior. By altering the
|
||||
* request and resetting its dispatched flag (via
|
||||
* {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
|
||||
* a new action may be specified for dispatching.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front exits its dispatch loop.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dispatchLoopShutdown()
|
||||
{}
|
||||
}
|
280
airtime_mvc/library/Zend/Controller/Plugin/ActionStack.php
Normal file
280
airtime_mvc/library/Zend/Controller/Plugin/ActionStack.php
Normal file
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Plugin_Abstract */
|
||||
require_once 'Zend/Controller/Plugin/Abstract.php';
|
||||
|
||||
/** Zend_Registry */
|
||||
require_once 'Zend/Registry.php';
|
||||
|
||||
/**
|
||||
* Manage a stack of actions
|
||||
*
|
||||
* @uses Zend_Controller_Plugin_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ActionStack.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
class Zend_Controller_Plugin_ActionStack extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
/** @var Zend_Registry */
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* Registry key under which actions are stored
|
||||
* @var string
|
||||
*/
|
||||
protected $_registryKey = 'Zend_Controller_Plugin_ActionStack';
|
||||
|
||||
/**
|
||||
* Valid keys for stack items
|
||||
* @var array
|
||||
*/
|
||||
protected $_validKeys = array(
|
||||
'module',
|
||||
'controller',
|
||||
'action',
|
||||
'params'
|
||||
);
|
||||
|
||||
/**
|
||||
* Flag to determine whether request parameters are cleared between actions, or whether new parameters
|
||||
* are added to existing request parameters.
|
||||
*
|
||||
* @var Bool
|
||||
*/
|
||||
protected $_clearRequestParams = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Registry $registry
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Registry $registry = null, $key = null)
|
||||
{
|
||||
if (null === $registry) {
|
||||
$registry = Zend_Registry::getInstance();
|
||||
}
|
||||
$this->setRegistry($registry);
|
||||
|
||||
if (null !== $key) {
|
||||
$this->setRegistryKey($key);
|
||||
} else {
|
||||
$key = $this->getRegistryKey();
|
||||
}
|
||||
|
||||
$registry[$key] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set registry object
|
||||
*
|
||||
* @param Zend_Registry $registry
|
||||
* @return Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
public function setRegistry(Zend_Registry $registry)
|
||||
{
|
||||
$this->_registry = $registry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve registry object
|
||||
*
|
||||
* @return Zend_Registry
|
||||
*/
|
||||
public function getRegistry()
|
||||
{
|
||||
return $this->_registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve registry key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRegistryKey()
|
||||
{
|
||||
return $this->_registryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set registry key
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
public function setRegistryKey($key)
|
||||
{
|
||||
$this->_registryKey = (string) $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set clearRequestParams flag
|
||||
*
|
||||
* @param bool $clearRequestParams
|
||||
* @return Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
public function setClearRequestParams($clearRequestParams)
|
||||
{
|
||||
$this->_clearRequestParams = (bool) $clearRequestParams;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve clearRequestParams flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getClearRequestParams()
|
||||
{
|
||||
return $this->_clearRequestParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve action stack
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStack()
|
||||
{
|
||||
$registry = $this->getRegistry();
|
||||
$stack = $registry[$this->getRegistryKey()];
|
||||
return $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save stack to registry
|
||||
*
|
||||
* @param array $stack
|
||||
* @return Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
protected function _saveStack(array $stack)
|
||||
{
|
||||
$registry = $this->getRegistry();
|
||||
$registry[$this->getRegistryKey()] = $stack;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an item onto the stack
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $next
|
||||
* @return Zend_Controller_Plugin_ActionStack
|
||||
*/
|
||||
public function pushStack(Zend_Controller_Request_Abstract $next)
|
||||
{
|
||||
$stack = $this->getStack();
|
||||
array_push($stack, $next);
|
||||
return $this->_saveStack($stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop an item off the action stack
|
||||
*
|
||||
* @return false|Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function popStack()
|
||||
{
|
||||
$stack = $this->getStack();
|
||||
if (0 == count($stack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$next = array_pop($stack);
|
||||
$this->_saveStack($stack);
|
||||
|
||||
if (!$next instanceof Zend_Controller_Request_Abstract) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('ArrayStack should only contain request objects');
|
||||
}
|
||||
$action = $next->getActionName();
|
||||
if (empty($action)) {
|
||||
return $this->popStack($stack);
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
$controller = $next->getControllerName();
|
||||
if (empty($controller)) {
|
||||
$next->setControllerName($request->getControllerName());
|
||||
}
|
||||
|
||||
$module = $next->getModuleName();
|
||||
if (empty($module)) {
|
||||
$next->setModuleName($request->getModuleName());
|
||||
}
|
||||
|
||||
return $next;
|
||||
}
|
||||
|
||||
/**
|
||||
* postDispatch() plugin hook -- check for actions in stack, and dispatch if any found
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
// Don't move on to next request if this is already an attempt to
|
||||
// forward
|
||||
if (!$request->isDispatched()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setRequest($request);
|
||||
$stack = $this->getStack();
|
||||
if (empty($stack)) {
|
||||
return;
|
||||
}
|
||||
$next = $this->popStack();
|
||||
if (!$next) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->forward($next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward request with next action
|
||||
*
|
||||
* @param array $next
|
||||
* @return void
|
||||
*/
|
||||
public function forward(Zend_Controller_Request_Abstract $next)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if ($this->getClearRequestParams()) {
|
||||
$request->clearParams();
|
||||
}
|
||||
|
||||
$request->setModuleName($next->getModuleName())
|
||||
->setControllerName($next->getControllerName())
|
||||
->setActionName($next->getActionName())
|
||||
->setParams($next->getParams())
|
||||
->setDispatched(false);
|
||||
}
|
||||
}
|
363
airtime_mvc/library/Zend/Controller/Plugin/Broker.php
Normal file
363
airtime_mvc/library/Zend/Controller/Plugin/Broker.php
Normal file
|
@ -0,0 +1,363 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Broker.php 20255 2010-01-13 13:23:36Z matthew $
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Plugin_Abstract */
|
||||
require_once 'Zend/Controller/Plugin/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Plugin_Broker extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Array of instance of objects extending Zend_Controller_Plugin_Abstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_plugins = array();
|
||||
|
||||
|
||||
/**
|
||||
* Register a plugin.
|
||||
*
|
||||
* @param Zend_Controller_Plugin_Abstract $plugin
|
||||
* @param int $stackIndex
|
||||
* @return Zend_Controller_Plugin_Broker
|
||||
*/
|
||||
public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null)
|
||||
{
|
||||
if (false !== array_search($plugin, $this->_plugins, true)) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Plugin already registered');
|
||||
}
|
||||
|
||||
$stackIndex = (int) $stackIndex;
|
||||
|
||||
if ($stackIndex) {
|
||||
if (isset($this->_plugins[$stackIndex])) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Plugin with stackIndex "' . $stackIndex . '" already registered');
|
||||
}
|
||||
$this->_plugins[$stackIndex] = $plugin;
|
||||
} else {
|
||||
$stackIndex = count($this->_plugins);
|
||||
while (isset($this->_plugins[$stackIndex])) {
|
||||
++$stackIndex;
|
||||
}
|
||||
$this->_plugins[$stackIndex] = $plugin;
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request) {
|
||||
$this->_plugins[$stackIndex]->setRequest($request);
|
||||
}
|
||||
$response = $this->getResponse();
|
||||
if ($response) {
|
||||
$this->_plugins[$stackIndex]->setResponse($response);
|
||||
}
|
||||
|
||||
ksort($this->_plugins);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a plugin.
|
||||
*
|
||||
* @param string|Zend_Controller_Plugin_Abstract $plugin Plugin object or class name
|
||||
* @return Zend_Controller_Plugin_Broker
|
||||
*/
|
||||
public function unregisterPlugin($plugin)
|
||||
{
|
||||
if ($plugin instanceof Zend_Controller_Plugin_Abstract) {
|
||||
// Given a plugin object, find it in the array
|
||||
$key = array_search($plugin, $this->_plugins, true);
|
||||
if (false === $key) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Plugin never registered.');
|
||||
}
|
||||
unset($this->_plugins[$key]);
|
||||
} elseif (is_string($plugin)) {
|
||||
// Given a plugin class, find all plugins of that class and unset them
|
||||
foreach ($this->_plugins as $key => $_plugin) {
|
||||
$type = get_class($_plugin);
|
||||
if ($plugin == $type) {
|
||||
unset($this->_plugins[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a plugin of a particular class registered?
|
||||
*
|
||||
* @param string $class
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlugin($class)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
$type = get_class($plugin);
|
||||
if ($class == $type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a plugin or plugins by class
|
||||
*
|
||||
* @param string $class Class name of plugin(s) desired
|
||||
* @return false|Zend_Controller_Plugin_Abstract|array Returns false if none found, plugin if only one found, and array of plugins if multiple plugins of same class found
|
||||
*/
|
||||
public function getPlugin($class)
|
||||
{
|
||||
$found = array();
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
$type = get_class($plugin);
|
||||
if ($class == $type) {
|
||||
$found[] = $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
switch (count($found)) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
return $found[0];
|
||||
default:
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPlugins()
|
||||
{
|
||||
return $this->_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request object, and register with each plugin
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return Zend_Controller_Plugin_Broker
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$this->_request = $request;
|
||||
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
$plugin->setRequest($request);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response object
|
||||
*
|
||||
* @param Zend_Controller_Response_Abstract $response
|
||||
* @return Zend_Controller_Plugin_Broker
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Abstract $response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
$plugin->setResponse($response);
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract $response
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front begins evaluating the
|
||||
* request against its routes.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function routeStartup(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->routeStartup($request);
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front exits its iterations over
|
||||
* the route set.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function routeShutdown(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->routeShutdown($request);
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front enters its dispatch loop.
|
||||
*
|
||||
* During the dispatch loop, Zend_Controller_Front keeps a
|
||||
* Zend_Controller_Request_Abstract object, and uses
|
||||
* Zend_Controller_Dispatcher to dispatch the
|
||||
* Zend_Controller_Request_Abstract object to controllers/actions.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->dispatchLoopStartup($request);
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before an action is dispatched by Zend_Controller_Dispatcher.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->preDispatch($request);
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called after an action is dispatched by Zend_Controller_Dispatcher.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function postDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->postDispatch($request);
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before Zend_Controller_Front exits its dispatch loop.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
public function dispatchLoopShutdown()
|
||||
{
|
||||
foreach ($this->_plugins as $plugin) {
|
||||
try {
|
||||
$plugin->dispatchLoopShutdown();
|
||||
} catch (Exception $e) {
|
||||
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
|
||||
throw $e;
|
||||
} else {
|
||||
$this->getResponse()->setException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
289
airtime_mvc/library/Zend/Controller/Plugin/ErrorHandler.php
Normal file
289
airtime_mvc/library/Zend/Controller/Plugin/ErrorHandler.php
Normal file
|
@ -0,0 +1,289 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Plugin_Abstract */
|
||||
require_once 'Zend/Controller/Plugin/Abstract.php';
|
||||
|
||||
/**
|
||||
* Handle exceptions that bubble up based on missing controllers, actions, or
|
||||
* application errors, and forward to an error handler.
|
||||
*
|
||||
* @uses Zend_Controller_Plugin_Abstract
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Plugins
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ErrorHandler.php 20246 2010-01-12 21:36:08Z dasprid $
|
||||
*/
|
||||
class Zend_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* Const - No controller exception; controller does not exist
|
||||
*/
|
||||
const EXCEPTION_NO_CONTROLLER = 'EXCEPTION_NO_CONTROLLER';
|
||||
|
||||
/**
|
||||
* Const - No action exception; controller exists, but action does not
|
||||
*/
|
||||
const EXCEPTION_NO_ACTION = 'EXCEPTION_NO_ACTION';
|
||||
|
||||
/**
|
||||
* Const - No route exception; no routing was possible
|
||||
*/
|
||||
const EXCEPTION_NO_ROUTE = 'EXCEPTION_NO_ROUTE';
|
||||
|
||||
/**
|
||||
* Const - Other Exception; exceptions thrown by application controllers
|
||||
*/
|
||||
const EXCEPTION_OTHER = 'EXCEPTION_OTHER';
|
||||
|
||||
/**
|
||||
* Module to use for errors; defaults to default module in dispatcher
|
||||
* @var string
|
||||
*/
|
||||
protected $_errorModule;
|
||||
|
||||
/**
|
||||
* Controller to use for errors; defaults to 'error'
|
||||
* @var string
|
||||
*/
|
||||
protected $_errorController = 'error';
|
||||
|
||||
/**
|
||||
* Action to use for errors; defaults to 'error'
|
||||
* @var string
|
||||
*/
|
||||
protected $_errorAction = 'error';
|
||||
|
||||
/**
|
||||
* Flag; are we already inside the error handler loop?
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isInsideErrorHandlerLoop = false;
|
||||
|
||||
/**
|
||||
* Exception count logged at first invocation of plugin
|
||||
* @var int
|
||||
*/
|
||||
protected $_exceptionCountAtFirstEncounter = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Options may include:
|
||||
* - module
|
||||
* - controller
|
||||
* - action
|
||||
*
|
||||
* @param Array $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Array $options = array())
|
||||
{
|
||||
$this->setErrorHandler($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* setErrorHandler() - setup the error handling options
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Controller_Plugin_ErrorHandler
|
||||
*/
|
||||
public function setErrorHandler(Array $options = array())
|
||||
{
|
||||
if (isset($options['module'])) {
|
||||
$this->setErrorHandlerModule($options['module']);
|
||||
}
|
||||
if (isset($options['controller'])) {
|
||||
$this->setErrorHandlerController($options['controller']);
|
||||
}
|
||||
if (isset($options['action'])) {
|
||||
$this->setErrorHandlerAction($options['action']);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module name for the error handler
|
||||
*
|
||||
* @param string $module
|
||||
* @return Zend_Controller_Plugin_ErrorHandler
|
||||
*/
|
||||
public function setErrorHandlerModule($module)
|
||||
{
|
||||
$this->_errorModule = (string) $module;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current error handler module
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorHandlerModule()
|
||||
{
|
||||
if (null === $this->_errorModule) {
|
||||
$this->_errorModule = Zend_Controller_Front::getInstance()->getDispatcher()->getDefaultModule();
|
||||
}
|
||||
return $this->_errorModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the controller name for the error handler
|
||||
*
|
||||
* @param string $controller
|
||||
* @return Zend_Controller_Plugin_ErrorHandler
|
||||
*/
|
||||
public function setErrorHandlerController($controller)
|
||||
{
|
||||
$this->_errorController = (string) $controller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current error handler controller
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorHandlerController()
|
||||
{
|
||||
return $this->_errorController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action name for the error handler
|
||||
*
|
||||
* @param string $action
|
||||
* @return Zend_Controller_Plugin_ErrorHandler
|
||||
*/
|
||||
public function setErrorHandlerAction($action)
|
||||
{
|
||||
$this->_errorAction = (string) $action;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current error handler action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorHandlerAction()
|
||||
{
|
||||
return $this->_errorAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route shutdown hook -- Ccheck for router exceptions
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function routeShutdown(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$this->_handleError($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post dispatch hook -- check for exceptions and dispatch error handler if
|
||||
* necessary
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function postDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$this->_handleError($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle errors and exceptions
|
||||
*
|
||||
* If the 'noErrorHandler' front controller flag has been set,
|
||||
* returns early.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @return void
|
||||
*/
|
||||
protected function _handleError(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$frontController = Zend_Controller_Front::getInstance();
|
||||
if ($frontController->getParam('noErrorHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$response = $this->getResponse();
|
||||
|
||||
if ($this->_isInsideErrorHandlerLoop) {
|
||||
$exceptions = $response->getException();
|
||||
if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
|
||||
// Exception thrown by error handler; tell the front controller to throw it
|
||||
$frontController->throwExceptions(true);
|
||||
throw array_pop($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
// check for an exception AND allow the error handler controller the option to forward
|
||||
if (($response->isException()) && (!$this->_isInsideErrorHandlerLoop)) {
|
||||
$this->_isInsideErrorHandlerLoop = true;
|
||||
|
||||
// Get exception information
|
||||
$error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
|
||||
$exceptions = $response->getException();
|
||||
$exception = $exceptions[0];
|
||||
$exceptionType = get_class($exception);
|
||||
$error->exception = $exception;
|
||||
switch ($exceptionType) {
|
||||
case 'Zend_Controller_Router_Exception':
|
||||
if (404 == $exception->getCode()) {
|
||||
$error->type = self::EXCEPTION_NO_ROUTE;
|
||||
} else {
|
||||
$error->type = self::EXCEPTION_OTHER;
|
||||
}
|
||||
break;
|
||||
case 'Zend_Controller_Dispatcher_Exception':
|
||||
$error->type = self::EXCEPTION_NO_CONTROLLER;
|
||||
break;
|
||||
case 'Zend_Controller_Action_Exception':
|
||||
if (404 == $exception->getCode()) {
|
||||
$error->type = self::EXCEPTION_NO_ACTION;
|
||||
} else {
|
||||
$error->type = self::EXCEPTION_OTHER;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$error->type = self::EXCEPTION_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
// Keep a copy of the original request
|
||||
$error->request = clone $request;
|
||||
|
||||
// get a count of the number of exceptions encountered
|
||||
$this->_exceptionCountAtFirstEncounter = count($exceptions);
|
||||
|
||||
// Forward to the error handler
|
||||
$request->setParam('error_handler', $error)
|
||||
->setModuleName($this->getErrorHandlerModule())
|
||||
->setControllerName($this->getErrorHandlerController())
|
||||
->setActionName($this->getErrorHandlerAction())
|
||||
->setDispatched(false);
|
||||
}
|
||||
}
|
||||
}
|
60
airtime_mvc/library/Zend/Controller/Plugin/PutHandler.php
Normal file
60
airtime_mvc/library/Zend/Controller/Plugin/PutHandler.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Plugin
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: PutHandler.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Plugin_Abstract
|
||||
*/
|
||||
require_once 'Zend/Controller/Plugin/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Request_Http
|
||||
*/
|
||||
require_once 'Zend/Controller/Request/Http.php';
|
||||
|
||||
/**
|
||||
* Plugin to digest PUT request body and make params available just like POST
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Zend_Controller_Plugin
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Plugin_PutHandler extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* Before dispatching, digest PUT request body and set params
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
if (!$request instanceof Zend_Controller_Request_Http) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_request->isPut()) {
|
||||
$putParams = array();
|
||||
parse_str($this->_request->getRawBody(), $putParams);
|
||||
$request->setParams($putParams);
|
||||
}
|
||||
}
|
||||
}
|
356
airtime_mvc/library/Zend/Controller/Request/Abstract.php
Normal file
356
airtime_mvc/library/Zend/Controller/Request/Abstract.php
Normal file
|
@ -0,0 +1,356 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Request_Abstract
|
||||
{
|
||||
/**
|
||||
* Has the action been dispatched?
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_dispatched = false;
|
||||
|
||||
/**
|
||||
* Module
|
||||
* @var string
|
||||
*/
|
||||
protected $_module;
|
||||
|
||||
/**
|
||||
* Module key for retrieving module from params
|
||||
* @var string
|
||||
*/
|
||||
protected $_moduleKey = 'module';
|
||||
|
||||
/**
|
||||
* Controller
|
||||
* @var string
|
||||
*/
|
||||
protected $_controller;
|
||||
|
||||
/**
|
||||
* Controller key for retrieving controller from params
|
||||
* @var string
|
||||
*/
|
||||
protected $_controllerKey = 'controller';
|
||||
|
||||
/**
|
||||
* Action
|
||||
* @var string
|
||||
*/
|
||||
protected $_action;
|
||||
|
||||
/**
|
||||
* Action key for retrieving action from params
|
||||
* @var string
|
||||
*/
|
||||
protected $_actionKey = 'action';
|
||||
|
||||
/**
|
||||
* Request parameters
|
||||
* @var array
|
||||
*/
|
||||
protected $_params = array();
|
||||
|
||||
/**
|
||||
* Retrieve the module name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
if (null === $this->_module) {
|
||||
$this->_module = $this->getParam($this->getModuleKey());
|
||||
}
|
||||
|
||||
return $this->_module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module name to use
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setModuleName($value)
|
||||
{
|
||||
$this->_module = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the controller name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getControllerName()
|
||||
{
|
||||
if (null === $this->_controller) {
|
||||
$this->_controller = $this->getParam($this->getControllerKey());
|
||||
}
|
||||
|
||||
return $this->_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the controller name to use
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setControllerName($value)
|
||||
{
|
||||
$this->_controller = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the action name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getActionName()
|
||||
{
|
||||
if (null === $this->_action) {
|
||||
$this->_action = $this->getParam($this->getActionKey());
|
||||
}
|
||||
|
||||
return $this->_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action name
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setActionName($value)
|
||||
{
|
||||
$this->_action = $value;
|
||||
/**
|
||||
* @see ZF-3465
|
||||
*/
|
||||
if (null === $value) {
|
||||
$this->setParam($this->getActionKey(), $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the module key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleKey()
|
||||
{
|
||||
return $this->_moduleKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module key
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setModuleKey($key)
|
||||
{
|
||||
$this->_moduleKey = (string) $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the controller key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getControllerKey()
|
||||
{
|
||||
return $this->_controllerKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the controller key
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setControllerKey($key)
|
||||
{
|
||||
$this->_controllerKey = (string) $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the action key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getActionKey()
|
||||
{
|
||||
return $this->_actionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action key
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setActionKey($key)
|
||||
{
|
||||
$this->_actionKey = (string) $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an action parameter
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default Default value to use if key not found
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($key, $default = null)
|
||||
{
|
||||
$key = (string) $key;
|
||||
if (isset($this->_params[$key])) {
|
||||
return $this->_params[$key];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve only user params (i.e, any param specific to the object and not the environment)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserParams()
|
||||
{
|
||||
return $this->_params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single user param (i.e, a param specific to the object and not the environment)
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $default Default value to use if key not found
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserParam($key, $default = null)
|
||||
{
|
||||
if (isset($this->_params[$key])) {
|
||||
return $this->_params[$key];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an action parameter
|
||||
*
|
||||
* A $value of null will unset the $key if it exists
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setParam($key, $value)
|
||||
{
|
||||
$key = (string) $key;
|
||||
|
||||
if ((null === $value) && isset($this->_params[$key])) {
|
||||
unset($this->_params[$key]);
|
||||
} elseif (null !== $value) {
|
||||
$this->_params[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all action parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set action parameters en masse; does not overwrite
|
||||
*
|
||||
* Null values will unset the associated key.
|
||||
*
|
||||
* @param array $array
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setParams(array $array)
|
||||
{
|
||||
$this->_params = $this->_params + (array) $array;
|
||||
|
||||
foreach ($this->_params as $key => $value) {
|
||||
if (null === $value) {
|
||||
unset($this->_params[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset all user parameters
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function clearParams()
|
||||
{
|
||||
$this->_params = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag indicating whether or not request has been dispatched
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function setDispatched($flag = true)
|
||||
{
|
||||
$this->_dispatched = $flag ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the request has been dispatched
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDispatched()
|
||||
{
|
||||
return $this->_dispatched;
|
||||
}
|
||||
}
|
82
airtime_mvc/library/Zend/Controller/Request/Apache404.php
Normal file
82
airtime_mvc/library/Zend/Controller/Request/Apache404.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Apache404.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Request_Http */
|
||||
require_once 'Zend/Controller/Request/Http.php';
|
||||
|
||||
/** Zend_Uri */
|
||||
require_once 'Zend/Uri.php';
|
||||
|
||||
/**
|
||||
* Zend_Controller_Request_Apache404
|
||||
*
|
||||
* HTTP request object for use with Zend_Controller family. Extends basic HTTP
|
||||
* request object to allow for two edge cases when using Apache:
|
||||
* - Using Apache's 404 handler instead of mod_rewrite to direct requests
|
||||
* - Using the PT flag in rewrite rules
|
||||
*
|
||||
* In each case, the URL to check against is found in REDIRECT_URL, not
|
||||
* REQUEST_URI.
|
||||
*
|
||||
* @uses Zend_Controller_Request_Http
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
*/
|
||||
class Zend_Controller_Request_Apache404 extends Zend_Controller_Request_Http
|
||||
{
|
||||
public function setRequestUri($requestUri = null)
|
||||
{
|
||||
$parseUriGetVars = false;
|
||||
if ($requestUri === null) {
|
||||
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
|
||||
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
|
||||
} elseif (isset($_SERVER['REDIRECT_URL'])) { // Check if using mod_rewrite
|
||||
$requestUri = $_SERVER['REDIRECT_URL'];
|
||||
if (isset($_SERVER['REDIRECT_QUERYSTRING'])) {
|
||||
$parseUriGetVars = $_SERVER['REDIRECT_QUERYSTRING'];
|
||||
}
|
||||
} elseif (isset($_SERVER['REQUEST_URI'])) {
|
||||
$requestUri = $_SERVER['REQUEST_URI'];
|
||||
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
|
||||
$requestUri = $_SERVER['ORIG_PATH_INFO'];
|
||||
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
|
||||
}
|
||||
} else {
|
||||
return $this;
|
||||
}
|
||||
} elseif (!is_string($requestUri)) {
|
||||
return $this;
|
||||
} else {
|
||||
if (false !== ($pos = strpos($requestUri, '?'))) {
|
||||
$parseUriGetVars = substr($requestUri, $pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($parseUriGetVars) {
|
||||
// Set GET items, if available
|
||||
parse_str($parseUriGetVars, $_GET);
|
||||
}
|
||||
|
||||
$this->_requestUri = $requestUri;
|
||||
return $this;
|
||||
}
|
||||
}
|
37
airtime_mvc/library/Zend/Controller/Request/Exception.php
Normal file
37
airtime_mvc/library/Zend/Controller/Request/Exception.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Exception */
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Request_Exception extends Zend_Controller_Exception
|
||||
{}
|
||||
|
1053
airtime_mvc/library/Zend/Controller/Request/Http.php
Normal file
1053
airtime_mvc/library/Zend/Controller/Request/Http.php
Normal file
File diff suppressed because it is too large
Load diff
276
airtime_mvc/library/Zend/Controller/Request/HttpTestCase.php
Normal file
276
airtime_mvc/library/Zend/Controller/Request/HttpTestCase.php
Normal file
|
@ -0,0 +1,276 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HttpTestCase.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Request_Http
|
||||
*/
|
||||
require_once 'Zend/Controller/Request/Http.php';
|
||||
|
||||
/**
|
||||
* Zend_Controller_Request_HttpTestCase
|
||||
*
|
||||
* HTTP request object for use with Zend_Controller family.
|
||||
*
|
||||
* @uses Zend_Controller_Request_Http
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
*/
|
||||
class Zend_Controller_Request_HttpTestCase extends Zend_Controller_Request_Http
|
||||
{
|
||||
/**
|
||||
* Request headers
|
||||
* @var array
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* Request method
|
||||
* @var string
|
||||
*/
|
||||
protected $_method = 'GET';
|
||||
|
||||
/**
|
||||
* Raw POST body
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_rawBody;
|
||||
|
||||
/**
|
||||
* Valid request method types
|
||||
* @var array
|
||||
*/
|
||||
protected $_validMethodTypes = array(
|
||||
'DELETE',
|
||||
'GET',
|
||||
'HEAD',
|
||||
'OPTIONS',
|
||||
'POST',
|
||||
'PUT',
|
||||
);
|
||||
|
||||
/**
|
||||
* Clear GET values
|
||||
*
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function clearQuery()
|
||||
{
|
||||
$_GET = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear POST values
|
||||
*
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function clearPost()
|
||||
{
|
||||
$_POST = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set raw POST body
|
||||
*
|
||||
* @param string $content
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function setRawBody($content)
|
||||
{
|
||||
$this->_rawBody = (string) $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RAW POST body
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->_rawBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear raw POST body
|
||||
*
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function clearRawBody()
|
||||
{
|
||||
$this->_rawBody = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cookie
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function setCookie($key, $value)
|
||||
{
|
||||
$_COOKIE[(string) $key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multiple cookies at once
|
||||
*
|
||||
* @param array $cookies
|
||||
* @return void
|
||||
*/
|
||||
public function setCookies(array $cookies)
|
||||
{
|
||||
foreach ($cookies as $key => $value) {
|
||||
$_COOKIE[$key] = $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cookies
|
||||
*
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function clearCookies()
|
||||
{
|
||||
$_COOKIE = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request method
|
||||
*
|
||||
* @param string $type
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function setMethod($type)
|
||||
{
|
||||
$type = strtoupper(trim((string) $type));
|
||||
if (!in_array($type, $this->_validMethodTypes)) {
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
throw new Zend_Controller_Exception('Invalid request method specified');
|
||||
}
|
||||
$this->_method = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request method
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a request header
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function setHeader($key, $value)
|
||||
{
|
||||
$key = $this->_normalizeHeaderName($key);
|
||||
$this->_headers[$key] = (string) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request headers
|
||||
*
|
||||
* @param array $headers
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
foreach ($headers as $key => $value) {
|
||||
$this->setHeader($key, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request header
|
||||
*
|
||||
* @param string $header
|
||||
* @param mixed $default
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHeader($header, $default = null)
|
||||
{
|
||||
$header = $this->_normalizeHeaderName($header);
|
||||
if (array_key_exists($header, $this->_headers)) {
|
||||
return $this->_headers[$header];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all request headers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear request headers
|
||||
*
|
||||
* @return Zend_Controller_Request_HttpTestCase
|
||||
*/
|
||||
public function clearHeaders()
|
||||
{
|
||||
$this->_headers = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get REQUEST_URI
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getRequestUri()
|
||||
{
|
||||
return $this->_requestUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a header name for setting and retrieval
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function _normalizeHeaderName($name)
|
||||
{
|
||||
$name = strtoupper((string) $name);
|
||||
$name = str_replace('-', '_', $name);
|
||||
return $name;
|
||||
}
|
||||
}
|
55
airtime_mvc/library/Zend/Controller/Request/Simple.php
Normal file
55
airtime_mvc/library/Zend/Controller/Request/Simple.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Request_Abstract */
|
||||
require_once 'Zend/Controller/Request/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Request_Simple extends Zend_Controller_Request_Abstract
|
||||
{
|
||||
|
||||
public function __construct($action = null, $controller = null, $module = null, array $params = array())
|
||||
{
|
||||
if ($action) {
|
||||
$this->setActionName($action);
|
||||
}
|
||||
|
||||
if ($controller) {
|
||||
$this->setControllerName($controller);
|
||||
}
|
||||
|
||||
if ($module) {
|
||||
$this->setModuleName($module);
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
$this->setParams($params);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
794
airtime_mvc/library/Zend/Controller/Response/Abstract.php
Normal file
794
airtime_mvc/library/Zend/Controller/Response/Abstract.php
Normal file
|
@ -0,0 +1,794 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 21302 2010-03-02 23:01:38Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_Abstract
|
||||
*
|
||||
* Base class for Zend_Controller responses
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Response_Abstract
|
||||
{
|
||||
/**
|
||||
* Body content
|
||||
* @var array
|
||||
*/
|
||||
protected $_body = array();
|
||||
|
||||
/**
|
||||
* Exception stack
|
||||
* @var Exception
|
||||
*/
|
||||
protected $_exceptions = array();
|
||||
|
||||
/**
|
||||
* Array of headers. Each header is an array with keys 'name' and 'value'
|
||||
* @var array
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* Array of raw headers. Each header is a single string, the entire header to emit
|
||||
* @var array
|
||||
*/
|
||||
protected $_headersRaw = array();
|
||||
|
||||
/**
|
||||
* HTTP response code to use in headers
|
||||
* @var int
|
||||
*/
|
||||
protected $_httpResponseCode = 200;
|
||||
|
||||
/**
|
||||
* Flag; is this response a redirect?
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isRedirect = false;
|
||||
|
||||
/**
|
||||
* Whether or not to render exceptions; off by default
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_renderExceptions = false;
|
||||
|
||||
/**
|
||||
* Flag; if true, when header operations are called after headers have been
|
||||
* sent, an exception will be raised; otherwise, processing will continue
|
||||
* as normal. Defaults to true.
|
||||
*
|
||||
* @see canSendHeaders()
|
||||
* @var boolean
|
||||
*/
|
||||
public $headersSentThrowsException = true;
|
||||
|
||||
/**
|
||||
* Normalize a header name
|
||||
*
|
||||
* Normalizes a header name to X-Capitalized-Names
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function _normalizeHeader($name)
|
||||
{
|
||||
$filtered = str_replace(array('-', '_'), ' ', (string) $name);
|
||||
$filtered = ucwords(strtolower($filtered));
|
||||
$filtered = str_replace(' ', '-', $filtered);
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a header
|
||||
*
|
||||
* If $replace is true, replaces any headers already defined with that
|
||||
* $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param boolean $replace
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setHeader($name, $value, $replace = false)
|
||||
{
|
||||
$this->canSendHeaders(true);
|
||||
$name = $this->_normalizeHeader($name);
|
||||
$value = (string) $value;
|
||||
|
||||
if ($replace) {
|
||||
foreach ($this->_headers as $key => $header) {
|
||||
if ($name == $header['name']) {
|
||||
unset($this->_headers[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_headers[] = array(
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
'replace' => $replace
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set redirect URL
|
||||
*
|
||||
* Sets Location header and response code. Forces replacement of any prior
|
||||
* redirects.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $code
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setRedirect($url, $code = 302)
|
||||
{
|
||||
$this->canSendHeaders(true);
|
||||
$this->setHeader('Location', $url, true)
|
||||
->setHttpResponseCode($code);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a redirect?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return $this->_isRedirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of headers; see {@link $_headers} for format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear headers
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function clearHeaders()
|
||||
{
|
||||
$this->_headers = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the specified HTTP header
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function clearHeader($name)
|
||||
{
|
||||
if (! count($this->_headers)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($this->_headers as $index => $header) {
|
||||
if ($name == $header['name']) {
|
||||
unset($this->_headers[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set raw HTTP header
|
||||
*
|
||||
* Allows setting non key => value headers, such as status codes
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setRawHeader($value)
|
||||
{
|
||||
$this->canSendHeaders(true);
|
||||
if ('Location' == substr($value, 0, 8)) {
|
||||
$this->_isRedirect = true;
|
||||
}
|
||||
$this->_headersRaw[] = (string) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all {@link setRawHeader() raw HTTP headers}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRawHeaders()
|
||||
{
|
||||
return $this->_headersRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all {@link setRawHeader() raw HTTP headers}
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function clearRawHeaders()
|
||||
{
|
||||
$this->_headersRaw = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the specified raw HTTP header
|
||||
*
|
||||
* @param string $headerRaw
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function clearRawHeader($headerRaw)
|
||||
{
|
||||
if (! count($this->_headersRaw)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$key = array_search($headerRaw, $this->_headersRaw);
|
||||
unset($this->_headersRaw[$key]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all headers, normal and raw
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function clearAllHeaders()
|
||||
{
|
||||
return $this->clearHeaders()
|
||||
->clearRawHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set HTTP response code to use with headers
|
||||
*
|
||||
* @param int $code
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setHttpResponseCode($code)
|
||||
{
|
||||
if (!is_int($code) || (100 > $code) || (599 < $code)) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Invalid HTTP response code');
|
||||
}
|
||||
|
||||
if ((300 <= $code) && (307 >= $code)) {
|
||||
$this->_isRedirect = true;
|
||||
} else {
|
||||
$this->_isRedirect = false;
|
||||
}
|
||||
|
||||
$this->_httpResponseCode = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve HTTP response code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttpResponseCode()
|
||||
{
|
||||
return $this->_httpResponseCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we send headers?
|
||||
*
|
||||
* @param boolean $throw Whether or not to throw an exception if headers have been sent; defaults to false
|
||||
* @return boolean
|
||||
* @throws Zend_Controller_Response_Exception
|
||||
*/
|
||||
public function canSendHeaders($throw = false)
|
||||
{
|
||||
$ok = headers_sent($file, $line);
|
||||
if ($ok && $throw && $this->headersSentThrowsException) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
|
||||
}
|
||||
|
||||
return !$ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send all headers
|
||||
*
|
||||
* Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
|
||||
* has been specified, it is sent with the first header.
|
||||
*
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function sendHeaders()
|
||||
{
|
||||
// Only check if we can send headers if we have headers to send
|
||||
if (count($this->_headersRaw) || count($this->_headers) || (200 != $this->_httpResponseCode)) {
|
||||
$this->canSendHeaders(true);
|
||||
} elseif (200 == $this->_httpResponseCode) {
|
||||
// Haven't changed the response code, and we have no headers
|
||||
return $this;
|
||||
}
|
||||
|
||||
$httpCodeSent = false;
|
||||
|
||||
foreach ($this->_headersRaw as $header) {
|
||||
if (!$httpCodeSent && $this->_httpResponseCode) {
|
||||
header($header, true, $this->_httpResponseCode);
|
||||
$httpCodeSent = true;
|
||||
} else {
|
||||
header($header);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_headers as $header) {
|
||||
if (!$httpCodeSent && $this->_httpResponseCode) {
|
||||
header($header['name'] . ': ' . $header['value'], $header['replace'], $this->_httpResponseCode);
|
||||
$httpCodeSent = true;
|
||||
} else {
|
||||
header($header['name'] . ': ' . $header['value'], $header['replace']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$httpCodeSent) {
|
||||
header('HTTP/1.1 ' . $this->_httpResponseCode);
|
||||
$httpCodeSent = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set body content
|
||||
*
|
||||
* If $name is not passed, or is not a string, resets the entire body and
|
||||
* sets the 'default' key to $content.
|
||||
*
|
||||
* If $name is a string, sets the named segment in the body array to
|
||||
* $content.
|
||||
*
|
||||
* @param string $content
|
||||
* @param null|string $name
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setBody($content, $name = null)
|
||||
{
|
||||
if ((null === $name) || !is_string($name)) {
|
||||
$this->_body = array('default' => (string) $content);
|
||||
} else {
|
||||
$this->_body[$name] = (string) $content;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append content to the body content
|
||||
*
|
||||
* @param string $content
|
||||
* @param null|string $name
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function appendBody($content, $name = null)
|
||||
{
|
||||
if ((null === $name) || !is_string($name)) {
|
||||
if (isset($this->_body['default'])) {
|
||||
$this->_body['default'] .= (string) $content;
|
||||
} else {
|
||||
return $this->append('default', $content);
|
||||
}
|
||||
} elseif (isset($this->_body[$name])) {
|
||||
$this->_body[$name] .= (string) $content;
|
||||
} else {
|
||||
return $this->append($name, $content);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear body array
|
||||
*
|
||||
* With no arguments, clears the entire body array. Given a $name, clears
|
||||
* just that named segment; if no segment matching $name exists, returns
|
||||
* false to indicate an error.
|
||||
*
|
||||
* @param string $name Named segment to clear
|
||||
* @return boolean
|
||||
*/
|
||||
public function clearBody($name = null)
|
||||
{
|
||||
if (null !== $name) {
|
||||
$name = (string) $name;
|
||||
if (isset($this->_body[$name])) {
|
||||
unset($this->_body[$name]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_body = array();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the body content
|
||||
*
|
||||
* If $spec is false, returns the concatenated values of the body content
|
||||
* array. If $spec is boolean true, returns the body content array. If
|
||||
* $spec is a string and matches a named segment, returns the contents of
|
||||
* that segment; otherwise, returns null.
|
||||
*
|
||||
* @param boolean $spec
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getBody($spec = false)
|
||||
{
|
||||
if (false === $spec) {
|
||||
ob_start();
|
||||
$this->outputBody();
|
||||
return ob_get_clean();
|
||||
} elseif (true === $spec) {
|
||||
return $this->_body;
|
||||
} elseif (is_string($spec) && isset($this->_body[$spec])) {
|
||||
return $this->_body[$spec];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a named body segment to the body content array
|
||||
*
|
||||
* If segment already exists, replaces with $content and places at end of
|
||||
* array.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $content
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function append($name, $content)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
|
||||
}
|
||||
|
||||
if (isset($this->_body[$name])) {
|
||||
unset($this->_body[$name]);
|
||||
}
|
||||
$this->_body[$name] = (string) $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a named body segment to the body content array
|
||||
*
|
||||
* If segment already exists, replaces with $content and places at top of
|
||||
* array.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $content
|
||||
* @return void
|
||||
*/
|
||||
public function prepend($name, $content)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
|
||||
}
|
||||
|
||||
if (isset($this->_body[$name])) {
|
||||
unset($this->_body[$name]);
|
||||
}
|
||||
|
||||
$new = array($name => (string) $content);
|
||||
$this->_body = $new + $this->_body;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a named segment into the body content array
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $content
|
||||
* @param string $parent
|
||||
* @param boolean $before Whether to insert the new segment before or
|
||||
* after the parent. Defaults to false (after)
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function insert($name, $content, $parent = null, $before = false)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
|
||||
}
|
||||
|
||||
if ((null !== $parent) && !is_string($parent)) {
|
||||
require_once 'Zend/Controller/Response/Exception.php';
|
||||
throw new Zend_Controller_Response_Exception('Invalid body segment parent key ("' . gettype($parent) . '")');
|
||||
}
|
||||
|
||||
if (isset($this->_body[$name])) {
|
||||
unset($this->_body[$name]);
|
||||
}
|
||||
|
||||
if ((null === $parent) || !isset($this->_body[$parent])) {
|
||||
return $this->append($name, $content);
|
||||
}
|
||||
|
||||
$ins = array($name => (string) $content);
|
||||
$keys = array_keys($this->_body);
|
||||
$loc = array_search($parent, $keys);
|
||||
if (!$before) {
|
||||
// Increment location if not inserting before
|
||||
++$loc;
|
||||
}
|
||||
|
||||
if (0 === $loc) {
|
||||
// If location of key is 0, we're prepending
|
||||
$this->_body = $ins + $this->_body;
|
||||
} elseif ($loc >= (count($this->_body))) {
|
||||
// If location of key is maximal, we're appending
|
||||
$this->_body = $this->_body + $ins;
|
||||
} else {
|
||||
// Otherwise, insert at location specified
|
||||
$pre = array_slice($this->_body, 0, $loc);
|
||||
$post = array_slice($this->_body, $loc);
|
||||
$this->_body = $pre + $ins + $post;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo the body segments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function outputBody()
|
||||
{
|
||||
$body = implode('', $this->_body);
|
||||
echo $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an exception with the response
|
||||
*
|
||||
* @param Exception $e
|
||||
* @return Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public function setException(Exception $e)
|
||||
{
|
||||
$this->_exceptions[] = $e;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the exception stack
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getException()
|
||||
{
|
||||
return $this->_exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has an exception been registered with the response?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isException()
|
||||
{
|
||||
return !empty($this->_exceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the response object contain an exception of a given type?
|
||||
*
|
||||
* @param string $type
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExceptionOfType($type)
|
||||
{
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($e instanceof $type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the response object contain an exception with a given message?
|
||||
*
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExceptionOfMessage($message)
|
||||
{
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($message == $e->getMessage()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the response object contain an exception with a given code?
|
||||
*
|
||||
* @param int $code
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExceptionOfCode($code)
|
||||
{
|
||||
$code = (int) $code;
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($code == $e->getCode()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all exceptions of a given type
|
||||
*
|
||||
* @param string $type
|
||||
* @return false|array
|
||||
*/
|
||||
public function getExceptionByType($type)
|
||||
{
|
||||
$exceptions = array();
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($e instanceof $type) {
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($exceptions)) {
|
||||
$exceptions = false;
|
||||
}
|
||||
|
||||
return $exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all exceptions of a given message
|
||||
*
|
||||
* @param string $message
|
||||
* @return false|array
|
||||
*/
|
||||
public function getExceptionByMessage($message)
|
||||
{
|
||||
$exceptions = array();
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($message == $e->getMessage()) {
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($exceptions)) {
|
||||
$exceptions = false;
|
||||
}
|
||||
|
||||
return $exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all exceptions of a given code
|
||||
*
|
||||
* @param mixed $code
|
||||
* @return void
|
||||
*/
|
||||
public function getExceptionByCode($code)
|
||||
{
|
||||
$code = (int) $code;
|
||||
$exceptions = array();
|
||||
foreach ($this->_exceptions as $e) {
|
||||
if ($code == $e->getCode()) {
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($exceptions)) {
|
||||
$exceptions = false;
|
||||
}
|
||||
|
||||
return $exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to render exceptions (off by default)
|
||||
*
|
||||
* If called with no arguments or a null argument, returns the value of the
|
||||
* flag; otherwise, sets it and returns the current value.
|
||||
*
|
||||
* @param boolean $flag Optional
|
||||
* @return boolean
|
||||
*/
|
||||
public function renderExceptions($flag = null)
|
||||
{
|
||||
if (null !== $flag) {
|
||||
$this->_renderExceptions = $flag ? true : false;
|
||||
}
|
||||
|
||||
return $this->_renderExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the response, including all headers, rendering exceptions if so
|
||||
* requested.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendResponse()
|
||||
{
|
||||
$this->sendHeaders();
|
||||
|
||||
if ($this->isException() && $this->renderExceptions()) {
|
||||
$exceptions = '';
|
||||
foreach ($this->getException() as $e) {
|
||||
$exceptions .= $e->__toString() . "\n";
|
||||
}
|
||||
echo $exceptions;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->outputBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __toString functionality
|
||||
*
|
||||
* Proxies to {@link sendResponse()} and returns response value as string
|
||||
* using output buffering.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
ob_start();
|
||||
$this->sendResponse();
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
68
airtime_mvc/library/Zend/Controller/Response/Cli.php
Normal file
68
airtime_mvc/library/Zend/Controller/Response/Cli.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cli.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Response_Abstract */
|
||||
require_once 'Zend/Controller/Response/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_Cli
|
||||
*
|
||||
* CLI response for controllers
|
||||
*
|
||||
* @uses Zend_Controller_Response_Abstract
|
||||
* @package Zend_Controller
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Response_Cli extends Zend_Controller_Response_Abstract
|
||||
{
|
||||
/**
|
||||
* Flag; if true, when header operations are called after headers have been
|
||||
* sent, an exception will be raised; otherwise, processing will continue
|
||||
* as normal. Defaults to false.
|
||||
*
|
||||
* @see canSendHeaders()
|
||||
* @var boolean
|
||||
*/
|
||||
public $headersSentThrowsException = false;
|
||||
|
||||
|
||||
/**
|
||||
* Magic __toString functionality
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->isException() && $this->renderExceptions()) {
|
||||
$exceptions = '';
|
||||
foreach ($this->getException() as $e) {
|
||||
$exceptions .= $e->__toString() . "\n";
|
||||
}
|
||||
return $exceptions;
|
||||
}
|
||||
|
||||
return $this->_body;
|
||||
}
|
||||
}
|
36
airtime_mvc/library/Zend/Controller/Response/Exception.php
Normal file
36
airtime_mvc/library/Zend/Controller/Response/Exception.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Exception */
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Controller
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Response_Exception extends Zend_Controller_Exception
|
||||
{}
|
||||
|
38
airtime_mvc/library/Zend/Controller/Response/Http.php
Normal file
38
airtime_mvc/library/Zend/Controller/Response/Http.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Response_Abstract */
|
||||
require_once 'Zend/Controller/Response/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_Http
|
||||
*
|
||||
* HTTP response for controllers
|
||||
*
|
||||
* @uses Zend_Controller_Response_Abstract
|
||||
* @package Zend_Controller
|
||||
* @subpackage Response
|
||||
*/
|
||||
class Zend_Controller_Response_Http extends Zend_Controller_Response_Abstract
|
||||
{
|
||||
}
|
130
airtime_mvc/library/Zend/Controller/Response/HttpTestCase.php
Normal file
130
airtime_mvc/library/Zend/Controller/Response/HttpTestCase.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HttpTestCase.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Response_Http
|
||||
*/
|
||||
require_once 'Zend/Controller/Response/Http.php';
|
||||
|
||||
/**
|
||||
* Zend_Controller_Response_HttpTestCase
|
||||
*
|
||||
* @uses Zend_Controller_Response_Http
|
||||
* @package Zend_Controller
|
||||
* @subpackage Response
|
||||
*/
|
||||
class Zend_Controller_Response_HttpTestCase extends Zend_Controller_Response_Http
|
||||
{
|
||||
/**
|
||||
* "send" headers by returning array of all headers that would be sent
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sendHeaders()
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($this->_headersRaw as $header) {
|
||||
$headers[] = $header;
|
||||
}
|
||||
foreach ($this->_headers as $header) {
|
||||
$name = $header['name'];
|
||||
$key = strtolower($name);
|
||||
if (array_key_exists($name, $headers)) {
|
||||
if ($header['replace']) {
|
||||
$headers[$key] = $header['name'] . ': ' . $header['value'];
|
||||
}
|
||||
} else {
|
||||
$headers[$key] = $header['name'] . ': ' . $header['value'];
|
||||
}
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we send headers?
|
||||
*
|
||||
* @param bool $throw
|
||||
* @return void
|
||||
*/
|
||||
public function canSendHeaders($throw = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the concatenated body segments
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function outputBody()
|
||||
{
|
||||
$fullContent = '';
|
||||
foreach ($this->_body as $content) {
|
||||
$fullContent .= $content;
|
||||
}
|
||||
return $fullContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get body and/or body segments
|
||||
*
|
||||
* @param bool|string $spec
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getBody($spec = false)
|
||||
{
|
||||
if (false === $spec) {
|
||||
return $this->outputBody();
|
||||
} elseif (true === $spec) {
|
||||
return $this->_body;
|
||||
} elseif (is_string($spec) && isset($this->_body[$spec])) {
|
||||
return $this->_body[$spec];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* "send" Response
|
||||
*
|
||||
* Concats all response headers, and then final body (separated by two
|
||||
* newlines)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sendResponse()
|
||||
{
|
||||
$headers = $this->sendHeaders();
|
||||
$content = implode("\n", $headers) . "\n\n";
|
||||
|
||||
if ($this->isException() && $this->renderExceptions()) {
|
||||
$exceptions = '';
|
||||
foreach ($this->getException() as $e) {
|
||||
$exceptions .= $e->__toString() . "\n";
|
||||
}
|
||||
$content .= $exceptions;
|
||||
} else {
|
||||
$content .= $this->outputBody();
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
170
airtime_mvc/library/Zend/Controller/Router/Abstract.php
Normal file
170
airtime_mvc/library/Zend/Controller/Router/Abstract.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Router_Interface */
|
||||
require_once 'Zend/Controller/Router/Interface.php';
|
||||
|
||||
/**
|
||||
* Simple first implementation of a router, to be replaced
|
||||
* with rules-based URI processor.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
|
||||
{
|
||||
/**
|
||||
* Front controller instance
|
||||
* @var Zend_Controller_Front
|
||||
*/
|
||||
protected $_frontController;
|
||||
|
||||
/**
|
||||
* Array of invocation parameters to use when instantiating action
|
||||
* controllers
|
||||
* @var array
|
||||
*/
|
||||
protected $_invokeParams = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $params = array())
|
||||
{
|
||||
$this->setParams($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or modify a parameter to use when instantiating an action controller
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Router
|
||||
*/
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
$name = (string) $name;
|
||||
$this->_invokeParams[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameters to pass to action controller constructors
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Controller_Router
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
$this->_invokeParams = array_merge($this->_invokeParams, $params);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single parameter from the controller parameter stack
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name)
|
||||
{
|
||||
if(isset($this->_invokeParams[$name])) {
|
||||
return $this->_invokeParams[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve action controller instantiation parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_invokeParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the controller parameter stack
|
||||
*
|
||||
* By default, clears all parameters. If a parameter name is given, clears
|
||||
* only that parameter; if an array of parameter names is provided, clears
|
||||
* each.
|
||||
*
|
||||
* @param null|string|array single key or array of keys for params to clear
|
||||
* @return Zend_Controller_Router
|
||||
*/
|
||||
public function clearParams($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$this->_invokeParams = array();
|
||||
} elseif (is_string($name) && isset($this->_invokeParams[$name])) {
|
||||
unset($this->_invokeParams[$name]);
|
||||
} elseif (is_array($name)) {
|
||||
foreach ($name as $key) {
|
||||
if (is_string($key) && isset($this->_invokeParams[$key])) {
|
||||
unset($this->_invokeParams[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Front Controller
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController()
|
||||
{
|
||||
// Used cache version if found
|
||||
if (null !== $this->_frontController) {
|
||||
return $this->_frontController;
|
||||
}
|
||||
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
$this->_frontController = Zend_Controller_Front::getInstance();
|
||||
return $this->_frontController;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Front Controller
|
||||
*
|
||||
* @param Zend_Controller_Front $controller
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function setFrontController(Zend_Controller_Front $controller)
|
||||
{
|
||||
$this->_frontController = $controller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
36
airtime_mvc/library/Zend/Controller/Router/Exception.php
Normal file
36
airtime_mvc/library/Zend/Controller/Router/Exception.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Exception */
|
||||
require_once 'Zend/Controller/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Router_Exception extends Zend_Controller_Exception
|
||||
{}
|
||||
|
124
airtime_mvc/library/Zend/Controller/Router/Interface.php
Normal file
124
airtime_mvc/library/Zend/Controller/Router/Interface.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Controller_Router_Interface
|
||||
{
|
||||
/**
|
||||
* Processes a request and sets its controller and action. If
|
||||
* no route was possible, an exception is thrown.
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Request_Abstract|boolean
|
||||
*/
|
||||
public function route(Zend_Controller_Request_Abstract $dispatcher);
|
||||
|
||||
/**
|
||||
* Generates a URL path that can be used in URL creation, redirection, etc.
|
||||
*
|
||||
* May be passed user params to override ones from URI, Request or even defaults.
|
||||
* If passed parameter has a value of null, it's URL variable will be reset to
|
||||
* default.
|
||||
*
|
||||
* If null is passed as a route name assemble will use the current Route or 'default'
|
||||
* if current is not yet set.
|
||||
*
|
||||
* Reset is used to signal that all parameters should be reset to it's defaults.
|
||||
* Ignoring all URL specified values. User specified params still get precedence.
|
||||
*
|
||||
* Encode tells to url encode resulting path parts.
|
||||
*
|
||||
* @param array $userParams Options passed by a user used to override parameters
|
||||
* @param mixed $name The name of a Route to use
|
||||
* @param bool $reset Whether to reset to the route defaults ignoring URL params
|
||||
* @param bool $encode Tells to encode URL parts on output
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return string Resulting URL path
|
||||
*/
|
||||
public function assemble($userParams, $name = null, $reset = false, $encode = true);
|
||||
|
||||
/**
|
||||
* Retrieve Front Controller
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController();
|
||||
|
||||
/**
|
||||
* Set Front Controller
|
||||
*
|
||||
* @param Zend_Controller_Front $controller
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function setFrontController(Zend_Controller_Front $controller);
|
||||
|
||||
/**
|
||||
* Add or modify a parameter with which to instantiate any helper objects
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $param
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function setParam($name, $value);
|
||||
|
||||
/**
|
||||
* Set an array of a parameters to pass to helper object constructors
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function setParams(array $params);
|
||||
|
||||
/**
|
||||
* Retrieve a single parameter from the controller parameter stack
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name);
|
||||
|
||||
/**
|
||||
* Retrieve the parameters to pass to helper object constructors
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams();
|
||||
|
||||
/**
|
||||
* Clear the controller parameter stack
|
||||
*
|
||||
* By default, clears all parameters. If a parameter name is given, clears
|
||||
* only that parameter; if an array of parameter names is provided, clears
|
||||
* each.
|
||||
*
|
||||
* @param null|string|array single key or array of keys for params to clear
|
||||
* @return Zend_Controller_Router_Interface
|
||||
*/
|
||||
public function clearParams($name = null);
|
||||
|
||||
}
|
528
airtime_mvc/library/Zend/Controller/Router/Rewrite.php
Normal file
528
airtime_mvc/library/Zend/Controller/Router/Rewrite.php
Normal file
|
@ -0,0 +1,528 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Rewrite.php 20246 2010-01-12 21:36:08Z dasprid $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Abstract */
|
||||
require_once 'Zend/Controller/Router/Abstract.php';
|
||||
|
||||
/** Zend_Controller_Router_Route */
|
||||
require_once 'Zend/Controller/Router/Route.php';
|
||||
|
||||
/**
|
||||
* Ruby routing based Router.
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://manuals.rubyonrails.com/read/chapter/65
|
||||
*/
|
||||
class Zend_Controller_Router_Rewrite extends Zend_Controller_Router_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Whether or not to use default routes
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useDefaultRoutes = true;
|
||||
|
||||
/**
|
||||
* Array of routes to match against
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_routes = array();
|
||||
|
||||
/**
|
||||
* Currently matched route
|
||||
*
|
||||
* @var Zend_Controller_Router_Route_Interface
|
||||
*/
|
||||
protected $_currentRoute = null;
|
||||
|
||||
/**
|
||||
* Global parameters given to all routes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_globalParams = array();
|
||||
|
||||
/**
|
||||
* Separator to use with chain names
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_chainNameSeparator = '-';
|
||||
|
||||
/**
|
||||
* Determines if request parameters should be used as global parameters
|
||||
* inside this router.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useCurrentParamsAsGlobal = false;
|
||||
|
||||
/**
|
||||
* Add default routes which are used to mimic basic router behaviour
|
||||
*
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function addDefaultRoutes()
|
||||
{
|
||||
if (!$this->hasRoute('default')) {
|
||||
$dispatcher = $this->getFrontController()->getDispatcher();
|
||||
$request = $this->getFrontController()->getRequest();
|
||||
|
||||
require_once 'Zend/Controller/Router/Route/Module.php';
|
||||
$compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
|
||||
|
||||
$this->_routes = array_merge(array('default' => $compat), $this->_routes);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add route to the route chain
|
||||
*
|
||||
* If route contains method setRequest(), it is initialized with a request object
|
||||
*
|
||||
* @param string $name Name of the route
|
||||
* @param Zend_Controller_Router_Route_Interface $route Instance of the route
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function addRoute($name, Zend_Controller_Router_Route_Interface $route)
|
||||
{
|
||||
if (method_exists($route, 'setRequest')) {
|
||||
$route->setRequest($this->getFrontController()->getRequest());
|
||||
}
|
||||
|
||||
$this->_routes[$name] = $route;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add routes to the route chain
|
||||
*
|
||||
* @param array $routes Array of routes with names as keys and routes as values
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function addRoutes($routes) {
|
||||
foreach ($routes as $name => $route) {
|
||||
$this->addRoute($name, $route);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create routes out of Zend_Config configuration
|
||||
*
|
||||
* Example INI:
|
||||
* routes.archive.route = "archive/:year/*"
|
||||
* routes.archive.defaults.controller = archive
|
||||
* routes.archive.defaults.action = show
|
||||
* routes.archive.defaults.year = 2000
|
||||
* routes.archive.reqs.year = "\d+"
|
||||
*
|
||||
* routes.news.type = "Zend_Controller_Router_Route_Static"
|
||||
* routes.news.route = "news"
|
||||
* routes.news.defaults.controller = "news"
|
||||
* routes.news.defaults.action = "list"
|
||||
*
|
||||
* And finally after you have created a Zend_Config with above ini:
|
||||
* $router = new Zend_Controller_Router_Rewrite();
|
||||
* $router->addConfig($config, 'routes');
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
* @param string $section Name of the config section containing route's definitions
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function addConfig(Zend_Config $config, $section = null)
|
||||
{
|
||||
if ($section !== null) {
|
||||
if ($config->{$section} === null) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("No route configuration in section '{$section}'");
|
||||
}
|
||||
|
||||
$config = $config->{$section};
|
||||
}
|
||||
|
||||
foreach ($config as $name => $info) {
|
||||
$route = $this->_getRouteFromConfig($info);
|
||||
|
||||
if ($route instanceof Zend_Controller_Router_Route_Chain) {
|
||||
if (!isset($info->chain)) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("No chain defined");
|
||||
}
|
||||
|
||||
if ($info->chain instanceof Zend_Config) {
|
||||
$childRouteNames = $info->chain;
|
||||
} else {
|
||||
$childRouteNames = explode(',', $info->chain);
|
||||
}
|
||||
|
||||
foreach ($childRouteNames as $childRouteName) {
|
||||
$childRoute = $this->getRoute(trim($childRouteName));
|
||||
$route->chain($childRoute);
|
||||
}
|
||||
|
||||
$this->addRoute($name, $route);
|
||||
} elseif (isset($info->chains) && $info->chains instanceof Zend_Config) {
|
||||
$this->_addChainRoutesFromConfig($name, $route, $info->chains);
|
||||
} else {
|
||||
$this->addRoute($name, $route);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a route frm a config instance
|
||||
*
|
||||
* @param Zend_Config $info
|
||||
* @return Zend_Controller_Router_Route_Interface
|
||||
*/
|
||||
protected function _getRouteFromConfig(Zend_Config $info)
|
||||
{
|
||||
$class = (isset($info->type)) ? $info->type : 'Zend_Controller_Router_Route';
|
||||
if (!class_exists($class)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($class);
|
||||
}
|
||||
|
||||
$route = call_user_func(array($class, 'getInstance'), $info);
|
||||
|
||||
if (isset($info->abstract) && $info->abstract && method_exists($route, 'isAbstract')) {
|
||||
$route->isAbstract(true);
|
||||
}
|
||||
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add chain routes from a config route
|
||||
*
|
||||
* @param string $name
|
||||
* @param Zend_Controller_Router_Route_Interface $route
|
||||
* @param Zend_Config $childRoutesInfo
|
||||
* @return void
|
||||
*/
|
||||
protected function _addChainRoutesFromConfig($name,
|
||||
Zend_Controller_Router_Route_Interface $route,
|
||||
Zend_Config $childRoutesInfo)
|
||||
{
|
||||
foreach ($childRoutesInfo as $childRouteName => $childRouteInfo) {
|
||||
if (is_string($childRouteInfo)) {
|
||||
$childRouteName = $childRouteInfo;
|
||||
$childRoute = $this->getRoute($childRouteName);
|
||||
} else {
|
||||
$childRoute = $this->_getRouteFromConfig($childRouteInfo);
|
||||
}
|
||||
|
||||
if ($route instanceof Zend_Controller_Router_Route_Chain) {
|
||||
$chainRoute = clone $route;
|
||||
$chainRoute->chain($childRoute);
|
||||
} else {
|
||||
$chainRoute = $route->chain($childRoute);
|
||||
}
|
||||
|
||||
$chainName = $name . $this->_chainNameSeparator . $childRouteName;
|
||||
|
||||
if (isset($childRouteInfo->chains)) {
|
||||
$this->_addChainRoutesFromConfig($chainName, $chainRoute, $childRouteInfo->chains);
|
||||
} else {
|
||||
$this->addRoute($chainName, $chainRoute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a route from the route chain
|
||||
*
|
||||
* @param string $name Name of the route
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function removeRoute($name)
|
||||
{
|
||||
if (!isset($this->_routes[$name])) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("Route $name is not defined");
|
||||
}
|
||||
|
||||
unset($this->_routes[$name]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all standard default routes
|
||||
*
|
||||
* @param Zend_Controller_Router_Route_Interface Route
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function removeDefaultRoutes()
|
||||
{
|
||||
$this->_useDefaultRoutes = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if named route exists
|
||||
*
|
||||
* @param string $name Name of the route
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasRoute($name)
|
||||
{
|
||||
return isset($this->_routes[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a named route
|
||||
*
|
||||
* @param string $name Name of the route
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Router_Route_Interface Route object
|
||||
*/
|
||||
public function getRoute($name)
|
||||
{
|
||||
if (!isset($this->_routes[$name])) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("Route $name is not defined");
|
||||
}
|
||||
|
||||
return $this->_routes[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a currently matched route
|
||||
*
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Router_Route_Interface Route object
|
||||
*/
|
||||
public function getCurrentRoute()
|
||||
{
|
||||
if (!isset($this->_currentRoute)) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("Current route is not defined");
|
||||
}
|
||||
return $this->getRoute($this->_currentRoute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a name of currently matched route
|
||||
*
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Router_Route_Interface Route object
|
||||
*/
|
||||
public function getCurrentRouteName()
|
||||
{
|
||||
if (!isset($this->_currentRoute)) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception("Current route is not defined");
|
||||
}
|
||||
return $this->_currentRoute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an array of routes added to the route chain
|
||||
*
|
||||
* @return array All of the defined routes
|
||||
*/
|
||||
public function getRoutes()
|
||||
{
|
||||
return $this->_routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a matching route to the current PATH_INFO and inject
|
||||
* returning values to the Request object.
|
||||
*
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return Zend_Controller_Request_Abstract Request object
|
||||
*/
|
||||
public function route(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
if (!$request instanceof Zend_Controller_Request_Http) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object');
|
||||
}
|
||||
|
||||
if ($this->_useDefaultRoutes) {
|
||||
$this->addDefaultRoutes();
|
||||
}
|
||||
|
||||
// Find the matching route
|
||||
$routeMatched = false;
|
||||
|
||||
foreach (array_reverse($this->_routes) as $name => $route) {
|
||||
// TODO: Should be an interface method. Hack for 1.0 BC
|
||||
if (method_exists($route, 'isAbstract') && $route->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Should be an interface method. Hack for 1.0 BC
|
||||
if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
|
||||
$match = $request->getPathInfo();
|
||||
} else {
|
||||
$match = $request;
|
||||
}
|
||||
|
||||
if ($params = $route->match($match)) {
|
||||
$this->_setRequestParams($request, $params);
|
||||
$this->_currentRoute = $name;
|
||||
$routeMatched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$routeMatched) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception('No route matched the request', 404);
|
||||
}
|
||||
|
||||
if($this->_useCurrentParamsAsGlobal) {
|
||||
$params = $request->getParams();
|
||||
foreach($params as $param => $value) {
|
||||
$this->setGlobalParam($param, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $request;
|
||||
|
||||
}
|
||||
|
||||
protected function _setRequestParams($request, $params)
|
||||
{
|
||||
foreach ($params as $param => $value) {
|
||||
|
||||
$request->setParam($param, $value);
|
||||
|
||||
if ($param === $request->getModuleKey()) {
|
||||
$request->setModuleName($value);
|
||||
}
|
||||
if ($param === $request->getControllerKey()) {
|
||||
$request->setControllerName($value);
|
||||
}
|
||||
if ($param === $request->getActionKey()) {
|
||||
$request->setActionName($value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a URL path that can be used in URL creation, redirection, etc.
|
||||
*
|
||||
* @param array $userParams Options passed by a user used to override parameters
|
||||
* @param mixed $name The name of a Route to use
|
||||
* @param bool $reset Whether to reset to the route defaults ignoring URL params
|
||||
* @param bool $encode Tells to encode URL parts on output
|
||||
* @throws Zend_Controller_Router_Exception
|
||||
* @return string Resulting absolute URL path
|
||||
*/
|
||||
public function assemble($userParams, $name = null, $reset = false, $encode = true)
|
||||
{
|
||||
if ($name == null) {
|
||||
try {
|
||||
$name = $this->getCurrentRouteName();
|
||||
} catch (Zend_Controller_Router_Exception $e) {
|
||||
$name = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
$params = array_merge($this->_globalParams, $userParams);
|
||||
|
||||
$route = $this->getRoute($name);
|
||||
$url = $route->assemble($params, $reset, $encode);
|
||||
|
||||
if (!preg_match('|^[a-z]+://|', $url)) {
|
||||
$url = rtrim($this->getFrontController()->getBaseUrl(), '/') . '/' . $url;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global parameter
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function setGlobalParam($name, $value)
|
||||
{
|
||||
$this->_globalParams[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the separator to use with chain names
|
||||
*
|
||||
* @param string $separator The separator to use
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function setChainNameSeparator($separator) {
|
||||
$this->_chainNameSeparator = $separator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the separator to use for chain names
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getChainNameSeparator() {
|
||||
return $this->_chainNameSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines/returns whether to use the request parameters as global parameters.
|
||||
*
|
||||
* @param boolean|null $use
|
||||
* Null/unset when you want to retrieve the current state.
|
||||
* True when request parameters should be global, false otherwise
|
||||
* @return boolean|Zend_Controller_Router_Rewrite
|
||||
* Returns a boolean if first param isn't set, returns an
|
||||
* instance of Zend_Controller_Router_Rewrite otherwise.
|
||||
*
|
||||
*/
|
||||
public function useRequestParametersAsGlobal($use = null) {
|
||||
if($use === null) {
|
||||
return $this->_useCurrentParamsAsGlobal;
|
||||
}
|
||||
|
||||
$this->_useCurrentParamsAsGlobal = (bool) $use;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
559
airtime_mvc/library/Zend/Controller/Router/Route.php
Normal file
559
airtime_mvc/library/Zend/Controller/Router/Route.php
Normal file
|
@ -0,0 +1,559 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Route.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* Route
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://manuals.rubyonrails.com/read/chapter/65
|
||||
*/
|
||||
class Zend_Controller_Router_Route extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
/**
|
||||
* Default translator
|
||||
*
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected static $_defaultTranslator;
|
||||
|
||||
/**
|
||||
* Translator
|
||||
*
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* Default locale
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected static $_defaultLocale;
|
||||
|
||||
/**
|
||||
* Locale
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_locale;
|
||||
|
||||
/**
|
||||
* Wether this is a translated route or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isTranslated = false;
|
||||
|
||||
/**
|
||||
* Translatable variables
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_translatable = array();
|
||||
|
||||
protected $_urlVariable = ':';
|
||||
protected $_urlDelimiter = '/';
|
||||
protected $_regexDelimiter = '#';
|
||||
protected $_defaultRegex = null;
|
||||
|
||||
/**
|
||||
* Holds names of all route's pattern variable names. Array index holds a position in URL.
|
||||
* @var array
|
||||
*/
|
||||
protected $_variables = array();
|
||||
|
||||
/**
|
||||
* Holds Route patterns for all URL parts. In case of a variable it stores it's regex
|
||||
* requirement or null. In case of a static part, it holds only it's direct value.
|
||||
* In case of a wildcard, it stores an asterisk (*)
|
||||
* @var array
|
||||
*/
|
||||
protected $_parts = array();
|
||||
|
||||
/**
|
||||
* Holds user submitted default values for route's variables. Name and value pairs.
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaults = array();
|
||||
|
||||
/**
|
||||
* Holds user submitted regular expression patterns for route's variables' values.
|
||||
* Name and value pairs.
|
||||
* @var array
|
||||
*/
|
||||
protected $_requirements = array();
|
||||
|
||||
/**
|
||||
* Associative array filled on match() that holds matched path values
|
||||
* for given variable names.
|
||||
* @var array
|
||||
*/
|
||||
protected $_values = array();
|
||||
|
||||
/**
|
||||
* Associative array filled on match() that holds wildcard variable
|
||||
* names and values.
|
||||
* @var array
|
||||
*/
|
||||
protected $_wildcardData = array();
|
||||
|
||||
/**
|
||||
* Helper var that holds a count of route pattern's static parts
|
||||
* for validation
|
||||
* @var int
|
||||
*/
|
||||
protected $_staticCount = 0;
|
||||
|
||||
public function getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array();
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
return new self($config->route, $defs, $reqs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the route for mapping by splitting (exploding) it
|
||||
* to a corresponding atomic parts. These parts are assigned
|
||||
* a position which is later used for matching and preparing values.
|
||||
*
|
||||
* @param string $route Map used to match with later submitted URL path
|
||||
* @param array $defaults Defaults for map variables with keys as variable names
|
||||
* @param array $reqs Regular expression requirements for variables (keys as variable names)
|
||||
* @param Zend_Translate $translator Translator to use for this instance
|
||||
*/
|
||||
public function __construct($route, $defaults = array(), $reqs = array(), Zend_Translate $translator = null, $locale = null)
|
||||
{
|
||||
$route = trim($route, $this->_urlDelimiter);
|
||||
$this->_defaults = (array) $defaults;
|
||||
$this->_requirements = (array) $reqs;
|
||||
$this->_translator = $translator;
|
||||
$this->_locale = $locale;
|
||||
|
||||
if ($route !== '') {
|
||||
foreach (explode($this->_urlDelimiter, $route) as $pos => $part) {
|
||||
if (substr($part, 0, 1) == $this->_urlVariable && substr($part, 1, 1) != $this->_urlVariable) {
|
||||
$name = substr($part, 1);
|
||||
|
||||
if (substr($name, 0, 1) === '@' && substr($name, 1, 1) !== '@') {
|
||||
$name = substr($name, 1);
|
||||
$this->_translatable[] = $name;
|
||||
$this->_isTranslated = true;
|
||||
}
|
||||
|
||||
$this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
|
||||
$this->_variables[$pos] = $name;
|
||||
} else {
|
||||
if (substr($part, 0, 1) == $this->_urlVariable) {
|
||||
$part = substr($part, 1);
|
||||
}
|
||||
|
||||
if (substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@') {
|
||||
$this->_isTranslated = true;
|
||||
}
|
||||
|
||||
$this->_parts[$pos] = $part;
|
||||
|
||||
if ($part !== '*') {
|
||||
$this->_staticCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path with parts defined by a map. Assigns and
|
||||
* returns an array of variables on a successful match.
|
||||
*
|
||||
* @param string $path Path used to match against this routing map
|
||||
* @return array|false An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($path, $partial = false)
|
||||
{
|
||||
if ($this->_isTranslated) {
|
||||
$translateMessages = $this->getTranslator()->getMessages();
|
||||
}
|
||||
|
||||
$pathStaticCount = 0;
|
||||
$values = array();
|
||||
$matchedPath = '';
|
||||
|
||||
if (!$partial) {
|
||||
$path = trim($path, $this->_urlDelimiter);
|
||||
}
|
||||
|
||||
if ($path !== '') {
|
||||
$path = explode($this->_urlDelimiter, $path);
|
||||
|
||||
foreach ($path as $pos => $pathPart) {
|
||||
// Path is longer than a route, it's not a match
|
||||
if (!array_key_exists($pos, $this->_parts)) {
|
||||
if ($partial) {
|
||||
break;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$matchedPath .= $pathPart . $this->_urlDelimiter;
|
||||
|
||||
// If it's a wildcard, get the rest of URL as wildcard data and stop matching
|
||||
if ($this->_parts[$pos] == '*') {
|
||||
$count = count($path);
|
||||
for($i = $pos; $i < $count; $i+=2) {
|
||||
$var = urldecode($path[$i]);
|
||||
if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) {
|
||||
$this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null;
|
||||
}
|
||||
}
|
||||
|
||||
$matchedPath = implode($this->_urlDelimiter, $path);
|
||||
break;
|
||||
}
|
||||
|
||||
$name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
|
||||
$pathPart = urldecode($pathPart);
|
||||
|
||||
// Translate value if required
|
||||
$part = $this->_parts[$pos];
|
||||
if ($this->_isTranslated && (substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@' && $name === null) || $name !== null && in_array($name, $this->_translatable)) {
|
||||
if (substr($part, 0, 1) === '@') {
|
||||
$part = substr($part, 1);
|
||||
}
|
||||
|
||||
if (($originalPathPart = array_search($pathPart, $translateMessages)) !== false) {
|
||||
$pathPart = $originalPathPart;
|
||||
}
|
||||
}
|
||||
|
||||
if (substr($part, 0, 2) === '@@') {
|
||||
$part = substr($part, 1);
|
||||
}
|
||||
|
||||
// If it's a static part, match directly
|
||||
if ($name === null && $part != $pathPart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's a variable with requirement, match a regex. If not - everything matches
|
||||
if ($part !== null && !preg_match($this->_regexDelimiter . '^' . $part . '$' . $this->_regexDelimiter . 'iu', $pathPart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's a variable store it's value for later
|
||||
if ($name !== null) {
|
||||
$values[$name] = $pathPart;
|
||||
} else {
|
||||
$pathStaticCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all static mappings have been matched
|
||||
if ($this->_staticCount != $pathStaticCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$return = $values + $this->_wildcardData + $this->_defaults;
|
||||
|
||||
// Check if all map variables have been initialized
|
||||
foreach ($this->_variables as $var) {
|
||||
if (!array_key_exists($var, $return)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setMatchedPath(rtrim($matchedPath, $this->_urlDelimiter));
|
||||
|
||||
$this->_values = $values;
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles user submitted parameters forming a URL path defined by this route
|
||||
*
|
||||
* @param array $data An array of variable and value pairs used as parameters
|
||||
* @param boolean $reset Whether or not to set route defaults with those provided in $data
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
|
||||
{
|
||||
if ($this->_isTranslated) {
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
if (isset($data['@locale'])) {
|
||||
$locale = $data['@locale'];
|
||||
unset($data['@locale']);
|
||||
} else {
|
||||
$locale = $this->getLocale();
|
||||
}
|
||||
}
|
||||
|
||||
$url = array();
|
||||
$flag = false;
|
||||
|
||||
foreach ($this->_parts as $key => $part) {
|
||||
$name = isset($this->_variables[$key]) ? $this->_variables[$key] : null;
|
||||
|
||||
$useDefault = false;
|
||||
if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) {
|
||||
$useDefault = true;
|
||||
}
|
||||
|
||||
if (isset($name)) {
|
||||
if (isset($data[$name]) && !$useDefault) {
|
||||
$value = $data[$name];
|
||||
unset($data[$name]);
|
||||
} elseif (!$reset && !$useDefault && isset($this->_values[$name])) {
|
||||
$value = $this->_values[$name];
|
||||
} elseif (!$reset && !$useDefault && isset($this->_wildcardData[$name])) {
|
||||
$value = $this->_wildcardData[$name];
|
||||
} elseif (isset($this->_defaults[$name])) {
|
||||
$value = $this->_defaults[$name];
|
||||
} else {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception($name . ' is not specified');
|
||||
}
|
||||
|
||||
if ($this->_isTranslated && in_array($name, $this->_translatable)) {
|
||||
$url[$key] = $translator->translate($value, $locale);
|
||||
} else {
|
||||
$url[$key] = $value;
|
||||
}
|
||||
} elseif ($part != '*') {
|
||||
if ($this->_isTranslated && substr($part, 0, 1) === '@') {
|
||||
if (substr($part, 1, 1) !== '@') {
|
||||
$url[$key] = $translator->translate(substr($part, 1), $locale);
|
||||
} else {
|
||||
$url[$key] = substr($part, 1);
|
||||
}
|
||||
} else {
|
||||
if (substr($part, 0, 2) === '@@') {
|
||||
$part = substr($part, 1);
|
||||
}
|
||||
|
||||
$url[$key] = $part;
|
||||
}
|
||||
} else {
|
||||
if (!$reset) $data += $this->_wildcardData;
|
||||
$defaults = $this->getDefaults();
|
||||
foreach ($data as $var => $value) {
|
||||
if ($value !== null && (!isset($defaults[$var]) || $value != $defaults[$var])) {
|
||||
$url[$key++] = $var;
|
||||
$url[$key++] = $value;
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$return = '';
|
||||
|
||||
foreach (array_reverse($url, true) as $key => $value) {
|
||||
$defaultValue = null;
|
||||
|
||||
if (isset($this->_variables[$key])) {
|
||||
$defaultValue = $this->getDefault($this->_variables[$key]);
|
||||
|
||||
if ($this->_isTranslated && $defaultValue !== null && isset($this->_translatable[$this->_variables[$key]])) {
|
||||
$defaultValue = $translator->translate($defaultValue, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
if ($flag || $value !== $defaultValue || $partial) {
|
||||
if ($encode) $value = urlencode($value);
|
||||
$return = $this->_urlDelimiter . $value . $return;
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return trim($return, $this->_urlDelimiter);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single parameter of route's defaults
|
||||
*
|
||||
* @param string $name Array key of the parameter
|
||||
* @return string Previously set default
|
||||
*/
|
||||
public function getDefault($name) {
|
||||
if (isset($this->_defaults[$name])) {
|
||||
return $this->_defaults[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of defaults
|
||||
*
|
||||
* @return array Route defaults
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all variables which are used by the route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables()
|
||||
{
|
||||
return $this->_variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a default translator
|
||||
*
|
||||
* @param Zend_Translate $translator
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultTranslator(Zend_Translate $translator = null)
|
||||
{
|
||||
self::$_defaultTranslator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default translator
|
||||
*
|
||||
* @return Zend_Translate
|
||||
*/
|
||||
public static function getDefaultTranslator()
|
||||
{
|
||||
return self::$_defaultTranslator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a translator
|
||||
*
|
||||
* @param Zend_Translate $translator
|
||||
* @return void
|
||||
*/
|
||||
public function setTranslator(Zend_Translate $translator)
|
||||
{
|
||||
$this->_translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translator
|
||||
*
|
||||
* @throws Zend_Controller_Router_Exception When no translator can be found
|
||||
* @return Zend_Translate
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
if ($this->_translator !== null) {
|
||||
return $this->_translator;
|
||||
} else if (($translator = self::getDefaultTranslator()) !== null) {
|
||||
return $translator;
|
||||
} else {
|
||||
try {
|
||||
$translator = Zend_Registry::get('Zend_Translate');
|
||||
} catch (Zend_Exception $e) {
|
||||
$translator = null;
|
||||
}
|
||||
|
||||
if ($translator instanceof Zend_Translate) {
|
||||
return $translator;
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception('Could not find a translator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a default locale
|
||||
*
|
||||
* @param mixed $locale
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultLocale($locale = null)
|
||||
{
|
||||
self::$_defaultLocale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getDefaultLocale()
|
||||
{
|
||||
return self::$_defaultLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a locale
|
||||
*
|
||||
* @param mixed $locale
|
||||
* @return void
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->_locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
if ($this->_locale !== null) {
|
||||
return $this->_locale;
|
||||
} else if (($locale = self::getDefaultLocale()) !== null) {
|
||||
return $locale;
|
||||
} else {
|
||||
try {
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
} catch (Zend_Exception $e) {
|
||||
$locale = null;
|
||||
}
|
||||
|
||||
if ($locale !== null) {
|
||||
return $locale;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
117
airtime_mvc/library/Zend/Controller/Router/Route/Abstract.php
Normal file
117
airtime_mvc/library/Zend/Controller/Router/Route/Abstract.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Controller_Router_Route_Interface
|
||||
*/
|
||||
require_once 'Zend/Controller/Router/Route/Interface.php';
|
||||
|
||||
/**
|
||||
* Abstract Route
|
||||
*
|
||||
* Implements interface and provides convenience methods
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Controller_Router_Route_Abstract implements Zend_Controller_Router_Route_Interface
|
||||
{
|
||||
/**
|
||||
* Wether this route is abstract or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isAbstract = false;
|
||||
|
||||
/**
|
||||
* Path matched by this route
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_matchedPath = null;
|
||||
|
||||
/**
|
||||
* Get the version of the route
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set partially matched path
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function setMatchedPath($path)
|
||||
{
|
||||
$this->_matchedPath = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get partially matched path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMatchedPath()
|
||||
{
|
||||
return $this->_matchedPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check or set wether this is an abstract route or not
|
||||
*
|
||||
* @param boolean $flag
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAbstract($flag = null)
|
||||
{
|
||||
if ($flag !== null) {
|
||||
$this->_isAbstract = $flag;
|
||||
}
|
||||
|
||||
return $this->_isAbstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new chain
|
||||
*
|
||||
* @param Zend_Controller_Router_Route_Abstract $route
|
||||
* @param string $separator
|
||||
* @return Zend_Controller_Router_Route_Chain
|
||||
*/
|
||||
public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = '/')
|
||||
{
|
||||
require_once 'Zend/Controller/Router/Route/Chain.php';
|
||||
|
||||
$chain = new Zend_Controller_Router_Route_Chain();
|
||||
$chain->chain($this)->chain($route, $separator);
|
||||
|
||||
return $chain;
|
||||
}
|
||||
|
||||
}
|
169
airtime_mvc/library/Zend/Controller/Router/Route/Chain.php
Normal file
169
airtime_mvc/library/Zend/Controller/Router/Route/Chain.php
Normal file
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Chain.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* Chain route is used for managing route chaining.
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
protected $_routes = array();
|
||||
protected $_separators = array();
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
return new self($config->route, $defs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a route to this chain
|
||||
*
|
||||
* @param Zend_Controller_Router_Route_Abstract $route
|
||||
* @param string $separator
|
||||
* @return Zend_Controller_Router_Route_Chain
|
||||
*/
|
||||
public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = '/')
|
||||
{
|
||||
$this->_routes[] = $route;
|
||||
$this->_separators[] = $separator;
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path with a previously defined route.
|
||||
* Assigns and returns an array of defaults on a successful match.
|
||||
*
|
||||
* @param Zend_Controller_Request_Http $request Request to get the path info from
|
||||
* @return array|false An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($request, $partial = null)
|
||||
{
|
||||
$path = trim($request->getPathInfo(), '/');
|
||||
$subPath = $path;
|
||||
$values = array();
|
||||
|
||||
foreach ($this->_routes as $key => $route) {
|
||||
if ($key > 0 && $matchedPath !== null) {
|
||||
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
|
||||
|
||||
if ($separator !== $this->_separators[$key]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subPath = substr($subPath, strlen($separator));
|
||||
}
|
||||
|
||||
// TODO: Should be an interface method. Hack for 1.0 BC
|
||||
if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
|
||||
$match = $subPath;
|
||||
} else {
|
||||
$request->setPathInfo($subPath);
|
||||
$match = $request;
|
||||
}
|
||||
|
||||
$res = $route->match($match, true);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$matchedPath = $route->getMatchedPath();
|
||||
|
||||
if ($matchedPath !== null) {
|
||||
$subPath = substr($subPath, strlen($matchedPath));
|
||||
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
|
||||
}
|
||||
|
||||
$values = $res + $values;
|
||||
}
|
||||
|
||||
$request->setPathInfo($path);
|
||||
|
||||
if ($subPath !== '' && $subPath !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a URL path defined by this route
|
||||
*
|
||||
* @param array $data An array of variable and value pairs used as parameters
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = false)
|
||||
{
|
||||
$value = '';
|
||||
$numRoutes = count($this->_routes);
|
||||
|
||||
foreach ($this->_routes as $key => $route) {
|
||||
if ($key > 0) {
|
||||
$value .= $this->_separators[$key];
|
||||
}
|
||||
|
||||
$value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key));
|
||||
|
||||
if (method_exists($route, 'getVariables')) {
|
||||
$variables = $route->getVariables();
|
||||
|
||||
foreach ($variables as $variable) {
|
||||
$data[$variable] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request object for this and the child routes
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract|null $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request = null)
|
||||
{
|
||||
$this->_request = $request;
|
||||
|
||||
foreach ($this->_routes as $route) {
|
||||
if (method_exists($route, 'setRequest')) {
|
||||
$route->setRequest($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
342
airtime_mvc/library/Zend/Controller/Router/Route/Hostname.php
Normal file
342
airtime_mvc/library/Zend/Controller/Router/Route/Hostname.php
Normal file
|
@ -0,0 +1,342 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Hostname.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* Hostname Route
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://manuals.rubyonrails.com/read/chapter/65
|
||||
*/
|
||||
class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
|
||||
protected $_hostVariable = ':';
|
||||
protected $_regexDelimiter = '#';
|
||||
protected $_defaultRegex = null;
|
||||
|
||||
/**
|
||||
* Holds names of all route's pattern variable names. Array index holds a position in host.
|
||||
* @var array
|
||||
*/
|
||||
protected $_variables = array();
|
||||
|
||||
/**
|
||||
* Holds Route patterns for all host parts. In case of a variable it stores it's regex
|
||||
* requirement or null. In case of a static part, it holds only it's direct value.
|
||||
* @var array
|
||||
*/
|
||||
protected $_parts = array();
|
||||
|
||||
/**
|
||||
* Holds user submitted default values for route's variables. Name and value pairs.
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaults = array();
|
||||
|
||||
/**
|
||||
* Holds user submitted regular expression patterns for route's variables' values.
|
||||
* Name and value pairs.
|
||||
* @var array
|
||||
*/
|
||||
protected $_requirements = array();
|
||||
|
||||
/**
|
||||
* Default scheme
|
||||
* @var string
|
||||
*/
|
||||
protected $_scheme = null;
|
||||
|
||||
/**
|
||||
* Associative array filled on match() that holds matched path values
|
||||
* for given variable names.
|
||||
* @var array
|
||||
*/
|
||||
protected $_values = array();
|
||||
|
||||
/**
|
||||
* Current request object
|
||||
*
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* Helper var that holds a count of route pattern's static parts
|
||||
* for validation
|
||||
* @var int
|
||||
*/
|
||||
private $_staticCount = 0;
|
||||
|
||||
/**
|
||||
* Set the request object
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract|null $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request = null)
|
||||
{
|
||||
$this->_request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
if ($this->_request === null) {
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
$this->_request = Zend_Controller_Front::getInstance()->getRequest();
|
||||
}
|
||||
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array();
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
$scheme = (isset($config->scheme)) ? $config->scheme : null;
|
||||
return new self($config->route, $defs, $reqs, $scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the route for mapping by splitting (exploding) it
|
||||
* to a corresponding atomic parts. These parts are assigned
|
||||
* a position which is later used for matching and preparing values.
|
||||
*
|
||||
* @param string $route Map used to match with later submitted hostname
|
||||
* @param array $defaults Defaults for map variables with keys as variable names
|
||||
* @param array $reqs Regular expression requirements for variables (keys as variable names)
|
||||
* @param string $scheme
|
||||
*/
|
||||
public function __construct($route, $defaults = array(), $reqs = array(), $scheme = null)
|
||||
{
|
||||
$route = trim($route, '.');
|
||||
$this->_defaults = (array) $defaults;
|
||||
$this->_requirements = (array) $reqs;
|
||||
$this->_scheme = $scheme;
|
||||
|
||||
if ($route != '') {
|
||||
foreach (explode('.', $route) as $pos => $part) {
|
||||
if (substr($part, 0, 1) == $this->_hostVariable) {
|
||||
$name = substr($part, 1);
|
||||
$this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
|
||||
$this->_variables[$pos] = $name;
|
||||
} else {
|
||||
$this->_parts[$pos] = $part;
|
||||
$this->_staticCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path with parts defined by a map. Assigns and
|
||||
* returns an array of variables on a successful match.
|
||||
*
|
||||
* @param Zend_Controller_Request_Http $request Request to get the host from
|
||||
* @return array|false An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($request)
|
||||
{
|
||||
// Check the scheme if required
|
||||
if ($this->_scheme !== null) {
|
||||
$scheme = $request->getScheme();
|
||||
|
||||
if ($scheme !== $this->_scheme) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the host and remove unnecessary port information
|
||||
$host = $request->getHttpHost();
|
||||
if (preg_match('#:\d+$#', $host, $result) === 1) {
|
||||
$host = substr($host, 0, -strlen($result[0]));
|
||||
}
|
||||
|
||||
$hostStaticCount = 0;
|
||||
$values = array();
|
||||
|
||||
$host = trim($host, '.');
|
||||
|
||||
if ($host != '') {
|
||||
$host = explode('.', $host);
|
||||
|
||||
foreach ($host as $pos => $hostPart) {
|
||||
// Host is longer than a route, it's not a match
|
||||
if (!array_key_exists($pos, $this->_parts)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
|
||||
$hostPart = urldecode($hostPart);
|
||||
|
||||
// If it's a static part, match directly
|
||||
if ($name === null && $this->_parts[$pos] != $hostPart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's a variable with requirement, match a regex. If not - everything matches
|
||||
if ($this->_parts[$pos] !== null && !preg_match($this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', $hostPart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's a variable store it's value for later
|
||||
if ($name !== null) {
|
||||
$values[$name] = $hostPart;
|
||||
} else {
|
||||
$hostStaticCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all static mappings have been matched
|
||||
if ($this->_staticCount != $hostStaticCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$return = $values + $this->_defaults;
|
||||
|
||||
// Check if all map variables have been initialized
|
||||
foreach ($this->_variables as $var) {
|
||||
if (!array_key_exists($var, $return)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_values = $values;
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles user submitted parameters forming a hostname defined by this route
|
||||
*
|
||||
* @param array $data An array of variable and value pairs used as parameters
|
||||
* @param boolean $reset Whether or not to set route defaults with those provided in $data
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
|
||||
{
|
||||
$host = array();
|
||||
$flag = false;
|
||||
|
||||
foreach ($this->_parts as $key => $part) {
|
||||
$name = isset($this->_variables[$key]) ? $this->_variables[$key] : null;
|
||||
|
||||
$useDefault = false;
|
||||
if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) {
|
||||
$useDefault = true;
|
||||
}
|
||||
|
||||
if (isset($name)) {
|
||||
if (isset($data[$name]) && !$useDefault) {
|
||||
$host[$key] = $data[$name];
|
||||
unset($data[$name]);
|
||||
} elseif (!$reset && !$useDefault && isset($this->_values[$name])) {
|
||||
$host[$key] = $this->_values[$name];
|
||||
} elseif (isset($this->_defaults[$name])) {
|
||||
$host[$key] = $this->_defaults[$name];
|
||||
} else {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception($name . ' is not specified');
|
||||
}
|
||||
} else {
|
||||
$host[$key] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
$return = '';
|
||||
|
||||
foreach (array_reverse($host, true) as $key => $value) {
|
||||
if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key]) || $partial) {
|
||||
if ($encode) $value = urlencode($value);
|
||||
$return = '.' . $value . $return;
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
$url = trim($return, '.');
|
||||
|
||||
if ($this->_scheme !== null) {
|
||||
$scheme = $this->_scheme;
|
||||
} else {
|
||||
$request = $this->getRequest();
|
||||
if ($request instanceof Zend_Controller_Request_Http) {
|
||||
$scheme = $request->getScheme();
|
||||
} else {
|
||||
$scheme = 'http';
|
||||
}
|
||||
}
|
||||
|
||||
$hostname = implode('.', $host);
|
||||
$url = $scheme . '://' . $url;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single parameter of route's defaults
|
||||
*
|
||||
* @param string $name Array key of the parameter
|
||||
* @return string Previously set default
|
||||
*/
|
||||
public function getDefault($name) {
|
||||
if (isset($this->_defaults[$name])) {
|
||||
return $this->_defaults[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of defaults
|
||||
*
|
||||
* @return array Route defaults
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all variables which are used by the route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables()
|
||||
{
|
||||
return $this->_variables;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Config */
|
||||
require_once 'Zend/Config.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Controller_Router_Route_Interface {
|
||||
public function match($path);
|
||||
public function assemble($data = array(), $reset = false, $encode = false);
|
||||
public static function getInstance(Zend_Config $config);
|
||||
}
|
||||
|
289
airtime_mvc/library/Zend/Controller/Router/Route/Module.php
Normal file
289
airtime_mvc/library/Zend/Controller/Router/Route/Module.php
Normal file
|
@ -0,0 +1,289 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Module.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* Module Route
|
||||
*
|
||||
* Default route for module functionality
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://manuals.rubyonrails.com/read/chapter/65
|
||||
*/
|
||||
class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
/**
|
||||
* URI delimiter
|
||||
*/
|
||||
const URI_DELIMITER = '/';
|
||||
|
||||
/**
|
||||
* Default values for the route (ie. module, controller, action, params)
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaults;
|
||||
|
||||
protected $_values = array();
|
||||
protected $_moduleValid = false;
|
||||
protected $_keysSet = false;
|
||||
|
||||
/**#@+
|
||||
* Array keys to use for module, controller, and action. Should be taken out of request.
|
||||
* @var string
|
||||
*/
|
||||
protected $_moduleKey = 'module';
|
||||
protected $_controllerKey = 'controller';
|
||||
protected $_actionKey = 'action';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
protected $_dispatcher;
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
public function getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$frontController = Zend_Controller_Front::getInstance();
|
||||
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
$dispatcher = $frontController->getDispatcher();
|
||||
$request = $frontController->getRequest();
|
||||
|
||||
return new self($defs, $dispatcher, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $defaults Defaults for map variables with keys as variable names
|
||||
* @param Zend_Controller_Dispatcher_Interface $dispatcher Dispatcher object
|
||||
* @param Zend_Controller_Request_Abstract $request Request object
|
||||
*/
|
||||
public function __construct(array $defaults = array(),
|
||||
Zend_Controller_Dispatcher_Interface $dispatcher = null,
|
||||
Zend_Controller_Request_Abstract $request = null)
|
||||
{
|
||||
$this->_defaults = $defaults;
|
||||
|
||||
if (isset($request)) {
|
||||
$this->_request = $request;
|
||||
}
|
||||
|
||||
if (isset($dispatcher)) {
|
||||
$this->_dispatcher = $dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request keys based on values in request object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setRequestKeys()
|
||||
{
|
||||
if (null !== $this->_request) {
|
||||
$this->_moduleKey = $this->_request->getModuleKey();
|
||||
$this->_controllerKey = $this->_request->getControllerKey();
|
||||
$this->_actionKey = $this->_request->getActionKey();
|
||||
}
|
||||
|
||||
if (null !== $this->_dispatcher) {
|
||||
$this->_defaults += array(
|
||||
$this->_controllerKey => $this->_dispatcher->getDefaultControllerName(),
|
||||
$this->_actionKey => $this->_dispatcher->getDefaultAction(),
|
||||
$this->_moduleKey => $this->_dispatcher->getDefaultModule()
|
||||
);
|
||||
}
|
||||
|
||||
$this->_keysSet = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path. Assigns and returns an array of variables
|
||||
* on a successful match.
|
||||
*
|
||||
* If a request object is registered, it uses its setModuleName(),
|
||||
* setControllerName(), and setActionName() accessors to set those values.
|
||||
* Always returns the values as an array.
|
||||
*
|
||||
* @param string $path Path used to match against this routing map
|
||||
* @return array An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($path, $partial = false)
|
||||
{
|
||||
$this->_setRequestKeys();
|
||||
|
||||
$values = array();
|
||||
$params = array();
|
||||
|
||||
if (!$partial) {
|
||||
$path = trim($path, self::URI_DELIMITER);
|
||||
} else {
|
||||
$matchedPath = $path;
|
||||
}
|
||||
|
||||
if ($path != '') {
|
||||
$path = explode(self::URI_DELIMITER, $path);
|
||||
|
||||
if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
|
||||
$values[$this->_moduleKey] = array_shift($path);
|
||||
$this->_moduleValid = true;
|
||||
}
|
||||
|
||||
if (count($path) && !empty($path[0])) {
|
||||
$values[$this->_controllerKey] = array_shift($path);
|
||||
}
|
||||
|
||||
if (count($path) && !empty($path[0])) {
|
||||
$values[$this->_actionKey] = array_shift($path);
|
||||
}
|
||||
|
||||
if ($numSegs = count($path)) {
|
||||
for ($i = 0; $i < $numSegs; $i = $i + 2) {
|
||||
$key = urldecode($path[$i]);
|
||||
$val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
|
||||
$params[$key] = (isset($params[$key]) ? (array_merge((array) $params[$key], array($val))): $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($partial) {
|
||||
$this->setMatchedPath($matchedPath);
|
||||
}
|
||||
|
||||
$this->_values = $values + $params;
|
||||
|
||||
return $this->_values + $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles user submitted parameters forming a URL path defined by this route
|
||||
*
|
||||
* @param array $data An array of variable and value pairs used as parameters
|
||||
* @param bool $reset Weither to reset the current params
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = true, $partial = false)
|
||||
{
|
||||
if (!$this->_keysSet) {
|
||||
$this->_setRequestKeys();
|
||||
}
|
||||
|
||||
$params = (!$reset) ? $this->_values : array();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value !== null) {
|
||||
$params[$key] = $value;
|
||||
} elseif (isset($params[$key])) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$params += $this->_defaults;
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) {
|
||||
if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) {
|
||||
$module = $params[$this->_moduleKey];
|
||||
}
|
||||
}
|
||||
unset($params[$this->_moduleKey]);
|
||||
|
||||
$controller = $params[$this->_controllerKey];
|
||||
unset($params[$this->_controllerKey]);
|
||||
|
||||
$action = $params[$this->_actionKey];
|
||||
unset($params[$this->_actionKey]);
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
$key = ($encode) ? urlencode($key) : $key;
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $arrayValue) {
|
||||
$arrayValue = ($encode) ? urlencode($arrayValue) : $arrayValue;
|
||||
$url .= '/' . $key;
|
||||
$url .= '/' . $arrayValue;
|
||||
}
|
||||
} else {
|
||||
if ($encode) $value = urlencode($value);
|
||||
$url .= '/' . $key;
|
||||
$url .= '/' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) {
|
||||
if ($encode) $action = urlencode($action);
|
||||
$url = '/' . $action . $url;
|
||||
}
|
||||
|
||||
if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
|
||||
if ($encode) $controller = urlencode($controller);
|
||||
$url = '/' . $controller . $url;
|
||||
}
|
||||
|
||||
if (isset($module)) {
|
||||
if ($encode) $module = urlencode($module);
|
||||
$url = '/' . $module . $url;
|
||||
}
|
||||
|
||||
return ltrim($url, self::URI_DELIMITER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single parameter of route's defaults
|
||||
*
|
||||
* @param string $name Array key of the parameter
|
||||
* @return string Previously set default
|
||||
*/
|
||||
public function getDefault($name) {
|
||||
if (isset($this->_defaults[$name])) {
|
||||
return $this->_defaults[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of defaults
|
||||
*
|
||||
* @return array Route defaults
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
}
|
269
airtime_mvc/library/Zend/Controller/Router/Route/Regex.php
Normal file
269
airtime_mvc/library/Zend/Controller/Router/Route/Regex.php
Normal file
|
@ -0,0 +1,269 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Regex.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* Regex Route
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
protected $_regex = null;
|
||||
protected $_defaults = array();
|
||||
protected $_reverse = null;
|
||||
protected $_map = array();
|
||||
protected $_values = array();
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
$map = ($config->map instanceof Zend_Config) ? $config->map->toArray() : array();
|
||||
$reverse = (isset($config->reverse)) ? $config->reverse : null;
|
||||
return new self($config->route, $defs, $map, $reverse);
|
||||
}
|
||||
|
||||
public function __construct($route, $defaults = array(), $map = array(), $reverse = null)
|
||||
{
|
||||
$this->_regex = $route;
|
||||
$this->_defaults = (array) $defaults;
|
||||
$this->_map = (array) $map;
|
||||
$this->_reverse = $reverse;
|
||||
}
|
||||
|
||||
public function getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path with a previously defined route.
|
||||
* Assigns and returns an array of defaults on a successful match.
|
||||
*
|
||||
* @param string $path Path used to match against this routing map
|
||||
* @return array|false An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($path, $partial = false)
|
||||
{
|
||||
if (!$partial) {
|
||||
$path = trim(urldecode($path), '/');
|
||||
$regex = '#^' . $this->_regex . '$#i';
|
||||
} else {
|
||||
$regex = '#^' . $this->_regex . '#i';
|
||||
}
|
||||
|
||||
$res = preg_match($regex, $path, $values);
|
||||
|
||||
if ($res === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($partial) {
|
||||
$this->setMatchedPath($values[0]);
|
||||
}
|
||||
|
||||
// array_filter_key()? Why isn't this in a standard PHP function set yet? :)
|
||||
foreach ($values as $i => $value) {
|
||||
if (!is_int($i) || $i === 0) {
|
||||
unset($values[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_values = $values;
|
||||
|
||||
$values = $this->_getMappedValues($values);
|
||||
$defaults = $this->_getMappedValues($this->_defaults, false, true);
|
||||
$return = $values + $defaults;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps numerically indexed array values to it's associative mapped counterpart.
|
||||
* Or vice versa. Uses user provided map array which consists of index => name
|
||||
* parameter mapping. If map is not found, it returns original array.
|
||||
*
|
||||
* Method strips destination type of keys form source array. Ie. if source array is
|
||||
* indexed numerically then every associative key will be stripped. Vice versa if reversed
|
||||
* is set to true.
|
||||
*
|
||||
* @param array $values Indexed or associative array of values to map
|
||||
* @param boolean $reversed False means translation of index to association. True means reverse.
|
||||
* @param boolean $preserve Should wrong type of keys be preserved or stripped.
|
||||
* @return array An array of mapped values
|
||||
*/
|
||||
protected function _getMappedValues($values, $reversed = false, $preserve = false)
|
||||
{
|
||||
if (count($this->_map) == 0) {
|
||||
return $values;
|
||||
}
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
if (is_int($key) && !$reversed) {
|
||||
if (array_key_exists($key, $this->_map)) {
|
||||
$index = $this->_map[$key];
|
||||
} elseif (false === ($index = array_search($key, $this->_map))) {
|
||||
$index = $key;
|
||||
}
|
||||
$return[$index] = $values[$key];
|
||||
} elseif ($reversed) {
|
||||
$index = $key;
|
||||
if (!is_int($key)) {
|
||||
if (array_key_exists($key, $this->_map)) {
|
||||
$index = $this->_map[$key];
|
||||
} else {
|
||||
$index = array_search($key, $this->_map, true);
|
||||
}
|
||||
}
|
||||
if (false !== $index) {
|
||||
$return[$index] = $values[$key];
|
||||
}
|
||||
} elseif ($preserve) {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a URL path defined by this route
|
||||
*
|
||||
* @param array $data An array of name (or index) and value pairs used as parameters
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
|
||||
{
|
||||
if ($this->_reverse === null) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception('Cannot assemble. Reversed route is not specified.');
|
||||
}
|
||||
|
||||
$defaultValuesMapped = $this->_getMappedValues($this->_defaults, true, false);
|
||||
$matchedValuesMapped = $this->_getMappedValues($this->_values, true, false);
|
||||
$dataValuesMapped = $this->_getMappedValues($data, true, false);
|
||||
|
||||
// handle resets, if so requested (By null value) to do so
|
||||
if (($resetKeys = array_search(null, $dataValuesMapped, true)) !== false) {
|
||||
foreach ((array) $resetKeys as $resetKey) {
|
||||
if (isset($matchedValuesMapped[$resetKey])) {
|
||||
unset($matchedValuesMapped[$resetKey]);
|
||||
unset($dataValuesMapped[$resetKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// merge all the data together, first defaults, then values matched, then supplied
|
||||
$mergedData = $defaultValuesMapped;
|
||||
$mergedData = $this->_arrayMergeNumericKeys($mergedData, $matchedValuesMapped);
|
||||
$mergedData = $this->_arrayMergeNumericKeys($mergedData, $dataValuesMapped);
|
||||
|
||||
if ($encode) {
|
||||
foreach ($mergedData as $key => &$value) {
|
||||
$value = urlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
ksort($mergedData);
|
||||
|
||||
$return = @vsprintf($this->_reverse, $mergedData);
|
||||
|
||||
if ($return === false) {
|
||||
require_once 'Zend/Controller/Router/Exception.php';
|
||||
throw new Zend_Controller_Router_Exception('Cannot assemble. Too few arguments?');
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single parameter of route's defaults
|
||||
*
|
||||
* @param string $name Array key of the parameter
|
||||
* @return string Previously set default
|
||||
*/
|
||||
public function getDefault($name) {
|
||||
if (isset($this->_defaults[$name])) {
|
||||
return $this->_defaults[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of defaults
|
||||
*
|
||||
* @return array Route defaults
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all variables which are used by the route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables()
|
||||
{
|
||||
$variables = array();
|
||||
|
||||
foreach ($this->_map as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$variables[] = $value;
|
||||
} else {
|
||||
$variables[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* _arrayMergeNumericKeys() - allows for a strict key (numeric's included) array_merge.
|
||||
* php's array_merge() lacks the ability to merge with numeric keys.
|
||||
*
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
* @return array
|
||||
*/
|
||||
protected function _arrayMergeNumericKeys(Array $array1, Array $array2)
|
||||
{
|
||||
$returnArray = $array1;
|
||||
foreach ($array2 as $array2Index => $array2Value) {
|
||||
$returnArray[$array2Index] = $array2Value;
|
||||
}
|
||||
return $returnArray;
|
||||
}
|
||||
|
||||
|
||||
}
|
125
airtime_mvc/library/Zend/Controller/Router/Route/Static.php
Normal file
125
airtime_mvc/library/Zend/Controller/Router/Route/Static.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Static.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Controller_Router_Route_Abstract */
|
||||
require_once 'Zend/Controller/Router/Route/Abstract.php';
|
||||
|
||||
/**
|
||||
* StaticRoute is used for managing static URIs.
|
||||
*
|
||||
* It's a lot faster compared to the standard Route implementation.
|
||||
*
|
||||
* @package Zend_Controller
|
||||
* @subpackage Router
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract
|
||||
{
|
||||
|
||||
protected $_route = null;
|
||||
protected $_defaults = array();
|
||||
|
||||
public function getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates route based on passed Zend_Config structure
|
||||
*
|
||||
* @param Zend_Config $config Configuration object
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config)
|
||||
{
|
||||
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
|
||||
return new self($config->route, $defs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the route for mapping.
|
||||
*
|
||||
* @param string $route Map used to match with later submitted URL path
|
||||
* @param array $defaults Defaults for map variables with keys as variable names
|
||||
*/
|
||||
public function __construct($route, $defaults = array())
|
||||
{
|
||||
$this->_route = trim($route, '/');
|
||||
$this->_defaults = (array) $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a user submitted path with a previously defined route.
|
||||
* Assigns and returns an array of defaults on a successful match.
|
||||
*
|
||||
* @param string $path Path used to match against this routing map
|
||||
* @return array|false An array of assigned values or a false on a mismatch
|
||||
*/
|
||||
public function match($path, $partial = false)
|
||||
{
|
||||
if ($partial) {
|
||||
if (substr($path, 0, strlen($this->_route)) === $this->_route) {
|
||||
$this->setMatchedPath($this->_route);
|
||||
return $this->_defaults;
|
||||
}
|
||||
} else {
|
||||
if (trim($path, '/') == $this->_route) {
|
||||
return $this->_defaults;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a URL path defined by this route
|
||||
*
|
||||
* @param array $data An array of variable and value pairs used as parameters
|
||||
* @return string Route path with user submitted parameters
|
||||
*/
|
||||
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
|
||||
{
|
||||
return $this->_route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single parameter of route's defaults
|
||||
*
|
||||
* @param string $name Array key of the parameter
|
||||
* @return string Previously set default
|
||||
*/
|
||||
public function getDefault($name) {
|
||||
if (isset($this->_defaults[$name])) {
|
||||
return $this->_defaults[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of defaults
|
||||
*
|
||||
* @return array Route defaults
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue