web/lib/Zend/Rest/Route.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Rest
    16  * @package    Zend_Rest
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Route.php 23421 2010-11-21 10:03:53Z wilmoore $
    19  * @version    $Id: Route.php 24593 2012-01-05 20:35:02Z matthew $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Controller_Router_Route_Interface
    23  * @see Zend_Controller_Router_Route_Interface
    24  */
    24  */
    44  *
    44  *
    45  * Request-aware route for RESTful modular routing
    45  * Request-aware route for RESTful modular routing
    46  *
    46  *
    47  * @category   Zend
    47  * @category   Zend
    48  * @package    Zend_Rest
    48  * @package    Zend_Rest
    49  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    49  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    50  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    50  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    51  */
    51  */
    52 class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
    52 class Zend_Rest_Route extends Zend_Controller_Router_Route_Module
    53 {
    53 {
    54     /**
    54     /**
    96     {
    96     {
    97         $frontController = Zend_Controller_Front::getInstance();
    97         $frontController = Zend_Controller_Front::getInstance();
    98         $defaultsArray = array();
    98         $defaultsArray = array();
    99         $restfulConfigArray = array();
    99         $restfulConfigArray = array();
   100         foreach ($config as $key => $values) {
   100         foreach ($config as $key => $values) {
   101         	if ($key == 'type') {
   101             if ($key == 'type') {
   102         		// do nothing
   102                 // do nothing
   103         	} elseif ($key == 'defaults') {
   103             } elseif ($key == 'defaults') {
   104         		$defaultsArray = $values->toArray();
   104                 $defaultsArray = $values->toArray();
   105         	} else {
   105             } else {
   106         		$restfulConfigArray[$key] = explode(',', $values);
   106                 $restfulConfigArray[$key] = explode(',', $values);
   107         	}
   107             }
   108         }
   108         }
   109         $instance = new self($frontController, $defaultsArray, $restfulConfigArray);
   109         $instance = new self($frontController, $defaultsArray, $restfulConfigArray);
   110         return $instance;
   110         return $instance;
   111     }
   111     }
   112 
   112 
   159                     // If Controller in URI is not found to be a RESTful
   159                     // If Controller in URI is not found to be a RESTful
   160                     // Controller, return false to fall back to other routes
   160                     // Controller, return false to fall back to other routes
   161                     return false;
   161                     return false;
   162                 }
   162                 }
   163             } elseif ($this->_checkRestfulController($moduleName, $controllerName)) {
   163             } elseif ($this->_checkRestfulController($moduleName, $controllerName)) {
   164             	$values[$this->_controllerKey] = $controllerName;
   164                 $values[$this->_controllerKey] = $controllerName;
   165             	$values[$this->_actionKey] = 'get';
   165                 $values[$this->_actionKey] = 'get';
   166             } else {
   166             } else {
   167             	return false;
   167                 return false;
   168             }
   168             }
   169 
   169 
   170             //Store path count for method mapping
   170             //Store path count for method mapping
   171             $pathElementCount = count($path);
   171             $pathElementCount = count($path);
   172 
   172 
   174             $specialGetTarget = false;
   174             $specialGetTarget = false;
   175             if ($pathElementCount && array_search($path[0], array('index', 'new')) > -1) {
   175             if ($pathElementCount && array_search($path[0], array('index', 'new')) > -1) {
   176                 $specialGetTarget = array_shift($path);
   176                 $specialGetTarget = array_shift($path);
   177             } elseif ($pathElementCount && $path[$pathElementCount-1] == 'edit') {
   177             } elseif ($pathElementCount && $path[$pathElementCount-1] == 'edit') {
   178                 $specialGetTarget = 'edit';
   178                 $specialGetTarget = 'edit';
   179                 $params['id'] = $path[$pathElementCount-2];
   179                 $params['id'] = urldecode($path[$pathElementCount-2]);
   180             } elseif ($pathElementCount == 1) {
   180             } elseif ($pathElementCount == 1) {
   181                 $params['id'] = urldecode(array_shift($path));
   181                 $params['id'] = urldecode(array_shift($path));
   182             } elseif ($pathElementCount == 0 && !isset($params['id'])) {
   182             } elseif ($pathElementCount == 0 && !isset($params['id'])) {
   183                 $specialGetTarget = 'index';
   183                 $specialGetTarget = 'index';
   184             }
   184             }
   185 
   185 
   186             // Digest URI params
   186             // Digest URI params
   187             if ($numSegs = count($path)) {
   187             if ($numSegs = count($path)) {
   188                 for ($i = 0; $i < $numSegs; $i = $i + 2) {
   188                 for ($i = 0; $i < $numSegs; $i = $i + 2) {
   189                     $key = urldecode($path[$i]);
   189                     $key = urldecode($path[$i]);
   190                     $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
   190                     $val = isset($path[$i + 1]) ? $path[$i + 1] : null;
   191                     $params[$key] = $val;
   191                     $params[$key] = urldecode($val);
   192                 }
   192                 }
   193             }
   193             }
   194 
   194 
   195             // Determine Action
   195             // Determine Action
   196             $requestMethod = strtolower($request->getMethod());
   196             $requestMethod = strtolower($request->getMethod());