protected function loadAppLibrary($class, $subdir, array $parameters = null, array $directories, $newInstance = false) 
	{
		// First check if the input is correct
		if (!is_array($directories)) 
		{
			throw new LibraryException("Could not load library. \$directory variable was not an array", 1);
		}

		// Search for the file
		foreach ($directories as $directory) 
		{
			// Skip the core directory
			if ($directory === Core::$coreDir . DS . 'Libraries')
			{
				continue;
			}

			// Determine the file
			$file = $directory . DS . $subdir . $class . '.php';
			$className = '\Application\Library\\'.$class;

			// Check if the file was already loaded
			if (class_exists($className, false)) 
			{
				// Return existing instance
				if (!isset($this->libraries[$className])) 
				{
					return $this->initLibrary($className, $parameters);
				}

				// If required to do so, return the existing instance or load a new one
				if ($newInstance)
				{
					$this->factory->logger->log("Library '".$className."' already loaded. Returning existing instance");
					return $this->libraries[$prefix.$class];	
				}

				$this->factory->logger->log("Library '".$className."' already loaded. Returning new instance");
				return $this->initLibrary($className, $parameters);
			}

			// Otherwise load the file first
			if (file_exists($file))
			{
				include_once($file);
				return $this->initLibrary($className, $parameters);
			}
		}

		// Maybe it's in a subdirectory with the same name as the class
		if ($subdir === '')
		{
			return $this->loadLibrary($class."/".$class, $parameters, $directories, $newInstance);
		}

		throw new LibraryException("Could not load library. Library was not found", 1);
	}
protected function loadAppLibrary($class, $subdir, array $parameters = null, array $directories, $newInstance = false) 
	{
		// First check if the input is correct
		if (!is_array($directories)) 
		{
			throw new LibraryException("Could not load library. \$directory variable was not an array", 1);
		}

		// Search for the file
		foreach ($directories as $directory) 
		{
			// Skip the core directory
			if ($directory === Core::$coreDir . DS . 'Libraries')
			{
				continue;
			}

			// Determine the file
			$file = $directory . DS . $subdir . $class . '.php';
			$className = '\Application\Library\\'.$class;

			// Check if the file was already loaded
			if (class_exists($className, false)) 
			{
				// Return existing instance
				if (!isset($this->libraries[$className])) 
				{
					return $this->initLibrary($className, $parameters);
				}

				// If required to do so, return the existing instance or load a new one
				if ($newInstance)
				{
					$this->factory->logger->log("Library '".$className."' already loaded. Returning existing instance");
					return $this->libraries[$prefix.$class];	
				}

				$this->factory->logger->log("Library '".$className."' already loaded. Returning new instance");
				return $this->initLibrary($className, $parameters);
			}

			// Otherwise load the file first
			if (file_exists($file))
			{
				include_once($file);
				return $this->initLibrary($className, $parameters);
			}
		}

		// Maybe it's in a subdirectory with the same name as the class
		if ($subdir === '')
		{
			return $this->loadLibrary($class."/".$class, $parameters, $directories, $newInstance);
		}

		throw new LibraryException("Could not load library. Library was not found", 1);
	}
protected function loadAppLibrary ( $ class , $ subdir , array $ parameters = null , array $ directories , $ newInstance = false ) { // First check if the input is correct if ( ! is_array ( $ directories ) ) { throw new LibraryException ( "Could not load library. \$directory variable was not an array" , 1 ) ; } // Search for the file foreach ( $ directories as $ directory ) { // Skip the core directory if ( $ directory === Core :: $ coreDir . DS . 'Libraries' ) { continue ; } // Determine the file $ file = $ directory . DS . $ subdir . $ class . '.php' ; $ className = '\Application\Library\\' . $ class ; // Check if the file was already loaded if ( class_exists ( $ className , false ) ) { // Return existing instance if ( ! isset ( $ this -> libraries [ $ className ] ) ) { return $ this -> initLibrary ( $ className , $ parameters ) ; } // If required to do so, return the existing instance or load a new one if ( $ newInstance ) { $ this -> factory -> logger -> log ( "Library '" . $ className . "' already loaded. Returning existing instance" ) ; return $ this -> libraries [ $ prefix . $ class ] ; } $ this -> factory -> logger -> log ( "Library '" . $ className . "' already loaded. Returning new instance" ) ; return $ this -> initLibrary ( $ className , $ parameters ) ; } // Otherwise load the file first if ( file_exists ( $ file ) ) { include_once ( $ file ) ; return $ this -> initLibrary ( $ className , $ parameters ) ; } } // Maybe it's in a subdirectory with the same name as the class if ( $ subdir === '' ) { return $ this -> loadLibrary ( $ class . "/" . $ class , $ parameters , $ directories , $ newInstance ) ; } throw new LibraryException ( "Could not load library. Library was not found" , 1 ) ; }
Application Library Loader

Loads, instantiates and returns an application library.
Could possibly extend a core library if requested.

@param	string	$class			Classname
@param   string 	$subdir 		Sub directory in which the final class can be found
@param	array	$params			Optional parameters to pass to the library class constructor
@param	array	$directory 		Optional list of directories where the library can be found. Overrides default list
@param   bool 	$newInstance 	Whether to return a new instance of the library or the same one
@return	object
@throws 	LibraryException
Application Library Loader