<commit_before><?php
/**
 * @version 	$Id:factory.php 46 2008-03-01 18:39:32Z mjaz $
 * @category	Koowa
 * @package		Koowa_Factory
 * @copyright	Copyright (C) 2007 - 2009 <NAME> and <NAME>. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 */

//Initialise the factory
KFactory::initialize();

/**
 * KFactory class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Factory
 * @static
 */
class KFactory
{
	/**
	 * The object container
	 *
	 * @var	array
	 */
	protected static $_container = null;
	
	/**
	 * The commandchain
	 *
	 * @var	KLoaderChain
	 */
	protected static $_chain = null;
	
	/**
	 * Constructor
	 * 
	 * Prevent creating instances of this class by making the contructor private
	 */
	private function __construct() { }
	
	/**
	 * Initialize
	 * 
	 * @return void
	 */	
	public static function initialize()
	{
		//Created the object container
		self::$_container = new ArrayObject();
	
		//Create the command chain and register the adapters
        self::$_chain = new KFactoryChain();
        
        //Add the koowa adapter
        self::addAdapter(new KFactoryAdapterKoowa());
	}
	
	/**
	 * Get an instance of a class based on a class identifier only creating it
	 * if it doesn't exist yet.
	 *
	 * @param mixed  The class identifier
	 * @param array  An optional associative array of configuration settings.
	 * @throws KFactoryException
	 * @return object  Return object on success, throws exception on failure
	 */
	public static function get($identifier, array $options = array())
	{
		//Check if the object already exists
		if(self::$_container->offsetExists($identifier)) {
			return self::$_container->offsetGet($identifier);
		} 
		
		//Get an instance based on the identifier
		$instance = self::$_chain->run($identifier, $options);
		if(!is_object($instance)) {
			throw new KFactoryException('Cannot create object instance from identifier : '.$identifier);	
		}	
		
		self::$_container->offsetSet($identifier, $instance);
		return $instance;
	}
	
	/**
	 * Get an instance of a class based on a class identifier always creating a 
	 * new instance.
	 *
	 * @param mixed  The class identifier
	 * @param array  An optional associative array of configuration settings.
	 * @throws KFactoryException
	 * @return object  Return object on success, throws exception on failure
	 */
	public static function tmp($identifier, array $options = array())
	{
		//Get an instance based on the identifier
		$object = self::$_chain->run($identifier, $options);
		if($object === false) {
			throw new KFactoryException('Cannot create object from identifier : '.$identifier);	<commit_msg>Added is_object check<commit_after><?php
/**
 * @version 	$Id:factory.php 46 2008-03-01 18:39:32Z mjaz $
 * @category	Koowa
 * @package		Koowa_Factory
 * @copyright	Copyright (C) 2007 - 2009 <NAME> and <NAME>. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 */

//Initialise the factory
KFactory::initialize();

/**
 * KFactory class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Factory
 * @static
 */
class KFactory
{
	/**
	 * The object container
	 *
	 * @var	array
	 */
	protected static $_container = null;
	
	/**
	 * The commandchain
	 *
	 * @var	KLoaderChain
	 */
	protected static $_chain = null;
	
	/**
	 * Constructor
	 * 
	 * Prevent creating instances of this class by making the contructor private
	 */
	private function __construct() { }
	
	/**
	 * Initialize
	 * 
	 * @return void
	 */	
	public static function initialize()
	{
		//Created the object container
		self::$_container = new ArrayObject();
	
		//Create the command chain and register the adapters
        self::$_chain = new KFactoryChain();
        
        //Add the koowa adapter
        self::addAdapter(new KFactoryAdapterKoowa());
	}
	
	/**
	 * Get an instance of a class based on a class identifier only creating it
	 * if it doesn't exist yet.
	 *
	 * @param	string|object	The class identifier, or an object
	 * @param	array  			An optional associative array of configuration settings.
	 * @throws	KFactoryException
	 * @return	object  		Return object on success, throws exception on failure
	 */
	public static function get($identifier, array $options = array())
	{
		if(is_object($identifier)) {
			return $identifier;
		}
		
		//Check if the object already exists
		if(self::$_container->offsetExists($identifier)) {
			return self::$_container->offsetGet($identifier);
		} 
		
		//Get an instance based on the identifier
		$instance = self::$_chain->run($identifier, $options);
		if(!is_object($instance)) {
			throw new KFactoryException('Cannot create object instance from identifier : '.$identifier);	
		}	
		
		self::$_container->offsetSet($identifier, $instance);
		return $instance;
	}
	
	/**
	 * Get an instance of a class based on a class identifier always creating a 
	 * new instance.
	 *
	 * @param	string|object	The class identifier, or an object
	 * @param 	array  			An optional associative array of configuration settings.
	 * @throws 	KFactoryException
	 * @return 	object  		Return object on success, throws exception on failure
	 */
	public static function tmp($identifier, array $options = array())
	{
		if(is_object($identifier)) {
			return $identifier;
		}
		
		//Get an instance based on the identifier
		$object = self::$_chain->run($identifier, $options);
		if($object === false) {
			throw new KFactoryException('Cannot create object from identifier : '.$identifier);	
{'fraction_non_alphanumeric': 0.11626647409279653, 'fraction_numerical': 0.009749052175482938, 'mean_word_length': 3.410828025477707, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '6262150', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1545, 'n_words': 532}