Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HttpRequestParameterService now just reads from $_GET and $_POST inst…

…ead of $_REQUEST
  • Loading branch information...
commit e0a48be2622b1212d95441f94ab5b2a03889879d 1 parent 5213995
@ehough ehough authored
View
10 .idea/tubepress.iml
@@ -10,6 +10,16 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jQuery-1.7.2" level="application" />
+ <orderEntry type="module-library">
+ <library name="PHP">
+ <CLASSES>
+ <root url="file:///usr/share/php" />
+ </CLASSES>
+ <SOURCES>
+ <root url="file:///usr/share/php" />
+ </SOURCES>
+ </library>
+ </orderEntry>
</component>
</module>
View
37 src/main/php/classes/tubepress/impl/http/DefaultHttpRequestParameterService.php
@@ -15,12 +15,17 @@
class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepress_spi_http_HttpRequestParameterService
{
/**
- * Gets the parameter value from PHP's $_REQUEST array.
+ * @var array A merged array of $_GET and $_POST for this request.
+ */
+ private $_cachedMergedGetAndPostArray;
+
+ /**
+ * Gets the parameter value from PHP's $_GET or $_POST array.
*
* @param string $name The name of the parameter.
*
* @return mixed The raw value of the parameter. Can be anything that would
- * otherwise be found in PHP's $_REQUEST array. Returns null
+ * otherwise be found in PHP's $_GET or $_POST array. Returns null
* if the parameter is not set on this request.
*/
public final function getParamValue($name)
@@ -31,7 +36,8 @@ class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepres
return null;
}
- $rawValue = $_REQUEST[$name];
+ $request = $this->_getGETandPOSTarray();
+ $rawValue = $request[$name];
$eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
@@ -51,7 +57,7 @@ class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepres
}
/**
- * Gets the parameter value from PHP's $_REQUEST array. If the hasParam($name) returs false, this
+ * Gets the parameter value from PHP's $_GET or $_POST array. If the hasParam($name) returns false, this
* behaves just like getParamvalue($name). Otherwise, if the raw parameter value is numeric, a conversion
* will be attempted.
*
@@ -59,7 +65,7 @@ class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepres
* @param int $default The default value is the raw value is not integral.
*
* @return mixed The raw value of the parameter. Can be anything that would
- * otherwise be found in PHP's $_REQUEST array. Returns null
+ * otherwise be found in PHP's $_GET or $_POST array. Returns null
* if the parameter is not set on this request.
*/
public final function getParamValueAsInt($name, $default)
@@ -76,15 +82,17 @@ class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepres
}
/**
- * Determines if the parameter is set in PHP's $_REQUEST array.
+ * Determines if the parameter is set in PHP's $_GET or $_POST array.
*
* @param string $name The name of the parameter.
*
- * @return mixed True if the parameter is found in PHP's $_REQUEST array, false otherwise.
+ * @return mixed True if the parameter is found in PHP's $_GET or $_POST array, false otherwise.
*/
public final function hasParam($name)
{
- return array_key_exists($name, $_REQUEST);
+ $request = $this->_getGETandPOSTarray();
+
+ return array_key_exists($name, $request);
}
/**
@@ -95,13 +103,24 @@ class tubepress_impl_http_DefaultHttpRequestParameterService implements tubepres
public final function getAllParams()
{
$toReturn = array();
+ $request = $this->_getGETandPOSTarray();
- foreach ($_REQUEST as $key => $value) {
+ foreach ($request as $key => $value) {
$toReturn[$key] = $this->getParamValue($key);
}
return $toReturn;
}
+
+ private function _getGETandPOSTarray()
+ {
+ if (! isset($this->_cachedMergedGetAndPostArray)) {
+
+ $this->_cachedMergedGetAndPostArray = array_merge($_GET, $_POST);
+ }
+
+ return $this->_cachedMergedGetAndPostArray;
+ }
}
View
14 src/main/php/classes/tubepress/spi/http/HttpRequestParameterService.php
@@ -10,25 +10,25 @@
*/
/**
- * Pulls out info from $_REQUEST.
+ * Pulls out info from $_GET or $_POST.
*/
interface tubepress_spi_http_HttpRequestParameterService
{
const _ = 'tubepress_spi_http_HttpRequestParameterService';
/**
- * Gets the parameter value from PHP's $_REQUEST array.
+ * Gets the parameter value from PHP's $_GET or $_POST array.
*
* @param string $name The name of the parameter.
*
* @return mixed The raw value of the parameter. Can be anything that would
- * otherwise be found in PHP's $_REQUEST array. Returns null
+ * otherwise be found in PHP's $_GET or $_POST array. Returns null
* if the parameter is not set on this request.
*/
function getParamValue($name);
/**
- * Gets the parameter value from PHP's $_REQUEST array. If the hasParam($name) returs false, this
+ * Gets the parameter value from PHP's $_GET or $_POST array. If the hasParam($name) returs false, this
* behaves just like getParamvalue($name). Otherwise, if the raw parameter value is numeric, a conversion
* will be attempted.
*
@@ -36,17 +36,17 @@ function getParamValue($name);
* @param int $default The default value is the raw value is not integral.
*
* @return mixed The raw value of the parameter. Can be anything that would
- * otherwise be found in PHP's $_REQUEST array. Returns null
+ * otherwise be found in PHP's $_GET or $_POST array. Returns null
* if the parameter is not set on this request.
*/
function getParamValueAsInt($name, $default);
/**
- * Determines if the parameter is set in PHP's $_REQUEST array.
+ * Determines if the parameter is set in PHP's $_GET or $_POST array.
*
* @param string $name The name of the parameter.
*
- * @return mixed True if the parameter is found in PHP's $_REQUEST array, false otherwise.
+ * @return mixed True if the parameter is found in PHP's $_GET or $_POST array, false otherwise.
*/
function hasParam($name);
View
15 src/test/php/classes/tubepress/impl/http/DefaultHttpRequestParameterServiceTest.php
@@ -23,13 +23,16 @@ function onSetup()
function testParamExists()
{
- $this->assertTrue($this->_sut->hasParam('something') === false);
-
- $_REQUEST['something'] = 5;
+ $_GET['something'] = 5;
$this->assertTrue($this->_sut->hasParam('something') === true);
}
+ function testParamNotExists()
+ {
+ $this->assertTrue($this->_sut->hasParam('something') === false);
+ }
+
function testGetParamValueNoExist()
{
$this->assertTrue($this->_sut->getParamValue('something') === null);
@@ -37,7 +40,7 @@ function testGetParamValueNoExist()
function testGetParam()
{
- $_REQUEST['something'] = array(1, 2, 3);
+ $_POST['something'] = array(1, 2, 3);
$this->_mockEventDispatcher->shouldReceive('dispatch')->once()->with(tubepress_api_const_event_CoreEventNames::VARIABLE_READ_FROM_EXTERNAL_INPUT, Mockery::on(function ($arg) {
@@ -57,7 +60,7 @@ function testGetParam()
function testGetParamAsIntActuallyInt()
{
- $_REQUEST['something'] = array(1, 2, 3);
+ $_POST['something'] = array(1, 2, 3);
$this->_mockEventDispatcher->shouldReceive('dispatch')->once()->with(tubepress_api_const_event_CoreEventNames::VARIABLE_READ_FROM_EXTERNAL_INPUT, Mockery::on(function ($arg) {
@@ -77,7 +80,7 @@ function testGetParamAsIntActuallyInt()
function testGetParamAsIntNotActuallyInt()
{
- $_REQUEST['something'] = array(1, 2, 3);
+ $_GET['something'] = array(1, 2, 3);
$this->_mockEventDispatcher->shouldReceive('dispatch')->once()->with(tubepress_api_const_event_CoreEventNames::VARIABLE_READ_FROM_EXTERNAL_INPUT, Mockery::on(function ($arg) {
Please sign in to comment.
Something went wrong with that request. Please try again.