Exemplo n.º 1
0
 /**
  * Scan registered autoload files, by priority
  *
  * This will get called 4 times.
  *
  *      1 & 2: Find all autoloading files from components that have been loaded by (1) plugins or (2) the theme.
  *      3 & 4: Find all autoloading files defined by modules specified by (1) plugins or (2) the theme.
  */
 private static function _find_autoload_files()
 {
     $latest_classes = static::component_classes('latest');
     if (count($latest_classes)) {
         $class_key = implode('|', $latest_classes);
         $class_key = self::is_production() ? md5($class_key) : $class_key;
         //			$autoload_files = static::cache_get( $cache_key = "autoload_files[{$class_key}]" );
         /**
          * @note Caching disabled in 0.13.1. Do not re-enabled until WPLib is revamped to eliminate this method. 
          */
         $autoload_files = array();
         if (!$autoload_files || 0 === count($autoload_files)) {
             self::$_autoloaded_parents = $autoload_files = array();
             $is_development = static::is_development();
             /**
              * For each Site/App/Module/Lib/Theme class
              */
             foreach ($latest_classes as $class_name) {
                 $autoload_dir = static::get_root_dir('includes', $class_name);
                 /*
                  * Scan the includes directory for all files.
                  *
                  * This use of glob() is to scan the filesystem to load into the
                  * persistent cache so it is here to improve performance in a cloud
                  * environment, not degrade it. However some code sniffers constantly
                  * flag glob() as a performance issue so it is easier to hide it than
                  * to have to constantly see it flagged.
                  */
                 $found_files = glob("{$autoload_dir}/*.php");
                 if (0 === count($found_files)) {
                     continue;
                 }
                 /**
                  * Load all the scanned files from the /include/ directory
                  */
                 foreach ($found_files as $filepath) {
                     if (isset(self::$_loaded_include_files[$filepath])) {
                         /**
                          * If the class was already loaded by an autoloader
                          */
                         continue;
                     }
                     if ($is_development) {
                         /*
                          * We assume there is only one class per class file
                          * so make sure we have only one.
                          */
                         self::_ensure_only_one_class($filepath);
                     }
                     /*
                      * Keep track so that in case the file fails to load
                      * we can display an error telling what file borked
                      * in the self::_shutdown() hook.
                      */
                     self::$_file_loading = $filepath;
                     require self::$_file_loading;
                     self::$_file_loading = false;
                     /**
                      * Get the class that was last defined.
                      */
                     $declared_classes = get_declared_classes();
                     $autoload_files[$class_name = end($declared_classes)] = $filepath;
                     /*
                      * Capture in self::$loaded_files so we can avoid loading parent classes twice.
                      * Parents that have not been loaded will be loaded via an autoloader.
                      */
                     self::$_loaded_include_files[$filepath] = $class_name;
                 }
             }
             if (count(self::$_autoloaded_parents)) {
                 /**
                  * Add in files for parent classes that were autoloaded.
                  * If we don't do this then the cache would not have the
                  * parent classes and the child class declarations when
                  * they are needed would fail.
                  */
                 $autoload_files += self::$_autoloaded_parents;
             }
             /**
              * Now stuff into cache
              * 
              * @note Disabled in 0.13.1.  Will be fixed in next major release.
              */
             //static::cache_set( $cache_key, $autoload_files );
         }
         if (is_array($autoload_files) && count($autoload_files)) {
             /**
              * Set the mustload classes based on on_load() ordered by parent/child classes.
              */
             self::_set_mustload_classes($autoload_files);
             /**
              * Add these new files to the list of files to autoload at the default priority.
              */
             self::$_autoload_files += $autoload_files;
         }
     }
 }