<commit_before><?php

namespace Princeton\App\Injection;

use Princeton\App\Exceptions\DependencyException;

/**
 * Typical usage:
 * 	StandardDependencyManager::register(); // ... or some other, app-specific subclass.
 * 	...
 * 	trait Foo {
 * 		protected function getFoo() {
 * 			DependencyManager::get('foo');
 * 		}
 * 	}
 */
class DependencyManager
{
	private static $manager;
	
	private $rules = array();
	private $default;

	/**
	 * Creates and registers an instance of the calling class as the default dependency manager,
	 * which will be used by DependencyManager::get($name).  This should normally be called only once.
	 * Use $force=true to override.
	 * 
	 * @param $force Whether to allow this to replace an already existing default manager.
	 * 
	 * @throws \Princeton\App\Exceptions\DependencyException
	 */
	public static function register($force = false)
	{
		if (isset(self::$manager)) {
			throw new DependencyException('Dependency Manager already registered!');
		}
		$class = get_called_class();
		self::$manager = new $class;
	}
	
	/**
	 * Gets the dependency object associated with $name.
	 * 
	 * @param unknown $name
	 */
	public static function get($name)
	{
		return self::$manager->inject($name);
	}
	
	/**
	 * To override the registered manager, explicitly create a new manager and use its inject() method to retrieve objects.
	 * Calling $manager->inject($name) is just like calling DependencyManager::get($name), only it uses $manager's ruleset<commit_msg>Fix force-re-registration flag<commit_after><?php

namespace Princeton\App\Injection;

use Princeton\App\Exceptions\DependencyException;

/**
 * Typical usage:
 * 	StandardDependencyManager::register(); // ... or some other, app-specific subclass.
 * 	...
 * 	trait Foo {
 * 		protected function getFoo() {
 * 			DependencyManager::get('foo');
 * 		}
 * 	}
 */
class DependencyManager
{
	private static $manager;
	
	private $rules = array();
	private $default;

	/**
	 * Creates and registers an instance of the calling class as the default dependency manager,
	 * which will be used by DependencyManager::get($name).  This should normally be called only once.
	 * Use $force=true to override.
	 * 
	 * @param $force Whether to allow this to replace an already existing default manager.
	 * 
	 * @throws \Princeton\App\Exceptions\DependencyException
	 */
	public static function register($force = false)
	{
		if (isset(self::$manager) && $force == false) {
			throw new DependencyException('Dependency Manager already registered!');
		}
		$class = get_called_class();
		self::$manager = new $class;
	}
	
	/**
	 * Gets the dependency object associated with $name.
	 * 
	 * @param unknown $name
	 */
	public static function get($name)
	{
		return self::$manager->inject($name);
	}
	
	/**
	 * To override the registered manager, explicitly create a new manager and use its inject() method to retrieve objects.
	 * Calling $manager->inject($name) is just like calling DependencyManager::get($name), only it uses $manager's ruleset
{'fraction_non_alphanumeric': 0.11969496021220159, 'fraction_numerical': 0.0, 'mean_word_length': 3.8897893030794166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6797317', 'n_tokens_mistral': 908, 'n_tokens_neox': 826, 'n_words': 281}