/** * We will register user defined events, it will trigger event when matches. * * @param $events * * @throws \RuntimeException */ public function registerEvents($events) { if (empty($events)) { throw new \RuntimeException(sprintf('Empty argument passed %s', __FUNCTION__)); } foreach ($events as $event => $namespace) { $parts = explode('@', $namespace); // attach all before and after event to handler $this->attach("{$event}.before", $parts[0] . '@before' . ucfirst(Inflector::pathAction(end($parts))))->attach("{$event}", $parts[0] . '@' . Inflector::pathAction(end($parts)))->attach("{$event}.after", $parts[0] . '@after' . ucfirst(Inflector::pathAction(end($parts)))); } }
/** * Set the controller as Route Controller * Cygnite Router knows how to respond to routes controller * request automatically * @param $controller * @return $this */ public function routeController($controller) { $actions = $this->getActions(); foreach ($actions as $key => $action) { $method = ucfirst(Inflector::pathAction($action)); if (method_exists($this, 'set' . $method . 'Route')) { $this->{'set' . $method . 'Route'}(Inflector::deCamelize($controller), $action); } } return $this; }
public function testPathActionMethod() { $this->assertEquals('dashSeparated', Inflector::pathAction('dash-separated')); $this->assertEquals('dashSeparated', Inflector::pathAction('dash_separated')); }