Varien_Autoload Class Reference

List of all members.

Public Member Functions

 __construct ()
 autoload ($class)
 __destruct ()

Static Public Member Functions

static instance ()
static register ()
static registerScope ($code)
static getScope ()

Public Attributes

const SCOPE_FILE_PREFIX = '__'

Protected Member Functions

 _saveCollectedStat ()

Protected Attributes

 $_isIncludePathDefined = null
 $_collectClasses = false
 $_collectPath = null
 $_arrLoadedClasses = array()

Static Protected Attributes

static $_instance
static $_scope = 'default'


Detailed Description

Classes source autoload

Definition at line 30 of file Autoload.php.


Constructor & Destructor Documentation

__construct (  ) 

Class constructor

Definition at line 45 of file Autoload.php.

00046     {
00047         $this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');
00048         if (defined('COMPILER_COLLECT_PATH')) {
00049             $this->_collectClasses  = true;
00050             $this->_collectPath     = COMPILER_COLLECT_PATH;
00051         }
00052         self::registerScope(self::$_scope);
00053     }

__destruct (  ) 

Class destructor

Definition at line 122 of file Autoload.php.

00123     {
00124         if ($this->_collectClasses) {
00125             $this->_saveCollectedStat();
00126         }
00127     }


Member Function Documentation

_saveCollectedStat (  )  [protected]

Save information about used classes per scope with class popularity Class_Name:popularity

Returns:
Varien_Autoload

Definition at line 135 of file Autoload.php.

00136     {
00137         if (!is_dir($this->_collectPath)) {
00138             @mkdir($this->_collectPath);
00139             @chmod($this->_collectPath, 0777);
00140         }
00141 
00142         if (!is_writeable($this->_collectPath)) {
00143             return $this;
00144         }
00145 
00146         foreach ($this->_arrLoadedClasses as $scope => $classes) {
00147             $file = $this->_collectPath.DIRECTORY_SEPARATOR.$scope.'.csv';
00148             $data = array();
00149             if (file_exists($file)) {
00150                 $data = explode("\n", file_get_contents($file));
00151                 foreach ($data as $index => $class) {
00152                     $class = explode(':', $class);
00153                     $searchIndex = array_search($class[0], $classes);
00154                     if ($searchIndex !== false) {
00155                         $class[1]+=1;
00156                         unset($classes[$searchIndex]);
00157                     }
00158                     $data[$index] = $class[0].':'.$class[1];
00159                 }
00160             }
00161             foreach ($classes as $class) {
00162                 $data[] = $class . ':1';
00163             }
00164             file_put_contents($file, implode("\n", $data));
00165         }
00166         return $this;
00167     }

autoload ( class  ) 

Load class source code

Parameters:
string $class

Definition at line 81 of file Autoload.php.

00082     {
00083         if ($this->_collectClasses) {
00084             $this->_arrLoadedClasses[self::$_scope][] = $class;
00085         }
00086         if ($this->_isIncludePathDefined) {
00087             $classFile = $class;
00088         } else {
00089             $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
00090         }
00091         $classFile.= '.php';
00092         //echo $classFile;die();
00093         return include $classFile;
00094     }

static getScope (  )  [static]

Get current autoload scope

Returns:
string

Definition at line 114 of file Autoload.php.

00115     {
00116         return self::$_scope;
00117     }

static instance (  )  [static]

Singleton pattern implementation

Returns:
Varien_Autoload

Definition at line 60 of file Autoload.php.

00061     {
00062         if (!self::$_instance) {
00063             self::$_instance = new Varien_Autoload();
00064         }
00065         return self::$_instance;
00066     }

static register (  )  [static]

Register SPL autoload function

Definition at line 71 of file Autoload.php.

00072     {
00073         spl_autoload_register(array(self::instance(), 'autoload'));
00074     }

static registerScope ( code  )  [static]

Register autoload scope This process allow include scope file which can contain classes definition which are used for this scope

Parameters:
string $code scope code

Definition at line 103 of file Autoload.php.

00104     {
00105         self::$_scope = $code;
00106         @include self::SCOPE_FILE_PREFIX.$code.'.php';
00107     }


Member Data Documentation

$_arrLoadedClasses = array() [protected]

Definition at line 40 of file Autoload.php.

$_collectClasses = false [protected]

Definition at line 38 of file Autoload.php.

$_collectPath = null [protected]

Definition at line 39 of file Autoload.php.

$_instance [static, protected]

Definition at line 34 of file Autoload.php.

$_isIncludePathDefined = null [protected]

Definition at line 37 of file Autoload.php.

$_scope = 'default' [static, protected]

Definition at line 35 of file Autoload.php.

const SCOPE_FILE_PREFIX = '__'

Definition at line 32 of file Autoload.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:57 2009 for Magento by  doxygen 1.5.8