Web Commons
Current file: /home/antoine/zavaee/Web Commons/WebCommons/controller.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 3 / 3
100.00%100.00%
100.00% 4 / 4
100.00%100.00%
100.00% 14 / 14
 
AbstractController
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
100.00%100.00%
100.00% 12 / 12
 public function getRequest()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function setRequest(Request $request)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function runAction($action)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9
ActionNotFoundException
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 0 / 0
ActionException
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function __construct($message, Exception $previous)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2


       1                 : <?php                                                                           
       2                 : /**                                                                             
       3                 :  * This file groups classes pertaining to the "controller" of MVC.              
       4                 :  *                                                                               
       5                 :  * @author Antoine d'Otreppe de Bouvette <a.dotreppe@aspyct.org>                
       6                 :  * @license http://www.opensource.org/licenses/mit-license.php                  
       7                 :  * @version 0.1dev                                                              
       8                 :  */                                                                             
       9                 :                                                                                 
      10                 : /**                                                                             
      11                 :  * Defines a common base for web controllers.                                   
      12                 :  *                                                                               
      13                 :  * @since 0.1                                                                   
      14                 :  */                                                                             
      15                 : abstract class AbstractController {                                             
      16                 :     /**                                                                         
      17                 :      * @var Request                                                             
      18                 :      */                                                                         
      19                 :     private $request;                                                           
      20                 :                                                                                     
      21                 :     /**                                                                         
      22                 :      * @return Request                                                          
      23                 :      * @since 0.1                                                               
      24                 :      */                                                                         
      25                 :     public function getRequest() {                                              
      26               1 :         return $this->request;                                                  
      27                 :     }                                                                           
      28                 :                                                                                     
      29                 :     /**                                                                         
      30                 :      * @param Request $request                                                  
      31                 :      * @since 0.1                                                               
      32                 :      */                                                                         
      33                 :     public function setRequest(Request $request) {                              
      34               1 :         $this->request = $request;                                              
      35               1 :     }                                                                           
      36                 :                                                                                     
      37                 :     /**                                                                         
      38                 :      * Finds the action named "do_$action" and runs it with the $request object.
      39                 :      * Returns the return value of the action. Throws an ActionNotFoundException
      40                 :      * if the action could not be found.                                        
      41                 :      *                                                                           
      42                 :      * @param string $action                                                    
      43                 :      * @param Request $request                                                  
      44                 :      * @throws ActionNotFoundException                                          
      45                 :      * @return mixed                                                            
      46                 :      * @since 0.1                                                               
      47                 :      */                                                                         
      48                 :     public function runAction($action) {                                        
      49               3 :         $method = array($this, 'do_' . $action);                                
      50                 :                                                                                         
      51               3 :         if (is_callable($method)) {                                             
      52                 :             try {                                                               
      53               2 :                 return call_user_func($method);                                 
      54                 :             }                                                                   
      55               1 :             catch (Exception $e) {                                              
      56               1 :                 throw new ActionException(                                      
      57               1 :                     get_class($this).'::do_'.$action.' thrown an exception',    
      58                 :                     $e                                                          
      59               1 :                 );                                                              
      60                 :             }                                                                   
      61                 :         }                                                                       
      62                 :         else {                                                                  
      63               1 :             throw new ActionNotFoundException(                                  
      64               1 :                 'Could not find action "' . $action . '".');                    
      65                 :         }                                                                       
      66                 :     }                                                                           
      67                 : }                                                                               
      68                 :                                                                                 
      69                 : /**                                                                             
      70                 :  * Exception thrown when the requested action could not be found.               
      71                 :  *                                                                               
      72                 :  * @since 0.1                                                                   
      73                 :  */                                                                             
      74                 : class ActionNotFoundException extends Exception {}                              
      75                 :                                                                                 
      76                 : /**                                                                             
      77                 :  * Exception thrown when an action ran by runAction() thrown an exception       
      78                 :  */                                                                             
      79                 : class ActionException extends Exception {                                       
      80                 :     /**                                                                         
      81                 :      * @param string $message                                                   
      82                 :      * @param Exception $previous                                               
      83                 :      */                                                                         
      84                 :     public function __construct($message, Exception $previous) {                
      85               1 :         parent::__construct($message, 0, $previous);                            
      86               1 :     }                                                                           

Generated by PHPUnit 3.4.5 and Xdebug 2.1.0 at Fri Jul 16 0:48:38 CEST 2010.