Created
March 3, 2015 03:22
-
-
Save cgsmith/ed03f4726f7161404fe7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Router; | |
/** | |
* Class RestRoute | |
* | |
* Extends \Zend_Controller_Router_Route and handles methods in the router | |
* | |
* @author Chris Smith | |
*/ | |
class RestRoute | |
extends \Zend_Controller_Router_Route | |
{ | |
/** | |
* @const string METHOD_GET Used to read only resource. | |
*/ | |
const METHOD_GET = 'GET'; | |
/** | |
* @var string HTTP method for use in match() | |
*/ | |
protected $_method; | |
/** | |
* @var request object | |
*/ | |
protected $_request; | |
/** | |
* Adding HTTP method for use in match() | |
* | |
* @param string $method our method we are checking against | |
* @see {parent::__construct} | |
* @param array $route | |
* @param array $defaults | |
* @param array $reqs | |
* @param \Zend_Translate $translator | |
* @param null $locale | |
*/ | |
public function __construct( | |
$request, $method, $route, $defaults = array(), $reqs = array(), | |
\Zend_Translate $translator = null, $locale = null) | |
{ | |
$this->_request = $request; | |
$this->_method = $method; | |
parent::__construct($route, $defaults, $reqs, $translator, $locale); | |
} | |
/** | |
* If our requested method does not match the route we return false | |
* | |
* @see {parent::match()} | |
* @param string $path | |
* @param bool $partial | |
* @return array|bool|false | |
*/ | |
public function match($path, $partial = false) | |
{ | |
return ( strtoupper( $this->_method ) !== strtoupper( $this->_request->getMethod() ) ) ? false : parent::match( $path, $partial ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment