Example #1
0
 /**
  * Tests if the route matches a given Request. A successful match will return
  * all of the routed parameters as an array. A failed match will return
  * boolean FALSE.
  *
  *     // Params: controller = users, action = edit, id = 10
  *     $params = $route->matches(Request::factory('users/edit/10'));
  *
  * This method should almost always be used within an if/else block:
  *
  *     if ($params = $route->matches($request))
  *     {
  *         // Parse the parameters
  *     }
  *
  * @param   Request $request  Request object to match
  * @return  array             on success
  * @return  FALSE             on failure
  * @uses    Lang::$i18n_routes
  * @uses    Route::matches
  * @uses    Route::remap
  * @uses    Request::$lang
  * @uses    Lang::$default
  * @uses    HTTP_Exception_404
  */
 public function matches(Request $request)
 {
     if (!Lang::$i18n_routes) {
         // i18n routes are off
         return parent::matches($request);
     }
     // Set params
     $params = parent::matches($request);
     if ($params !== FALSE) {
         foreach ($params as $label => &$param) {
             if (isset($this->_translate['<' . $label . '>']) or isset($this->_translate[$param])) {
                 // If param might be translated see if it needs to be
                 // converted back to application (source) language
                 $source_param = Route::remap(UTF8::strtolower($param));
                 if (Request::$lang !== Lang::$default and isset($this->_translate['<' . $label . '>']) and $source_param === $param and strtolower($param) !== $this->_defaults[$label]) {
                     // To avoid duplicate content throw 404
                     throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => $request->uri()));
                 }
                 // Set translated param
                 $param = UTF8::ucfirst($source_param);
             }
         }
         // Return URI converted back to application (source) language
         return $params;
     } else {
         // No match
         return FALSE;
     }
 }