Location: PHPKode > projects > Breeze CMS - A PHP Content Manage System > libs/Ice/ClassLoader.class.php
<?php
define("DEFAULT_SOURCE_FILE_SUFFIX", ".class.php");

class Ice_ClassLoader
{
    var $_paths;
    var $_sourceFileSuffix;
    
    function Ice_ClassLoader($path =  array("./"), $sourceFileSuffix = DEFAULT_SOURCE_FILE_SUFFIX)
    {
        $this->_paths = $path;
        $this->_sourceFileSuffix = $sourceFileSuffix;
    }
    
    function getInstance($path = array())
    {
        static $instance;

        if($instance == null)
        {
            $instance = new Ice_ClassLoader();
        }

        if(is_array($path) && count($path))
        {
            /*
            foreach ($path as $p)
            {
                $instance->addSearchFolder($p);
            }
            */
            $instance->_paths = $path;
        }
        else if ($path != nul)
        {
            $instance->addSearchFolder($path);
        }
		
        return $instance;
    }
    
    function addSearchFolder($folder)
    {
        $this->_paths[] = $folder;
        return true;
    }
    
    function load($sourceName)
    {
        $i = 0;
        $loaded = false;
        
        $registry = Ice_Registry::getInstance();

        $num = count($this->_paths);
        while ($i < $num && !$loaded)
        {
        	$path = $this->_paths[$i];
        	$sourceFile = $registry->get('APP_DIR') . "/" . $path . "/" . str_replace("_", "/", $sourceName) . $this->_sourceFileSuffix;
        	if (file_exists($sourceFile))
        	{
        	    require_once($sourceFile);
        	    $loaded = true;
        	}
        	$i++;
        }
        
        if(!$loaded)
        {
            die( "Could not load \"$sourceFile\"!" );
        }
        
        return true;
    }
}
Return current item: Breeze CMS - A PHP Content Manage System