Skip to content

Commit

Permalink
getParams now only returns the parsed params. fixes frapi#167
Browse files Browse the repository at this point in the history
moved the contents of getParams() into a new method setParams(), which is only called once in the constructor.
now getParams() is a simple getter rather than a mixed getter/setter.  also removed mixing of $this->request and $this->params
  • Loading branch information
clayhinson committed Jun 28, 2012
1 parent ecb5e6a commit 49e21ad
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/frapi/library/Frapi/Controller/Main.php
Expand Up @@ -36,7 +36,7 @@ class Frapi_Controller_Main
* The request parameter
*
* The value of the superglobal $_REQUEST
* variable from the web server.
* variable from the web server plus route variables.
*
* @var array $request The $_REQUEST
*/
Expand Down Expand Up @@ -247,7 +247,9 @@ public function __construct($customAuthorization=null)
$this->setAction($this->getParam('action'));
}

$this->setFiles($_FILES);
// assign the files and params from the request
$this->setFiles($_FILES)
->setParams($this->request);

$this->authorization->setAuthorizationParams($this->getParams());
} catch (Frapi_Exception $e) {
Expand Down Expand Up @@ -295,11 +297,12 @@ public function getFiles()
* the filess variable.
*
* @param array $params The params to set.
* @return void
* @return Frapi_Controller_Main
*/
private function setFiles($params)
{
$this->files = $params;
return $this;
}

/**
Expand All @@ -308,21 +311,22 @@ private function setFiles($params)
* This method returns an array of the parameters
* passed.
*
* Is this similar to getRequest ? I have to check tmrw.
* @todo ^
* @return Mixed An array or a string of parameters
*/
public function getParams()
{
$params = $this->request;

/**
* This certainly isn't a pure approach however it is a very
* practical approach that will suit most people most of the times.
*
* Unhappy? Remove me.
*/
return $this->params;
}

/**
* parses the request and sets request parameters for later use
*
* @param array $params request params collected so far
* @return Frapi_Controller_Main
*/
public function setParams(array $params)
{
// read the raw input to get the request body
$input = file_get_contents("php://input");
parse_str($input, $puts);

Expand Down Expand Up @@ -371,8 +375,9 @@ public function getParams()
}
}

$this->request = $params;
return $this->request;
// set the total request params; combines derived request params and parsed params
$this->params = $params;
return $this;
}

/**
Expand All @@ -386,8 +391,8 @@ public function getParams()
*/
public function getParam($key)
{
if (isset($this->request[$key])) {
return $this->request[$key];
if (isset($this->params[$key])) {
return $this->params[$key];
}

if (isset($this->files[$key])) {
Expand Down

0 comments on commit 49e21ad

Please sign in to comment.