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
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