Changeset 1638

Show
Ignore:
Timestamp:
02/04/07 17:23:30 (2 years ago)
Author:
david
Message:

support for lightweight actions. these don't run through action filters, don't call execute() on the action (and thus don't pass validation) and don't get any data from the actual request, only the arguments set on their containers. good for slots. make an action 'simple' by returning true from isSimple() in the action. closes #407

Location:
branches/0.11
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/samples/app/modules/Default/actions/MenuAction.class.php

    r1635 r1638  
    7171    return 'Success'; 
    7272  } 
     73   
     74  public function isSimple() 
     75  { 
     76    return true; 
     77  } 
    7378} 
    7479 
  • branches/0.11/src/action/AgaviAction.class.php

    r1607 r1638  
    130130 
    131131  /** 
     132   * Whether or not this action is "simple", i.e. doesn't use validation etc. 
     133   * 
     134   * @return     bool true, if this action should act in simple mode, or false. 
     135   * 
     136   * @author     David Zuelke <dz@bitxtender.com> 
     137   * @since      0.11.0 
     138   */ 
     139  public function isSimple() 
     140  { 
     141    return false; 
     142  } 
     143 
     144  /** 
    132145   * Manually register validators for this action. 
    133146   * 
  • branches/0.11/src/controller/AgaviExecutionContainer.class.php

    r1635 r1638  
    187187    $request = $this->context->getRequest(); 
    188188     
    189     $this->requestData = clone $request->getRequestData(); 
    190      
    191     if($this->arguments !== null) { 
    192       $this->requestData->merge($this->arguments); 
    193     } 
    194      
    195189    $controller->countExecution(); 
    196190     
     
    280274      $this->actionInstance->initialize($this); 
    281275       
    282       // create a new filter chain 
    283       $fcfi = $this->context->getFactoryInfo('filter_chain'); 
    284       $filterChain = new $fcfi['class'](); 
    285       $filterChain->initialize($this->context, $fcfi['parameters']); 
    286  
    287       if(AgaviConfig::get('core.available', false)) { 
    288         // the application is available so we'll register 
    289         // global and module filters, otherwise skip them 
    290  
    291         // does this action require security? 
    292         if(AgaviConfig::get('core.use_security', false) && $this->actionInstance->isSecure()) { 
    293           // register security filter 
    294           $filterChain->register($controller->getFilter('security')); 
     276      if($this->actionInstance->isSimple()) { 
     277        if($this->arguments !== null) { 
     278          $this->requestData = $this->arguments; 
     279        } else { 
     280          $this->requestData = new AgaviRequestDataHolder(); 
    295281        } 
    296  
    297         // load filters 
    298         $controller->loadFilters($filterChain, 'action'); 
    299         $controller->loadFilters($filterChain, 'action', $moduleName); 
     282        var_dump('foo'); 
     283        // run the execution filter, without a proper chain 
     284        $controller->getFilter('execution')->execute(new AgaviFilterChain(), $this); 
     285      } else { 
     286        $this->requestData = clone $request->getRequestData(); 
     287         
     288        if($this->arguments !== null) { 
     289          $this->requestData->merge($this->arguments); 
     290        } 
     291       
     292        // create a new filter chain 
     293        $fcfi = $this->context->getFactoryInfo('filter_chain'); 
     294        $filterChain = new $fcfi['class'](); 
     295        $filterChain->initialize($this->context, $fcfi['parameters']); 
     296 
     297        if(AgaviConfig::get('core.available', false)) { 
     298          // the application is available so we'll register 
     299          // global and module filters, otherwise skip them 
     300 
     301          // does this action require security? 
     302          if(AgaviConfig::get('core.use_security', false) && $this->actionInstance->isSecure()) { 
     303            // register security filter 
     304            $filterChain->register($controller->getFilter('security')); 
     305          } 
     306 
     307          // load filters 
     308          $controller->loadFilters($filterChain, 'action'); 
     309          $controller->loadFilters($filterChain, 'action', $moduleName); 
     310        } 
     311 
     312        // register the execution filter 
     313        $filterChain->register($controller->getFilter('execution')); 
     314 
     315        // process the filter chain 
     316        $filterChain->execute($this); 
    300317      } 
    301  
    302       // register the execution filter 
    303       $filterChain->register($controller->getFilter('execution')); 
    304  
    305       // process the filter chain 
    306       $filterChain->execute($this); 
    307318       
    308319      // restore autoloads 
     
    327338      } 
    328339       
    329       // TODO. this will be pretty difficult, I guess... 
    330340      $this->setNext($controller->createExecutionContainer($moduleName, $actionName)); 
    331341    } 
  • branches/0.11/src/filter/AgaviExecutionFilter.class.php

    r1635 r1638  
    206206  public function execute(AgaviFilterChain $filterChain, AgaviExecutionContainer $container) 
    207207  { 
    208     $lm = $this->context->getLoggerManager(); 
     208    // $lm = $this->context->getLoggerManager(); 
     209     
    209210    // get the context, controller and validator manager 
    210211    $controller = $this->context->getController(); 
     
    472473    // get the (already formatted) request method 
    473474    $method = $request->getMethod(); 
     475     
     476    $requestData = $container->getRequestData(); 
    474477 
    475478    $useGenericMethods = false; 
     
    480483    } 
    481484 
    482     if($useGenericMethods && !method_exists($actionInstance, $executeMethod) ) { 
     485    if($actionInstance->isSimple() || ($useGenericMethods && !method_exists($actionInstance, $executeMethod))) { 
    483486      // this action will skip validation/execution for this method 
    484487      // get the default view 
     
    487490      // set default validated status 
    488491      $validated = true; 
    489  
     492       
    490493      // get the current action validation configuration 
    491494      $validationConfig = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/validate/' . $actionName . '.xml'; 
     
    505508 
    506509      // process validators 
    507       $validated = $validationManager->execute($container->getRequestData()); 
    508  
     510      $validated = $validationManager->execute($requestData); 
     511       
    509512      $validateMethod = 'validate' . $method; 
    510513      if(!method_exists($actionInstance, $validateMethod)) { 
    511514        $validateMethod = 'validate'; 
    512515      } 
    513  
     516       
    514517      // prevent access to Request::getParameters() 
    515518      // process manual validation 
    516       if($actionInstance->$validateMethod($container->getRequestData()) && $validated) { 
     519      if($actionInstance->$validateMethod($requestData) && $validated) { 
    517520        // execute the action 
    518521        $key = $request->toggleLock(); 
    519         $viewName = $actionInstance->$executeMethod($container->getRequestData()); 
     522        $viewName = $actionInstance->$executeMethod($requestData); 
    520523        $request->toggleLock($key); 
    521524      } else { 
     
    526529        } 
    527530        $key = $request->toggleLock(); 
    528         $viewName = $actionInstance->$handleErrorMethod($container->getRequestData()); 
     531        $viewName = $actionInstance->$handleErrorMethod($requestData); 
    529532        $request->toggleLock($key); 
    530533      }