/** * Override this method to register routes handled by the module. * By default, handled routes follow the given pattern : * 'GET /module_name[/module_ctrl[/action[/param1/param2/...]]]' * If module is set as the default one, it also manages '/' request and its * route is named 'home' otherwise it is named with module's name. */ protected function registerRoutes() { $app = $this->app(); $module = $this; $route = $this->_name . '(/:ctrl(/:action(/:params+)))'; $route = '/' . ($this->isDefault() ? '(' . $route . ')' : $route); $app->get($route, function ($ctrl = 'index', $action = 'index', $params = null) use($app, $module) { // Set templates directory to the module's one if current view renderer is not Twig. if (!$app->view instanceof \BenGee\Slim\Twig\TwigView) { $app->view->setTemplatesDirectory($this->getDirectory() . DIRECTORY_SEPARATOR . 'views', $this->name()); } // Load controller class file. $ctrl_name = (!empty($ctrl) && trim($ctrl) != '' ? \BenGee\Slim\Utils\StringUtils::camelize($ctrl, true) : 'Index') . 'Controller'; require_once $this->getDirectory() . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $ctrl_name . '.php'; // Create an instance of the controller. $ctrl_instance = new $ctrl_name($module); // Call required action. $action_name = ($action != null && trim($action) != '' ? \BenGee\Slim\Utils\StringUtils::camelize($action) : 'index') . 'Action'; echo $params != null ? $ctrl_instance->{$action_name}($params) : $ctrl_instance->{$action_name}(); })->name($this->isDefault() ? 'home' : $this->name()); }
Result : <?php $result = StringUtils::camelize('a string to camelize1', false); echo $result . ' (' . ($result == 'aStringToCamelize1' ? 'SUCCESS' : 'FAILED') . ')'; ?> </li> <li> <pre>StringUtils::camelize('a string to camelize_2', true)</pre> Result : <?php $result = StringUtils::camelize('a string to camelize_2', true); echo $result . ' (' . ($result == 'AStringToCamelize2' ? 'SUCCESS' : 'FAILED') . ')'; ?> </li> <li> <pre>StringUtils::camelize('À_string-TO camelize=3', false)</pre> Result : <?php $result = StringUtils::camelize('À_string-TO camelize=3', false); echo $result . ' (' . ($result == 'aStringToCamelize3' ? 'SUCCESS' : 'FAILED') . ')'; ?> </li> </ul> </li> <li>startsWith() method <ul> <li> <pre>StringUtils::startsWith(null, '')</pre> Result : <?php try { $result = StringUtils::startsWith(null, ''); } catch (\Exception $e) { $result = '[!!! Exception !!!]'; }