public function rewrite(request $request) { $server = $request->get_server(); if (!$server['REQUEST_URI']) { $this->report_debug('No REQUEST_URI found - Nothing to rewrite'); return $this; } $this->report_debug("REQUEST_URI `{$server['REQUEST_URI']}` found"); foreach ($this->inform('uri_rewriter:rules') as $rule => $prm) { if (1 === preg_match($rule, $server['REQUEST_URI'], $matches)) { $this->report_debug("Rule `{$rule}` matches"); if (isset($prm['query'])) { $i = 1; foreach ($prm['query'] as $name => $value) { if ($value !== null || isset($matches[$i])) { $request->set('query', $name, $value !== null ? $value : $matches[$i++]); } } } if (isset($prm['internal'])) { $i = 1; foreach ($prm['internal'] as $name => $value) { $request->set('internal', $name, $value); } } return $this; } $this->report_debug("Rule `{$rule}` does not match"); } return $this; }
/** * XXX params in configurator ? * XXX params object or array ? * XXX bad balance between base_controller and generic_controller */ public function dispatch(request $request) { $filter = $this->pop('filter'); if ($controller = $filter->apply($request->get_query($this->inform('dispatcher:parameter')), array(array($filter, 'filter_string')))) { $this->report_debug("Specified controller `{$controller}` requested"); } else { $controller = $this->inform('dispatcher:default'); $this->report_debug("No specified controller requested, will use default `{$this->inform('dispatcher:default')}` one"); } try { $controller_o = $this->pop($controller . $this->inform('dispatcher:controller_suffix')); // First, try to find a controller object } catch (frame\exception\dna $e) { // Fallback to generic_controller $this->report_debug("Specific controller not found, will try the generic " . $this->inform('dispatcher:controller')); $controller_o = $this->pop($this->inform('dispatcher:controller'))->set_param($controller); } $controller_o->control_and_reveal($request); }