Current file: htdocs/lib/Varien/Autoload.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 8 CRAP
8.47%8.47%
8.47% 5 / 59
 
Varien_Autoload
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 8
8.47%8.47%
8.47% 5 / 59
 __construct()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 7
 instance()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 register()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 autoload($class)
0.00%0.00%
0.00% 0 / 1 3.79
55.56%55.56%
55.56% 5 / 9
 registerScope($code)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 5
 getScope()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 __destruct()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 _saveCollectedStat()
0.00%0.00%
0.00% 0 / 1 72
0.00%0.00%
0.00% 0 / 27


       1                 : <?php                                                                                                  
       2                 : /**                                                                                                    
       3                 :  * Magento                                                                                             
       4                 :  *                                                                                                     
       5                 :  * NOTICE OF LICENSE                                                                                   
       6                 :  *                                                                                                     
       7                 :  * This source file is subject to the Open Software License (OSL 3.0)                                  
       8                 :  * that is bundled with this package in the file LICENSE.txt.                                          
       9                 :  * It is also available through the world-wide-web at this URL:                                        
      10                 :  * http://opensource.org/licenses/osl-3.0.php                                                          
      11                 :  * If you did not receive a copy of the license and are unable to                                      
      12                 :  * obtain it through the world-wide-web, please send an email                                          
      13                 :  * to license@magentocommerce.com so we can send you a copy immediately.                               
      14                 :  *                                                                                                     
      15                 :  * DISCLAIMER                                                                                          
      16                 :  *                                                                                                     
      17                 :  * Do not edit or add to this file if you wish to upgrade Magento to newer                             
      18                 :  * versions in the future. If you wish to customize Magento for your                                   
      19                 :  * needs please refer to http://www.magentocommerce.com for more information.                          
      20                 :  *                                                                                                     
      21                 :  * @category   Varien                                                                                  
      22                 :  * @package    Varien_Autoload                                                                         
      23                 :  * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)            
      24                 :  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)             
      25                 :  */                                                                                                    
      26                 :                                                                                                        
      27                 : /**                                                                                                    
      28                 :  * Classes source autoload                                                                             
      29                 :  */                                                                                                    
      30                 : class Varien_Autoload                                                                                  
      31                 : {                                                                                                      
      32                 :     const SCOPE_FILE_PREFIX = '__';                                                                    
      33                 :                                                                                                        
      34                 :     static protected $_instance;                                                                       
      35                 :     static protected $_scope = 'default';                                                              
      36                 :                                                                                                        
      37                 :     protected $_isIncludePathDefined= null;                                                            
      38                 :     protected $_collectClasses      = false;                                                           
      39                 :     protected $_collectPath         = null;                                                            
      40                 :     protected $_arrLoadedClasses    = array();                                                         
      41                 :                                                                                                        
      42                 :     /**                                                                                                
      43                 :      * Class constructor                                                                               
      44                 :      */                                                                                                
      45                 :     public function __construct()                                                                      
      46                 :     {                                                                                                  
      47               0 :         $this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');                               
      48               0 :         if (defined('COMPILER_COLLECT_PATH')) {                                                        
      49               0 :             $this->_collectClasses  = true;                                                            
      50               0 :             $this->_collectPath     = COMPILER_COLLECT_PATH;                                           
      51               0 :         }                                                                                              
      52               0 :         self::registerScope(self::$_scope);                                                            
      53               0 :     }                                                                                                  
      54                 :                                                                                                        
      55                 :     /**                                                                                                
      56                 :      * Singleton pattern implementation                                                                
      57                 :      *                                                                                                 
      58                 :      * @return Varien_Autoload                                                                         
      59                 :      */                                                                                                
      60                 :     static public function instance()                                                                  
      61                 :     {                                                                                                  
      62               0 :         if (!self::$_instance) {                                                                       
      63               0 :             self::$_instance = new Varien_Autoload();                                                  
      64               0 :         }                                                                                              
      65               0 :         return self::$_instance;                                                                       
      66                 :     }                                                                                                  
      67                 :                                                                                                        
      68                 :     /**                                                                                                
      69                 :      * Register SPL autoload function                                                                  
      70                 :      */                                                                                                
      71                 :     static public function register()                                                                  
      72                 :     {                                                                                                  
      73               0 :         spl_autoload_register(array(self::instance(), 'autoload'));                                    
      74               0 :     }                                                                                                  
      75                 :                                                                                                        
      76                 :     /**                                                                                                
      77                 :      * Load class source code                                                                          
      78                 :      *                                                                                                 
      79                 :      * @param string $class                                                                            
      80                 :      */                                                                                                
      81                 :     public function autoload($class)                                                                   
      82                 :     {                                                                                                  
      83               4 :         if ($this->_collectClasses) {                                                                  
      84               0 :             $this->_arrLoadedClasses[self::$_scope][] = $class;                                        
      85               0 :         }                                                                                              
      86               4 :         if ($this->_isIncludePathDefined) {                                                            
      87               0 :             $classFile = $class;                                                                       
      88               0 :         } else {                                                                                       
      89               4 :             $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
      90                 :         }                                                                                              
      91               4 :         $classFile.= '.php';                                                                           
      92                 :         //echo $classFile;die();                                                                       
      93               4 :         return include $classFile;                                                                     
      94                 :     }                                                                                                  
      95                 :                                                                                                        
      96                 :     /**                                                                                                
      97                 :      * Register autoload scope                                                                         
      98                 :      * This process allow include scope file which can contain classes                                 
      99                 :      * definition which are used for this scope                                                        
     100                 :      *                                                                                                 
     101                 :      * @param string $code scope code                                                                  
     102                 :      */                                                                                                
     103                 :     static public function registerScope($code)                                                        
     104                 :     {                                                                                                  
     105               0 :         self::$_scope = $code;                                                                         
     106               0 :         if (defined('COMPILER_INCLUDE_PATH')) {                                                        
     107               0 :             @include_once self::SCOPE_FILE_PREFIX.$code.'.php';                                        
     108               0 :         }                                                                                              
     109               0 :     }                                                                                                  
     110                 :                                                                                                        
     111                 :     /**                                                                                                
     112                 :      * Get current autoload scope                                                                      
     113                 :      *                                                                                                 
     114                 :      * @return string                                                                                  
     115                 :      */                                                                                                
     116                 :     static public function getScope()                                                                  
     117                 :     {                                                                                                  
     118               0 :         return self::$_scope;                                                                          
     119                 :     }                                                                                                  
     120                 :                                                                                                        
     121                 :     /**                                                                                                
     122                 :      * Class destructor                                                                                
     123                 :      */                                                                                                
     124                 :     public function __destruct()                                                                       
     125                 :     {                                                                                                  
     126               0 :         if ($this->_collectClasses) {                                                                  
     127               0 :             $this->_saveCollectedStat();                                                               
     128               0 :         }                                                                                              
     129               0 :     }                                                                                                  
     130                 :                                                                                                        
     131                 :     /**                                                                                                
     132                 :      * Save information about used classes per scope with class popularity                             
     133                 :      * Class_Name:popularity                                                                           
     134                 :      *                                                                                                 
     135                 :      * @return Varien_Autoload                                                                         
     136                 :      */                                                                                                
     137                 :     protected function _saveCollectedStat()                                                            
     138                 :     {                                                                                                  
     139               0 :         if (!is_dir($this->_collectPath)) {                                                            
     140               0 :             @mkdir($this->_collectPath);                                                               
     141               0 :             @chmod($this->_collectPath, 0777);                                                         
     142               0 :         }                                                                                              
     143                 :                                                                                                        
     144               0 :         if (!is_writeable($this->_collectPath)) {                                                      
     145               0 :             return $this;                                                                              
     146                 :         }                                                                                              
     147                 :                                                                                                        
     148               0 :         foreach ($this->_arrLoadedClasses as $scope => $classes) {                                     
     149               0 :             $file = $this->_collectPath.DIRECTORY_SEPARATOR.$scope.'.csv';                             
     150               0 :             $data = array();                                                                           
     151               0 :             if (file_exists($file)) {                                                                  
     152               0 :                 $data = explode("\n", file_get_contents($file));                                       
     153               0 :                 foreach ($data as $index => $class) {                                                  
     154               0 :                     $class = explode(':', $class);                                                     
     155               0 :                     $searchIndex = array_search($class[0], $classes);                                  
     156               0 :                     if ($searchIndex !== false) {                                                      
     157               0 :                         $class[1]+=1;                                                                  
     158               0 :                         unset($classes[$searchIndex]);                                                 
     159               0 :                     }                                                                                  
     160               0 :                     $data[$index] = $class[0].':'.$class[1];                                           
     161               0 :                 }                                                                                      
     162               0 :             }                                                                                          
     163               0 :             foreach ($classes as $class) {                                                             
     164               0 :                 $data[] = $class . ':1';                                                               
     165               0 :             }                                                                                          
     166               0 :             file_put_contents($file, implode("\n", $data));                                            
     167               0 :         }                                                                                              
     168               0 :         return $this;                                                                                  
     169                 :     }                                                                                                  
     170                 : }                                                                                                      

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.4 and PHPUnit 3.5.13 at Tue Jul 5 9:07:16 UTC 2011.