import v2.0.0.0_RC3 | 2012-07-01

https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
2019-07-17 22:31:04 +02:00
parent 38c146901c
commit 2f397f01f7
2677 changed files with 296182 additions and 45159 deletions

View File

@ -17,7 +17,7 @@
* @subpackage Client
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Client.php 16541 2009-07-07 06:59:03Z bkarwin $
* @version $Id: Client.php 18173 2009-09-17 15:35:05Z padraic $
*/
@ -126,6 +126,7 @@ class Zend_Rest_Client extends Zend_Service_Abstract
*
* @param string $path
* @param array $query Array of GET parameters
* @throws Zend_Http_Client_Exception
* @return Zend_Http_Response
*/
final public function restGet($path, array $query = null)
@ -163,6 +164,7 @@ class Zend_Rest_Client extends Zend_Service_Abstract
*
* @param string $path
* @param mixed $data Raw data to send
* @throws Zend_Http_Client_Exception
* @return Zend_Http_Response
*/
final public function restPost($path, $data = null)
@ -176,6 +178,7 @@ class Zend_Rest_Client extends Zend_Service_Abstract
*
* @param string $path
* @param mixed $data Raw data to send in request
* @throws Zend_Http_Client_Exception
* @return Zend_Http_Response
*/
final public function restPut($path, $data = null)
@ -188,6 +191,7 @@ class Zend_Rest_Client extends Zend_Service_Abstract
* Performs an HTTP DELETE request to $path.
*
* @param string $path
* @throws Zend_Http_Client_Exception
* @return Zend_Http_Response
*/
final public function restDelete($path)

View File

@ -15,7 +15,7 @@
* @package Zend_Rest
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Controller.php 16595 2009-07-09 20:26:25Z matthew $
* @version $Id: Controller.php 18951 2009-11-12 16:26:19Z alexander $
*/
/** Zend_Controller_Action */
@ -24,45 +24,45 @@ require_once 'Zend/Controller/Action.php';
/**
* An abstract class to guide implementation of action controllers for use with
* Zend_Rest_Route.
*
*
* @package Zend_Rest
* @see Zend_Rest_Route
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Rest_Controller extends Zend_Controller_Action
{
/**
* The index action handles index/list requests; it should respond with a
* list of the requested resources.
*/
*/
abstract public function indexAction();
/**
* The get action handles GET requests and receives an 'id' parameter; it
* The get action handles GET requests and receives an 'id' parameter; it
* should respond with the server resource state of the resource identified
* by the 'id' value.
*/
*/
abstract public function getAction();
/**
* The post action handles POST requests; it should accept and digest a
* POSTed resource representation and persist the resource state.
*/
*/
abstract public function postAction();
/**
* The put action handles PUT requests and receives an 'id' parameter; it
* should update the server resource state of the resource identified by
* The put action handles PUT requests and receives an 'id' parameter; it
* should update the server resource state of the resource identified by
* the 'id' value.
*/
*/
abstract public function putAction();
/**
* The delete action handles DELETE requests and receives an 'id'
* The delete action handles DELETE requests and receives an 'id'
* parameter; it should update the server resource state of the resource
* identified by the 'id' value.
*/
*/
abstract public function deleteAction();
}

View File

@ -15,25 +15,25 @@
* @package Zend_Rest
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Route.php 16891 2009-07-20 19:37:29Z doctorrock83 $
* @version $Id: Route.php 19078 2009-11-20 00:36:49Z matthew $
*/
/**
* @see Zend_Controller_Router_Route_Interface
/**
* @see Zend_Controller_Router_Route_Interface
*/
require_once 'Zend/Controller/Router/Route/Interface.php';
/**
/**
* @see Zend_Controller_Router_Route_Module
*/
require_once 'Zend/Controller/Router/Route/Module.php';
/**
/**
* @see Zend_Controller_Dispatcher_Interface
*/
require_once 'Zend/Controller/Dispatcher/Interface.php';
/**
/**
* @see Zend_Controller_Request_Abstract
*/
require_once 'Zend/Controller/Request/Abstract.php';
@ -52,37 +52,41 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
/**
* Specific Modules to receive RESTful routes
* @var array
*/
protected $_restfulModules = null;
*/
protected $_restfulModules = null;
/**
* Specific Modules=>Controllers to receive RESTful routes
* @var array
*/
protected $_restfulControllers = null;
*/
protected $_restfulControllers = null;
/**
* @var Zend_Controller_Front
*/
protected $_front;
/**
* Constructor
*
* @param Zend_Controller_Front $front Front Controller object
* @param array $defaults Defaults for map variables with keys as variable names
* @param array $responders Modules or controllers to receive RESTful routes
*/
public function __construct(Zend_Controller_Front $front,
array $defaults = array(),
array $responders = array())
{
$this->_defaults = $defaults;
if($responders)
$this->_parseResponders($responders);
if (isset($front)) {
$this->_request = $front->getRequest();
$this->_dispatcher = $front->getDispatcher();
}
}
*/
public function __construct(Zend_Controller_Front $front,
array $defaults = array(),
array $responders = array()
) {
$this->_defaults = $defaults;
if ($responders) {
$this->_parseResponders($responders);
}
$this->_front = $front;
$this->_dispatcher = $front->getDispatcher();
}
/**
* Matches a user submitted request. Assigns and returns an array of variables
* on a successful match.
@ -93,83 +97,87 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
*
* @param Zend_Controller_Request_Http $request Request used to match against this routing ruleset
* @return array An array of assigned values or a false on a mismatch
*/
public function match($request)
{
$this->_setRequestKeys();
$path = $request->getPathInfo();
$values = array();
$params = array();
$path = trim($path, self::URI_DELIMITER);
if ($path != '') {
$path = explode(self::URI_DELIMITER, $path);
// Determine Module
$moduleName = $this->_defaults[$this->_moduleKey];
if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
$moduleName = $path[0];
if ($this->_checkRestfulModule($moduleName)) {
$values[$this->_moduleKey] = array_shift($path);
$this->_moduleValid = true;
}
}
// Determine Controller
$controllerName = $this->_defaults[$this->_controllerKey];
if (count($path) && !empty($path[0])) {
if ($this->_checkRestfulController($moduleName, $path[0])) {
$controllerName = $path[0];
$values[$this->_controllerKey] = array_shift($path);
$values[$this->_actionKey] = 'get';
} else {
// If Controller in URI is not found to be a RESTful
// Controller, return false to fall back to other routes
return false;
}
}
*/
public function match($request, $partial = false)
{
if (!$request instanceof Zend_Controller_Request_Http) {
$request = $this->_front->getRequest();
}
$this->_request = $request;
$this->_setRequestKeys();
$path = $request->getPathInfo();
$values = array();
$params = array();
$path = trim($path, self::URI_DELIMITER);
if ($path != '') {
$path = explode(self::URI_DELIMITER, $path);
// Determine Module
$moduleName = $this->_defaults[$this->_moduleKey];
$dispatcher = $this->_front->getDispatcher();
if ($dispatcher && $dispatcher->isValidModule($path[0])) {
$moduleName = $path[0];
if ($this->_checkRestfulModule($moduleName)) {
$values[$this->_moduleKey] = array_shift($path);
$this->_moduleValid = true;
}
}
// Determine Controller
$controllerName = $this->_defaults[$this->_controllerKey];
if (count($path) && !empty($path[0])) {
if ($this->_checkRestfulController($moduleName, $path[0])) {
$controllerName = $path[0];
$values[$this->_controllerKey] = array_shift($path);
$values[$this->_actionKey] = 'get';
} else {
// If Controller in URI is not found to be a RESTful
// Controller, return false to fall back to other routes
return false;
}
}
//Store path count for method mapping
$pathElementCount = count($path);
// Check for leading "special get" URI's
// Check for leading "special get" URI's
$specialGetTarget = false;
if ($pathElementCount && array_search($path[0], array('index', 'new')) > -1) {
if ($pathElementCount && array_search($path[0], array('index', 'new')) > -1) {
$specialGetTarget = array_shift($path);
} elseif ($pathElementCount && $path[$pathElementCount-1] == 'edit') {
$specialGetTarget = 'edit';
$params['id'] = $path[$pathElementCount-2];
} elseif ($pathElementCount == 1) {
$params['id'] = array_shift($path);
$params['id'] = array_shift($path);
} elseif ($pathElementCount == 0 || $pathElementCount > 1) {
$specialGetTarget = 'list';
$specialGetTarget = 'index';
}
// Digest URI params
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] = $val;
}
}
// Check for trailing "special get" URI
if (array_key_exists('edit', $params))
$specialGetTarget = 'edit';
// Determine Action
$requestMethod = strtolower($request->getMethod());
if ($requestMethod != 'get') {
if ($request->getParam('_method')) {
$values[$this->_actionKey] = strtolower($request->getParam('_method'));
} elseif ( $this->_request->getHeader('X-HTTP-Method-Override') ) {
$values[$this->_actionKey] = strtolower($this->_request->getHeader('X-HTTP-Method-Override'));
} else {
$values[$this->_actionKey] = $requestMethod;
// Digest URI params
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] = $val;
}
}
// Determine Action
$requestMethod = strtolower($request->getMethod());
if ($requestMethod != 'get') {
if ($request->getParam('_method')) {
$values[$this->_actionKey] = strtolower($request->getParam('_method'));
} elseif ( $request->getHeader('X-HTTP-Method-Override') ) {
$values[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
} else {
$values[$this->_actionKey] = $requestMethod;
}
//Map PUT and POST to actual create/update actions
//based on parameter count (posting to resource or collection)
// Map PUT and POST to actual create/update actions
// based on parameter count (posting to resource or collection)
switch( $values[$this->_actionKey] ){
case 'post':
if ($pathElementCount > 0) {
@ -182,17 +190,22 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
$values[$this->_actionKey] = 'put';
break;
}
} elseif ($specialGetTarget) {
$values[$this->_actionKey] = $specialGetTarget;
}
}
} elseif ($specialGetTarget) {
$values[$this->_actionKey] = $specialGetTarget;
}
}
$this->_values = $values + $params;
return $this->_values + $this->_defaults;
}
$result = $this->_values + $this->_defaults;
if ($partial && $result)
$this->setMatchedPath($request->getPathInfo());
return $result;
}
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
@ -200,71 +213,72 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
* @param bool $reset Weither to reset the current params
* @param bool $encode Weither to return urlencoded string
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = true)
{
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];
*/
public function assemble($data = array(), $reset = false, $encode = true)
{
if (!$this->_keysSet) {
if (null === $this->_request) {
$this->_request = $this->_front->getRequest();
}
$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]);
unset($params[$this->_actionKey]);
if (isset($params['index']) && $params['index']) {
unset($params['index']);
$url .= '/index';
foreach ($params as $key => $value) {
$url .= '/' . $key;
$url .= '/' . $value;
foreach ($params as $key => $value) {
$url .= '/' . $key . '/' . $value;
}
} else {
if (isset($params['id']))
$url .= '/' . $params['id'];
} elseif (isset($params['id'])) {
$url .= '/' . $params['id'];
}
if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
$url = '/' . $controller . $url;
}
if (isset($module)) {
$url = '/' . $module . $url;
}
return ltrim($url, self::URI_DELIMITER);
}
if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
$url = '/' . $controller . $url;
}
if (isset($module)) {
$url = '/' . $module . $url;
}
return ltrim($url, self::URI_DELIMITER);
}
/**
* Tells Rewrite Router which version this Route is
*
* @return int Route "version"
*/
public function getVersion()
{
return 2;
}
*/
public function getVersion()
{
return 2;
}
/**
* Parses the responders array sent to constructor to know
@ -272,19 +286,21 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
*
* @param array $responders
*/
private function _parseResponders($responders)
{
$modulesOnly = true;
foreach ($responders as $responder) {
if(is_array($responder))
$modulesOnly = false;
}
if ($modulesOnly) {
$this->_restfulModules = $responders;
} else {
$this->_restfulControllers = $responders;
}
}
private function _parseResponders($responders)
{
$modulesOnly = true;
foreach ($responders as $responder) {
if(is_array($responder)) {
$modulesOnly = false;
break;
}
}
if ($modulesOnly) {
$this->_restfulModules = $responders;
} else {
$this->_restfulControllers = $responders;
}
}
/**
* Determine if a specified module supports RESTful routing
@ -292,16 +308,19 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
* @param string $moduleName
* @return bool
*/
private function _checkRestfulModule($moduleName)
{
if ($this->_allRestful())
return true;
if ($this->_fullRestfulModule($moduleName))
return true;
if ($this->_restfulControllers && array_key_exists($moduleName, $this->_restfulControllers))
return true;
return false;
}
private function _checkRestfulModule($moduleName)
{
if ($this->_allRestful()) {
return true;
}
if ($this->_fullRestfulModule($moduleName)) {
return true;
}
if ($this->_restfulControllers && array_key_exists($moduleName, $this->_restfulControllers)) {
return true;
}
return false;
}
/**
* Determine if a specified module + controller combination supports
@ -311,28 +330,32 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
* @param string $controllerName
* @return bool
*/
private function _checkRestfulController($moduleName, $controllerName)
{
if ($this->_allRestful())
return true;
if ($this->_fullRestfulModule($moduleName))
return true;
if ($this->_checkRestfulModule($moduleName)
&& $this->_restfulControllers
&& array_search($controllerName, $this->_restfulControllers[$moduleName]) !== false)
return true;
return false;
}
private function _checkRestfulController($moduleName, $controllerName)
{
if ($this->_allRestful()) {
return true;
}
if ($this->_fullRestfulModule($moduleName)) {
return true;
}
if ($this->_checkRestfulModule($moduleName)
&& $this->_restfulControllers
&& (false !== array_search($controllerName, $this->_restfulControllers[$moduleName]))
) {
return true;
}
return false;
}
/**
* Determines if RESTful routing applies to the entire app
*
* @return bool
*/
private function _allRestful()
{
return (!$this->_restfulModules && !$this->_restfulControllers);
}
private function _allRestful()
{
return (!$this->_restfulModules && !$this->_restfulControllers);
}
/**
* Determines if RESTful routing applies to an entire module
@ -340,9 +363,11 @@ class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
* @param string $moduleName
* @return bool
*/
private function _fullRestfulModule($moduleName)
{
return ($this->_restfulModules && array_search($moduleName, $this->_restfulModules) !== false);
}
}
private function _fullRestfulModule($moduleName)
{
return (
$this->_restfulModules
&& (false !==array_search($moduleName, $this->_restfulModules))
);
}
}

View File

@ -17,21 +17,21 @@
* @subpackage Server
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Server.php 16541 2009-07-07 06:59:03Z bkarwin $
* @version $Id: Server.php 18545 2009-10-15 11:06:03Z yoshida@zend.co.jp $
*/
/**
* Zend_Server_Interface
* @see Zend_Server_Interface
*/
require_once 'Zend/Server/Interface.php';
/**
* Zend_Server_Reflection
* @see Zend_Server_Reflection
*/
require_once 'Zend/Server/Reflection.php';
/**
* Zend_Server_Abstract
* @see Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
@ -592,9 +592,11 @@ class Zend_Rest_Server implements Zend_Server_Interface
$object = $this->_functions[$this->_method]->getDeclaringClass()->newInstance();
}
} catch (Exception $e) {
echo $e->getMessage();
require_once 'Zend/Rest/Server/Exception.php';
throw new Zend_Rest_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $this->_functions[$this->_method]->getName(), 500);
throw new Zend_Rest_Server_Exception('Error instantiating class ' . $class .
' to invoke method ' . $this->_functions[$this->_method]->getName() .
' (' . $e->getMessage() . ') ',
500);
}
try {