Exemplo n.º 1
0
 /**
  * Provides auto loading feature. To be used with the Magic method __autoload
  * @param string $classname Class name to be loaded.
  */
 public static function autoload($classname)
 {
     //        if( class_exists($classname, false) === true )
     //			return;
     //app
     $class['DooConfig'] = 'app/DooConfig';
     $class['DooSiteMagic'] = 'app/DooSiteMagic';
     $class['DooWebApp'] = 'app/DooWebApp';
     //auth
     $class['DooAcl'] = 'auth/DooAcl';
     $class['DooAuth'] = 'auth/DooAuth';
     $class['DooDigestAuth'] = 'auth/DooDigestAuth';
     $class['DooRbAcl'] = 'auth/DooRbAcl';
     //cache
     $class['DooApcCache'] = 'cache/DooApcCache';
     $class['DooEAcceleratorCache'] = 'cache/DooEAcceleratorCache';
     $class['DooFileCache'] = 'cache/DooFileCache';
     $class['DooFrontCache'] = 'cache/DooFrontCache';
     $class['DooMemCache'] = 'cache/DooMemCache';
     $class['DooPhpCache'] = 'cache/DooPhpCache';
     $class['DooXCache'] = 'cache/DooXCache';
     //controller
     $class['DooController'] = 'controller/DooController';
     //db
     $class['DooDbExpression'] = 'db/DooDbExpression';
     $class['DooMasterSlave'] = 'db/DooMasterSlave';
     $class['DooModel'] = 'db/DooModel';
     $class['DooModelGen'] = 'db/DooModelGen';
     $class['DooSmartModel'] = 'db/DooSmartModel';
     $class['DooSqlMagic'] = 'db/DooSqlMagic';
     //db/manage
     $class['DooDbUpdater'] = 'db/manage/DooDbUpdater';
     $class['DooManageDb'] = 'db/manage/DooManageDb';
     $class['DooManageMySqlDb'] = 'db/manage/adapters/DooManageMySqlDb';
     $class['DooManagePgSqlDb'] = 'db/manage/adapters/DooManagePgSqlDb';
     $class['DooManageSqliteDb'] = 'db/manage/adapters/DooManageSqliteDb';
     //helper
     $class['DooBenchmark'] = 'helper/DooBenchmark';
     $class['DooFile'] = 'helper/DooFile';
     $class['DooFlashMessenger'] = 'helper/DooFlashMessenger';
     $class['DooForm'] = 'helper/DooForm';
     $class['DooGdImage'] = 'helper/DooGdImage';
     $class['DooMailer'] = 'helper/DooMailer';
     $class['DooPager'] = 'helper/DooPager';
     $class['DooRestClient'] = 'helper/DooRestClient';
     $class['DooTextHelper'] = 'helper/DooTextHelper';
     $class['DooTimezone'] = 'helper/DooTimezone';
     $class['DooUrlBuilder'] = 'helper/DooUrlBuilder';
     $class['DooValidator'] = 'helper/DooValidator';
     //logging
     $class['DooLog'] = 'logging/DooLog';
     //session
     $class['DooCacheSession'] = 'session/DooCacheSession';
     $class['DooSession'] = 'session/DooSession';
     //translate
     $class['DooTranslator'] = 'translate/DooTranslator';
     //uri
     $class['DooLoader'] = 'uri/DooLoader';
     $class['DooUriRouter'] = 'uri/DooUriRouter';
     //view
     $class['DooView'] = 'uri/DooView';
     $class['DooViewBasic'] = 'uri/DooViewBasic';
     if (isset($class[$classname])) {
         self::loadCore($class[$classname]);
     } else {
         if (isset(Doo::conf()->PROTECTED_FOLDER_ORI) === true) {
             $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER_ORI;
         } else {
             $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER;
         }
         if (empty(Doo::conf()->AUTOLOAD) === false) {
             if (Doo::conf()->APP_MODE == 'dev') {
                 $includeSub = Doo::conf()->AUTOLOAD;
                 $rs = array();
                 foreach ($includeSub as $sub) {
                     if (file_exists($sub) === false) {
                         if (file_exists($path . $sub) === true) {
                             $rs = array_merge($rs, DooFile::getFilePathList($path . $sub . '/'));
                         }
                     } else {
                         $rs = array_merge($rs, DooFile::getFilePathList($sub . '/'));
                     }
                 }
                 $autoloadConfigFolder = $path . 'config/autoload/';
                 $rsExisting = null;
                 if (file_exists($autoloadConfigFolder . 'autoload.php') === true) {
                     $rsExisting = (include $autoloadConfigFolder . 'autoload.php');
                 }
                 if ($rs != $rsExisting) {
                     if (!file_exists($autoloadConfigFolder)) {
                         mkdir($autoloadConfigFolder);
                     }
                     file_put_contents($autoloadConfigFolder . 'autoload.php', '<?php return ' . var_export($rs, true) . ';');
                 }
             } else {
                 $rs = (include_once $path . 'config/autoload/autoload.php');
             }
             if (isset($rs[$classname . '.php']) === true) {
                 require_once $rs[$classname . '.php'];
                 return;
             }
         }
         //autoloading namespaced class
         if (isset(Doo::conf()->APP_NAMESPACE_ID) === true && strpos($classname, '\\') !== false) {
             $pos = strpos($classname, Doo::conf()->APP_NAMESPACE_ID);
             if ($pos === 0) {
                 $classname = str_replace('\\', '/', substr($classname, strlen(Doo::conf()->APP_NAMESPACE_ID) + 1));
                 require_once $path . $classname . '.php';
             }
         }
     }
 }