Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/action/sfActions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <[email protected]>
* (c) 2004-2006 Sean Kerr <[email protected]>
*
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -57,6 +57,9 @@ public function execute($request)
}

// run action
return $this->$actionToRun($request);
return $this->getService('sf_parameter_resolver')
->setRequest($request)
->setComponent($this)
->execute($actionToRun);
}
}
66 changes: 66 additions & 0 deletions lib/action/sfParameterResolver.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

class sfParameterResolver
{
protected $container;
protected $request;
protected $component;

public function __construct(sfServiceContainer $container = null)
{
$this->container = $container;
}

public function setRequest(sfWebRequest $request)
{
$this->request = $request;

return $this;
}

public function setComponent(sfComponent $component)
{
$this->component = $component;

return $this;
}

public function execute($actionToRun = 'execute')
{
return call_user_func_array(array($this->component, $actionToRun), $this->resolveParams($actionToRun));
}

protected function resolveParams($actionToRun)
{
$reflection = new ReflectionObject($this->component);
$method = $reflection->getMethod($actionToRun);

$parameters = array();
foreach ($method->getParameters() as $i => $param) {
$type = $param->getClass();

// handle case where request parameter was not type hinted
if (null === $type && $i === 0) {
$parameters[] = $this->request;
continue;
}

if (null === $type) {
throw new \Exception("Additional parameters must be type hinted");
}

if ($type->getName() == "sfWebRequest") {
$parameters[] = $this->request;
} else {
$parameters[] = $this->getParamFromContainer($type->getName());
}
}

return $parameters;
}

protected function getParamFromContainer($param)
{
return $this->container->getService($param);
}
}
3 changes: 2 additions & 1 deletion lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static public function make()
'sfactions' => 'action/sfActions.class.php',
'sfcomponent' => 'action/sfComponent.class.php',
'sfcomponents' => 'action/sfComponents.class.php',
'sfparameterresolver' => 'action/sfParameterResolver.class.php',
'sfdata' => 'addon/sfData.class.php',
'sfpager' => 'addon/sfPager.class.php',
'sfautoload' => 'autoload/sfAutoload.class.php',
Expand Down Expand Up @@ -522,8 +523,8 @@ static public function make()
'sfwidgetforminput' => 'widget/sfWidgetFormInput.class.php',
'sfwidgetforminputcheckbox' => 'widget/sfWidgetFormInputCheckbox.class.php',
'sfwidgetforminputfile' => 'widget/sfWidgetFormInputFile.class.php',
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
'sfwidgetforminputfileeditable' => 'widget/sfWidgetFormInputFileEditable.class.php',
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
'sfwidgetforminputhidden' => 'widget/sfWidgetFormInputHidden.class.php',
'sfwidgetforminputpassword' => 'widget/sfWidgetFormInputPassword.class.php',
'sfwidgetforminputread' => 'widget/sfWidgetFormInputRead.class.php',
Expand Down
5 changes: 5 additions & 0 deletions lib/config/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ all:
arguments:
- '@sf_event_dispatcher'
- '@sf_formatter'

sf_parameter_resolver:
class: sfParameterResolver
arguments:
- '@service_container'
6 changes: 5 additions & 1 deletion lib/filter/sfExecutionFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ protected function executeAction($actionInstance)
{
// execute the action
$actionInstance->preExecute();
$viewName = $actionInstance->execute($this->context->getRequest());
$viewName = $this->context->getService('sf_parameter_resolver')
->setRequest($this->context->getRequest())
->setComponent($actionInstance)
->execute();

$actionInstance->postExecute();

return null === $viewName ? sfView::SUCCESS : $viewName;
Expand Down
7 changes: 5 additions & 2 deletions lib/helper/PartialHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function has_component_slot($name)
{
return false;
}

// check to see if component slot is empty (null)
if ($viewInstance->getComponentSlot($name))
{
Expand Down Expand Up @@ -385,7 +385,10 @@ function _call_component($moduleName, $componentName, $vars)
$timer = sfTimerManager::getTimer(sprintf('Component "%s/%s"', $moduleName, $componentName));
}

$retval = $componentInstance->$componentToRun($context->getRequest());
$retval = $context->getService('sf_parameter_resolver')
->setRequest($context->getRequest())
->setComponent($componentInstance)
->execute($componentToRun);

if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
{
Expand Down