<commit_before><?php

namespace mako
{
	/**
	* Classloader.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2012 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class ClassLoader
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Mapping from class names to paths.
		*/

		protected static $classes = array();
		
		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Protected constructor since this is a static class.
		*
		* @access  protected
		*/

		protected function __construct()
		{
			// Nothing here
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Add class to mapping.
		*
		* @access  public
		* @param   string  Class name
		* @param   string  Full path to class
		*/

		public static function addClass($className, $classPath)
		{
			static::$classes[$className] = $classPath;
		}

		/**
		* Add multiple classes to mapping.
		*
		* @access  public
		* @param   array   Array of classes to map (key = class name and value = class path)
		*/

		public static function addClasses(array $classes)
		{
			foreach($classes as $name => $path)
			{
				static::$classes[$name] = $path;
			}
		}

		/**
		* Load a class that has been mapped.
		*
		* @access  public
		* @param   string   Class name
		* @return  boolean
		*/

		public static function load($className)
		{
			if(isset(static::$classes[$className]))
			{
				if(file_exists(static::$classes[$className]))
				{
					include static::$classes[$className];

					return true;
				}
			}

			return false;
		}

		/**
		* Autoloader.
		*
		* @access  public
		* @param   string   Class name
		* @return  boolean
		*/

		public static function autoLoad($className)
		{
			// Try to load a mapped class

			if(static::load($className))
			{
				return true;
			}

			// Try to load an application class

			$fileName = MAKO_APPLICATION_PATH . '/' . str_replace('\\', '/', mb_strtolower($className)) . '.php';

			if(file_exists($fileName))
			{
				include $fileName;

				return true;
			}

			// Try to load class from a PSR-0 compatible library

			$className = ltrim($className, '\\');

			$fileName  = '';
			$namespace = '';

			if($lastNsPos = strripos($className, '\\'))
			{
				$namespace = substr($className, 0, $lastNsPos);
				$className = substr($className, $lastNsPos + 1);
				$fileName  = str_replace('\\', '/', $namespace) . '/';
			}

			$fileName .= str_replace('_', '/', $className) . '.php';

			if(file_exists(MAKO_LIBRARIES_PATH . '/' . $fileName))
			{
				include(MAKO_LIBRARIES_PATH . '/' . $fileName);

				return true;
			}

			return false;
		}
	}
}
<commit_msg>One can now add PSR-0 directories to the autoloader<commit_after><?php

namespace mako
{
	/**
	* Classloader.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2012 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class ClassLoader
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Mapping from class names to paths.
		*/

		protected static $classes = array();

		/**
		* PSR-0 directories.
		*/

		protected static $psr0 = array
		(
			MAKO_LIBRARIES_PATH
		);
		
		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Protected constructor since this is a static class.
		*
		* @access  protected
		*/

		protected function __construct()
		{
			// Nothing here
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Add class to mapping.
		*
		* @access  public
		* @param   string  Class name
		* @param   string  Full path to class
		*/

		public static function addClass($className, $classPath)
		{
			static::$classes[$className] = $classPath;
		}

		/**
		* Add multiple classes to mapping.
		*
		* @access  public
		* @param   array   Array of classes to map (key = class name and value = class path)
		*/

		public static function addClasses(array $classes)
		{
			foreach($classes as $name => $path)
			{
				static::$classes[$name] = $path;
			}
		}

		/**
		* Adds a PSR-0 directory path.
		*
		* @access  public
		* @param   string  Path to PSR-0 directory
		*/

		public static function addPsr0($path)
		{
			static::$psr0[] = $path;
		}

		/**
		* Autoloader.
		*
		* @access  public
		* @param   string   Class name
		* @return  boolean
		*/

		public static function autoLoad($className)
		{
			// Try to load a mapped class

			if(isset(static::$classes[$className]))
			{
				if(file_exists(static::$classes[$className]))
				{
					include static::$classes[$className];

					return true;
				}
			}

			// Try to load an application class

			$fileName = MAKO_APPLICATION_PATH . '/' . str_replace('\\', '/', mb_strtolower($className)) . '.php';

			if(file_exists($fileName))
			{
				include $fileName;

				return true;
			}

			// Try to load class from a PSR-0 compatible library

			$className = ltrim($className, '\\');

			$fileName  = '';
			$namespace = '';

			if($lastNsPos = strripos($className, '\\'))
			{
				$namespace = substr($className, 0, $lastNsPos);
				$className = substr($className, $lastNsPos + 1);
				$fileName  = str_replace('\\', '/', $namespace) . '/';
			}

			$fileName .= str_replace('_', '/', $className) . '.php';

			foreach(static::$psr0 as $path)
			{
				if(file_exists($path . '/' . $fileName))
				{
					include($path . '/' . $fileName);

					return true;
				}	
			}

			return false;
		}
	}
}

{'fraction_non_alphanumeric': 0.23253803596127248, 'fraction_numerical': 0.005186721991701245, 'mean_word_length': 1.7666188426590148, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6176572', 'n_tokens_mistral': 2179, 'n_tokens_neox': 1776, 'n_words': 423}