/** * {@inheritdoc} */ public function autoRoute(RoutingTable $table, $route, $resource = false) { $class = $route['snippet']; $dirs = explode('\\', $class); $dirs = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), $dirs); $pattern = 'ANY ' . str_replace('_', '.', implode('/', $dirs)); $table->match($pattern, $route); return $pattern; }
/** * {@inheritdoc} */ public function autoRoute(RoutingTable $table, $route, $resource = false) { $controller = $route['controller']; $dirs = explode('\\', $controller); if ($dirs == array('App')) { $dirs = array(); } else { $dirs = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), $dirs); } $patternBase = implode('/', $dirs); if ($resource) { $table->match($patternBase, 'action:' . $controller . '::index'); $table->match($patternBase . '/add', 'action:' . $controller . '::add'); //C $table->match($patternBase . '/:0', 'action:' . $controller . '::view'); //R $table->match($patternBase . '/:0/edit', 'action:' . $controller . '::edit'); //U $table->match($patternBase . '/:0/delete', 'action:' . $controller . '::delete'); //D $table->match('DELETE ' . $patternBase . '/:0', 'action:' . $controller . '::delete'); $table->match('PATCH ' . $patternBase . '/:0', 'action:' . $controller . '::edit'); $table->match('PUT ' . $patternBase . '/:0', 'action:' . $controller . '::edit'); $table->match('POST ' . $patternBase, 'action:' . $controller . '::add'); return $patternBase . '/:0'; } else { if (isset($route['action'])) { $action = $route['action']; $class = $this->getClass($controller); if (!$class) { throw new InvalidClassException(tr('Invalid controller: %1', $controller)); } $route = array('controller' => $controller, 'action' => $action); $reflect = new \ReflectionMethod($class, $action); $required = $reflect->getNumberOfRequiredParameters(); $total = $reflect->getNumberOfParameters(); if (!empty($prefix) and substr($prefix, -1) != '/') { $prefix .= '/'; } if ($action == 'index') { $table->match($patternBase, $route); } $patternBase .= '/' . str_replace('_', '.', Utilities::camelCaseToDashes($action)); if ($required < 1) { $table->match($patternBase, $route); } $path = $patternBase; for ($i = 0; $i < $total; $i++) { $path .= '/*'; if ($i <= $required) { $table->match($path, $route); } } return $patternBase; } else { $actions = $this->getActions($controller); if ($actions === false) { throw new InvalidClassException(tr('Invalid controller: %1', $controller)); } foreach ($actions as $action) { $route['action'] = $action; $this->autoRoute($table, $route, false); } return $patternBase; } } }