Skip to content

Commit

Permalink
Merge pull request #16 from EvolutionLabs/master
Browse files Browse the repository at this point in the history
expand parsing of controller actions
  • Loading branch information
pahanini authored Mar 8, 2017
2 parents 3758b92 + c5693f6 commit eb93f32
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions models/ControllerParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ public function parse(Doc $doc)
return false;
}

$object = $this->getObject();

$doc->path = Inflector::camel2id(substr($this->reflection->getShortName(), 0, -strlen('Controller')));
$doc->actions = array_keys($object->actions());
$doc->actions = $this->parseActions();

// Parse model
$modelParser = Yii::createObject(
Expand Down Expand Up @@ -90,4 +88,28 @@ public function parseClass(ControllerDoc $doc)
$parentParser->parseClass($doc);
}
}

/**
* include actions defined in controller, as well as those returned by `Controller::actions()` method
*
* @return array
*/
private function parseActions()
{
// default controller actions
$actions = array_keys($this->getObject()->actions());
$actionMethods = array_filter($this->reflection->getMethods(),
function ($method) {
// should match all methods named actionSomeAction
return preg_match('/action([A-Z]{1}[a-zA-Z]+)/', $method->name, $matches);
});
$actionMethods = array_map(function ($method) {
return Inflector::slug(str_replace('action', '', $method->name));
}, $actionMethods);
$actionMethods = array_merge($actions, $actionMethods);

return array_intersect(['index', 'view', 'create', 'update', 'delete', 'options'], $actionMethods);

}

}

0 comments on commit eb93f32

Please sign in to comment.