Skip to content

Commit

Permalink
Added customization of the inline action class
Browse files Browse the repository at this point in the history
  • Loading branch information
tisOO committed Jun 8, 2017
1 parent a529034 commit 62d290a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion JsonRpc2/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Controller extends \yii\web\Controller

public $enableResponseValidation = false;

/**
* @var string
*/
public $inlineActionClass = InlineAction::class;

/** @var array Stores information about param's types and method's return type */
private $methodInfo = [
'params' => [],
Expand Down Expand Up @@ -127,10 +132,29 @@ private function getActionResponse($requestObject)
*/
public function createAction($id)
{
$action = parent::createAction($id);
if ($id === '') {
$id = $this->defaultAction;
}

$action = null;
$actionMap = $this->actions();
if (isset($actionMap[$id])) {
$action = Yii::createObject($actionMap[$id], [$id, $this]);
} elseif (preg_match('/^[a-z0-9\\-_]+$/', $id) && strpos($id, '--') === false && trim($id, '-') === $id) {
$methodName = 'action' . str_replace(' ', '', ucwords(implode(' ', explode('-', $id))));
if (method_exists($this, $methodName)) {
$method = new \ReflectionMethod($this, $methodName);
if ($method->isPublic() && $method->getName() === $methodName) {
// need to check some information
$action = new $this->inlineActionClass($id, $this, $methodName);
}
}
}

if (empty($action))
throw new Exception(Yii::t('jsonrpc', 'Method not found').' '.$id, Exception::METHOD_NOT_FOUND);

/** @var \yii\base\Action $action */
$this->prepareActionParams($action);

return $action;
Expand Down

0 comments on commit 62d290a

Please sign in to comment.