Skip to content
Browse files

Improve params management in Request

  • Loading branch information...
1 parent b6dbb8b commit 77e3e5a35d8ff77875e987699a8f63a03289353e @kevinard kevinard committed Feb 22, 2012
View
6 framework/config/components.php
@@ -142,6 +142,12 @@
return new \framework\libs\Event($args[0], $args[1]);
},
'isUnique' => false),
+ 'registry' => array(
+ 'callable' => function ($c, $args)
+ {
+ return new \framework\libs\Registry($args[0]);
+ },
+ 'isUnique' => false),
'logger' => array(
'callable' => function ($c, $args)
{
View
12 framework/core/Core.php
@@ -65,14 +65,19 @@ public function run ()
$request = $this->getComponent('httpRequest');
$response = $this->getComponent('httpResponse');
- $params = array();
+ $params = array(
+ 'module' => null,
+ 'action' => null,
+ 'method' => null,
+ 'format' => null
+ );
$state = null;
if ($request->isCli())
{
$params = \modules\cli\CliUtils::extractParams();
$params['module'] = 'cli';
- $params["format"] = 'html';
+ $params["format"] = 'cli';
$params["method"] = 'get';
$state = \framework\core\Request::CLI_STATE;
@@ -102,7 +107,8 @@ public function run ()
$url = $request->getUrl();
- $params = $this->getComponent('router')->match($request->getMethod(), $url);
+ $params = $this->getComponent('registry', $this->getComponent('router')->match($request->getMethod(), $url));
+ $params['post'] = $request->getFromPost();
$params["method"] = $request->getMethod();
$this->duplicateContentPolicy($url, $params);
View
2 framework/core/FrameworkObject.php
@@ -105,7 +105,7 @@ public function getContainer()
public function createRequest($params = array(), $state = null)
{
- return $this->getComponent('request', $params, $state);
+ return $this->getComponent('request', $this->getComponent('registry', $params), $state);
}
public function createView(Array $file, $vars = false, $format = null)
View
13 framework/core/Request.php
@@ -28,7 +28,7 @@ class Request extends \framework\core\FrameworkObject
const CLI_STATE = -50;
const FIRST_REQUEST = -100;
- public function __construct (Array $params = array(), $state = self::DEFAULT_STATE)
+ public function __construct (\framework\Libs\Registry $params, $state = self::DEFAULT_STATE)
{
$this->_params = $params;
$this->_state = $state;
@@ -103,16 +103,19 @@ public function __set ($key, $value)
public function get ($key, $default = null)
{
- if (isset($this->_params['params'][$key]))
+ $value = $this->_params->get($key, true);
+
+ if ($value === null)
{
- return $this->_params['params'][$key];
+ $value = $default;
}
- return $default;
+
+ return $value;
}
public function set ($key, $value)
{
- $this->_params['params'][$key] = $value;
+ $this->_params->set($key, $value);
return $this;
}
}
View
2 framework/core/http/exception/NotFoundException.php
@@ -23,7 +23,7 @@ class NotFoundException extends \Exception
{
public function __construct ($params = null)
{
- $r = new \framework\core\Request(array('module' => 'errors', 'action' => 'error404', 'format' => 'html', 'params' => $params));
+ $r = new \framework\core\Request(new \framework\libs\Registry(array('module' => 'errors', 'action' => 'error404', 'method' => 'get', 'format' => 'html', 'params' => $params)));
$r->execute();
}
View
7 framework/libs/Registry.php
@@ -26,8 +26,13 @@ class Registry extends \ArrayObject
* This is recursive, i.e. every array inside $array will also be stored as an object
* @param array $array The array that will be accessed as an object
*/
- public function __construct(array $array = array())
+ public function __construct($array = array())
{
+ if ($array instanceof self)
+ {
+ $array = $array->toArray();
+ }
+
foreach($array as $key => $value)
{
if (\is_array($value))

0 comments on commit 77e3e5a

Please sign in to comment.
Something went wrong with that request. Please try again.