Dwoo - Unit Tests Report
Current file: /dwoo/lib/Dwoo/Plugin.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
82.35%82.35%
82.35% 14 / 17
 
Dwoo_Plugin
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
82.35%82.35%
82.35% 14 / 17
 public function __construct(Dwoo $dwoo)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public static function paramsToAttributes(array $params, $delim = '\'')
100.00%100.00%
100.00% 1 / 1
80.00%80.00%
80.00% 12 / 15



       1                 : <?php                                                                                                                                  
       2                 :                                                                                                                                        
       3                 : /**                                                                                                                                    
       4                 :  * base plugin class                                                                                                                   
       5                 :  *                                                                                                                                     
       6                 :  * you have to implement the <em>process()</em> method, it will receive the parameters that                                            
       7                 :  * are in the template code                                                                                                            
       8                 :  *                                                                                                                                     
       9                 :  * This software is provided 'as-is', without any express or implied warranty.                                                         
      10                 :  * In no event will the authors be held liable for any damages arising from the use of this software.                                  
      11                 :  *                                                                                                                                     
      12                 :  * @author     Jordi Boggiano <j.boggiano@seld.be>                                                                                     
      13                 :  * @copyright  Copyright (c) 2008, Jordi Boggiano                                                                                      
      14                 :  * @license    http://dwoo.org/LICENSE   Modified BSD License                                                                          
      15                 :  * @link       http://dwoo.org/                                                                                                        
      16                 :  * @version    1.0.0                                                                                                                   
      17                 :  * @date       2008-10-23                                                                                                              
      18                 :  * @package    Dwoo                                                                                                                    
      19                 :  */                                                                                                                                    
      20                 : abstract class Dwoo_Plugin                                                                                                             
      21                 : {                                                                                                                                      
      22                 :     /**                                                                                                                                
      23                 :      * the dwoo instance that runs this plugin                                                                                         
      24                 :      *                                                                                                                                 
      25                 :      * @var Dwoo                                                                                                                       
      26                 :      */                                                                                                                                
      27                 :     protected $dwoo;                                                                                                                   
      28                 :                                                                                                                                        
      29                 :     /**                                                                                                                                
      30                 :      * constructor, if you override it, call parent::__construct($dwoo); or assign                                                     
      31                 :      * the dwoo instance yourself if you need it                                                                                       
      32                 :      *                                                                                                                                 
      33                 :      * @param Dwoo $dwoo the dwoo instance that runs this plugin                                                                       
      34                 :      */                                                                                                                                
      35                 :     public function __construct(Dwoo $dwoo)                                                                                            
      36                 :     {                                                                                                                                  
      37              30 :         $this->dwoo = $dwoo;                                                                                                           
      38              30 :     }                                                                                                                                  
      39                 :                                                                                                                                        
      40                 :     // plugins should always implement :                                                                                               
      41                 :     // public function process($arg, $arg, ...)                                                                                        
      42                 :     // or for block plugins :                                                                                                          
      43                 :     // public function init($arg, $arg, ...)                                                                                           
      44                 :                                                                                                                                        
      45                 :     // this could be enforced with :                                                                                                   
      46                 :     // abstract public function process(...);                                                                                          
      47                 :     // if my feature request gets enough interest one day                                                                              
      48                 :     // see => http://bugs.php.net/bug.php?id=44043                                                                                     
      49                 :                                                                                                                                        
      50                 :     /**                                                                                                                                
      51                 :      * utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes           
      52                 :      *                                                                                                                                 
      53                 :      * this is to be used in preProcessing or postProcessing functions, example :                                                      
      54                 :      *  $p = $compiler->getCompiledParams($params);                                                                                    
      55                 :      *  // get only the rest array as attributes                                                                                       
      56                 :      *  $attributes = Dwoo_Plugin::paramsToAttributes($p['*']);                                                                        
      57                 :      *  // get all the parameters as attributes (if there is a rest array, it will be included)                                        
      58                 :      *  $attributes = Dwoo_Plugin::paramsToAttributes($p);                                                                             
      59                 :      *                                                                                                                                 
      60                 :      * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string     
      61                 :      * @param string $delim the string delimiter you want to use (defaults to ')                                                       
      62                 :      * @return string                                                                                                                  
      63                 :      */                                                                                                                                
      64                 :     public static function paramsToAttributes(array $params, $delim = '\'')                                                            
      65                 :     {                                                                                                                                  
      66               1 :         if (isset($params['*'])) {                                                                                                     
      67               1 :             $params = array_merge($params, $params['*']);                                                                              
      68               1 :             unset($params['*']);                                                                                                       
      69               1 :         }                                                                                                                              
      70                 :                                                                                                                                        
      71               1 :         $out = '';                                                                                                                     
      72               1 :         foreach ($params as $attr=>$val) {                                                                                             
      73               1 :             $out .= ' '.$attr.'=';                                                                                                     
      74               1 :             if (trim($val, '"\'')=='' || $val=='null') {                                                                               
      75               0 :                 $out .= str_replace($delim, '\\'.$delim, '""');                                                                        
      76               1 :             } elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) {                                                  
      77               0 :                 $out .= str_replace($delim, '\\'.$delim, '"'.substr($val, 1, -1).'"');                                                 
      78               0 :             } else {                                                                                                                   
      79               1 :                 $out .= str_replace($delim, '\\'.$delim, '"') . $delim . '.'.$val.'.' . $delim . str_replace($delim, '\\'.$delim, '"');
      80                 :             }                                                                                                                          
      81               1 :         }                                                                                                                              
      82                 :                                                                                                                                        
      83               1 :         return ltrim($out);                                                                                                            
      84                 :     }                                                                                                                                  
      85                 : }                                                                                                                                      


Generated by PHPUnit @package_version@ and Xdebug 2.1.0beta2-dev using PHP 5.3.0 at Sun Feb 7 16:30:52 UTC 2010.