Beispiel #1
0
 public function testUnderscoresCamelcase()
 {
     $uc = array('simple_test' => 'SimpleTest');
     foreach ($uc as $u => $c) {
         $this->assertEqual(FWU::underscoresToCamelcase($u), $c);
     }
 }
Beispiel #2
0
 /**
  * Dispatch request
  *
  * @param string|array $url
  * @return void
  */
 public function dispatch($url)
 {
     assert('is_string($url) || is_array($url)');
     // check recursion
     static $dispatch_count = 0;
     if ($dispatch_count >= 50) {
         throw new FWException('FWRequest->dispatch: Too much recursion. (loop?)');
     }
     ++$dispatch_count;
     // get router
     $router = $this->getRouter();
     if (!$router) {
         throw new FWException('Please FWRouter->setRouter() first.');
     }
     try {
         // route url
         if (is_string($url)) {
             $route = $router->route($url);
             if (!$route) {
                 $this->forward404();
             }
             if (!isset($route['controller']) || !isset($route['action'])) {
                 $this->forward404();
             }
         } else {
             $route = $url;
         }
         // validate controller and action names
         $controller = FWU::underscoresToCamelcase($route['controller']);
         $action = FWU::underscoresToCamelcase($route['action']);
         $controller_re = '|^[A-Za-z][A-Za-z0-9]*$|';
         $action_re = '|^[A-Za-z0-9]+$|';
         if (!preg_match($controller_re, $controller) || !preg_match($action_re, $action)) {
             $this->forward404();
         }
         // controller exists?
         $controller_class = $controller . 'Controller';
         $controller_file = APP_DIR . '/controllers/' . $controller_class . '.class.php';
         if (!is_file($controller_file)) {
             $this->forward404();
         }
         require_once $controller_file;
         if (!class_exists($controller_class)) {
             $this->forward404();
         }
         // action exists?
         $action_method = 'execute' . $action;
         if (!method_exists($controller_class, $action_method)) {
             $this->forward404();
         }
         // set parameters
         $this->flushParameters();
         $this->addParameters($route);
         $this->addParameters($_GET);
         $this->addParameters($_POST);
         // call action
         $obj = new $controller_class();
         $obj->setRequest($this);
         $this->forward404Unless($obj->dispatch($action));
     } catch (FWForwardException $e) {
         $this->dispatch($e->parameters);
     }
 }