Skip to content

Commit

Permalink
Adds minor handling refactors for sub-request - needs revisiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Manderson committed Oct 5, 2014
1 parent f002169 commit ad0d7ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Action/ActionKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ActionKernel implements HttpKernelInterface
/**
* @var array
*/
protected $dataSourceFactories;
protected $dataSourceFactories = array();

protected $init = false;

Expand Down
12 changes: 10 additions & 2 deletions src/Action/RequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ protected function processActionForm(\Symfony\Component\HttpFoundation\Request $
$request->attributes->set($mapping->getAttribute(), $instance);
} else {
$session = $request->getSession();
$session->set($mapping->getAttribute(), $instance);
if(!empty($session))
$session->set($mapping->getAttribute(), $instance);
}

return $instance;
Expand Down Expand Up @@ -799,12 +800,19 @@ protected function processForwardConfig(\Symfony\Component\HttpFoundation\Reques
protected function doForward($uri, \Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response)
{
$uri = $request->getUriForPath($uri);
$subRequest = Request::create($uri, 'GET', array(), $request->cookies->all(), array(), $request->server->all());
$subRequest = Request::create($uri, $request->getMethod(), $request->query->all(), $request->cookies->all(), $request->files->all(), $request->server->all());
if ($request->getSession()) {
$subRequest->setSession($request->getSession());
}

// Obtain a new subresponse
$attributes = $request->attributes->all();
// Remove silex attributes
unset($attributes['_controller']);
unset($attributes['_route']);
unset($attributes['_route_params']);
unset($attributes['path']);
$subRequest->attributes->add($attributes);
$subResponse = $this->actionKernel->getApplication()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);

// Update our current response to bring in the response
Expand Down
4 changes: 3 additions & 1 deletion src/Util/RequestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public static function createActionForm(\Symfony\Component\HttpFoundation\Reques
\Phruts\Util\ClassLoader::loadClass($config->getType());

$session = $request->getSession();
$instance = $session->get($attribute);
if(!empty($session)) {
$instance = $session->get($attribute);
}
}

// Can we recycle the existing form bean instance (if there is one)?
Expand Down
9 changes: 7 additions & 2 deletions tests/BehavioursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,15 @@ public function createApplication()
->assert('path', '.*')
->value('path', '/') // Set the welcome path
->before(function(Request $request) {
// Match a "?do=" as context path
$do = $request->get('do');
if(!empty($do)) {
$request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $do);
$rewritePath = $request->attributes->get('_rewrite_path'); // tmp var as attributes
if(empty($rewritePath)) {
$request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $do);
$request->attributes->set('_rewrite_path', 1);
} else {
$request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, null);
}
}
});

Expand Down
5 changes: 0 additions & 5 deletions tests/Resources/module1-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
<action path="/"
type="\Phruts\Actions\ForwardAction"
parameter="welcome"/>





<action path="/resourceA"
type="\Phruts\Actions\ForwardAction"
parameter="resource"/>
Expand Down

0 comments on commit ad0d7ad

Please sign in to comment.