public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
    {
        // each $name can only be loaded once per PHP process
        if (isset(self::$loaded[$name])) {
            return;
        }

        self::$loaded[$name] = true;

        if ($adaptive) {
            $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());

            // don't include already declared classes
            $classes = array_diff($classes, $declared);

            // the cache is different depending on which classes are already declared
            $name = $name.'-'.substr(hash('sha256', implode('|', $classes)), 0, 5);
        }

        $classes = array_unique($classes);

        // cache the core classes
        if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
            throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
        }
        $cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
        $cache = $cacheDir.'/'.$name.$extension;

        // auto-reload
        $reload = false;
        if ($autoReload) {
            $metadata = $cache.'.meta';
            if (!is_file($metadata) || !is_file($cache)) {
                $reload = true;
            } else {
                $time = filemtime($cache);
                $meta = unserialize(file_get_contents($metadata));

                sort($meta[1]);
                sort($classes);

                if ($meta[1] != $classes) {
                    $reload = true;
                } else {
                    foreach ($meta[0] as $resource) {
                        if (!is_file($resource) || filemtime($resource) > $time) {
                            $reload = true;

                            break;
                        }
                    }
                }
            }
        }

        if (!$reload && file_exists($cache)) {
            require_once $cache;

            return;
        }
        if (!$adaptive) {
            $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
        }

        $files = self::inline($classes, $cache, $declared);

        if ($autoReload) {
            // save the resources
            self::writeCacheFile($metadata, serialize(array(array_values($files), $classes)));
        }
    }
public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
    {
        // each $name can only be loaded once per PHP process
        if (isset(self::$loaded[$name])) {
            return;
        }

        self::$loaded[$name] = true;

        if ($adaptive) {
            $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());

            // don't include already declared classes
            $classes = array_diff($classes, $declared);

            // the cache is different depending on which classes are already declared
            $name = $name.'-'.substr(hash('sha256', implode('|', $classes)), 0, 5);
        }

        $classes = array_unique($classes);

        // cache the core classes
        if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
            throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
        }
        $cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
        $cache = $cacheDir.'/'.$name.$extension;

        // auto-reload
        $reload = false;
        if ($autoReload) {
            $metadata = $cache.'.meta';
            if (!is_file($metadata) || !is_file($cache)) {
                $reload = true;
            } else {
                $time = filemtime($cache);
                $meta = unserialize(file_get_contents($metadata));

                sort($meta[1]);
                sort($classes);

                if ($meta[1] != $classes) {
                    $reload = true;
                } else {
                    foreach ($meta[0] as $resource) {
                        if (!is_file($resource) || filemtime($resource) > $time) {
                            $reload = true;

                            break;
                        }
                    }
                }
            }
        }

        if (!$reload && file_exists($cache)) {
            require_once $cache;

            return;
        }
        if (!$adaptive) {
            $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
        }

        $files = self::inline($classes, $cache, $declared);

        if ($autoReload) {
            // save the resources
            self::writeCacheFile($metadata, serialize(array(array_values($files), $classes)));
        }
    }
public static function load ( $ classes , $ cacheDir , $ name , $ autoReload , $ adaptive = false , $ extension = '.php' ) { // each $name can only be loaded once per PHP process if ( isset ( self :: $ loaded [ $ name ] ) ) { return ; } self :: $ loaded [ $ name ] = true ; if ( $ adaptive ) { $ declared = array_merge ( get_declared_classes ( ) , get_declared_interfaces ( ) , get_declared_traits ( ) ) ; // don't include already declared classes $ classes = array_diff ( $ classes , $ declared ) ; // the cache is different depending on which classes are already declared $ name = $ name . '-' . substr ( hash ( 'sha256' , implode ( '|' , $ classes ) ) , 0 , 5 ) ; } $ classes = array_unique ( $ classes ) ; // cache the core classes if ( ! is_dir ( $ cacheDir ) && ! @ mkdir ( $ cacheDir , 0777 , true ) && ! is_dir ( $ cacheDir ) ) { throw new \ RuntimeException ( sprintf ( 'Class Collection Loader was not able to create directory "%s"' , $ cacheDir ) ) ; } $ cacheDir = rtrim ( realpath ( $ cacheDir ) ? : $ cacheDir , '/' . DIRECTORY_SEPARATOR ) ; $ cache = $ cacheDir . '/' . $ name . $ extension ; // auto-reload $ reload = false ; if ( $ autoReload ) { $ metadata = $ cache . '.meta' ; if ( ! is_file ( $ metadata ) || ! is_file ( $ cache ) ) { $ reload = true ; } else { $ time = filemtime ( $ cache ) ; $ meta = unserialize ( file_get_contents ( $ metadata ) ) ; sort ( $ meta [ 1 ] ) ; sort ( $ classes ) ; if ( $ meta [ 1 ] != $ classes ) { $ reload = true ; } else { foreach ( $ meta [ 0 ] as $ resource ) { if ( ! is_file ( $ resource ) || filemtime ( $ resource ) > $ time ) { $ reload = true ; break ; } } } } } if ( ! $ reload && file_exists ( $ cache ) ) { require_once $ cache ; return ; } if ( ! $ adaptive ) { $ declared = array_merge ( get_declared_classes ( ) , get_declared_interfaces ( ) , get_declared_traits ( ) ) ; } $ files = self :: inline ( $ classes , $ cache , $ declared ) ; if ( $ autoReload ) { // save the resources self :: writeCacheFile ( $ metadata , serialize ( array ( array_values ( $ files ) , $ classes ) ) ) ; } }
Loads a list of classes and caches them in one big file.

@param array  $classes    An array of classes to load
@param string $cacheDir   A cache directory
@param string $name       The cache name prefix
@param bool   $autoReload Whether to flush the cache when the cache is stale or not
@param bool   $adaptive   Whether to remove already declared classes or not
@param string $extension  File extension of the resulting file

@throws \InvalidArgumentException When class can't be loaded
Loads a list of classes and caches them in one big file .