<commit_before><?php
namespace Exedra\Application;

class Di
{
	private $storage;
	private $registry = array();
	private $dependency = array();

	public function __construct($registries = null)
	{
		if($registries)
			$this->register($registries);
	}

	/**
	 * Register dependency
	 * @param mixed key
	 * @param mixed val
	 */
	public function register($key, $val = null)
	{
		if(is_array($key)) foreach($key as $k=>$v) $this->register($k, $v); else $this->registry[$key] = $val;
	}

	/**
	 * Check if the the registry has been registered.
	 * @param string
	 * @return boolean
	 */
	public function has($dependency)
	{
		return isset($this->registry[$dependency]);
	}

	/**
	 * Resolve the dependency
	 * @param string property
	 * @return mixed
	 */
	public function get($dependency)
	{
		if(isset($this->storage[$dependency]))
			return $this->storage[$dependency];

		$class	= $this->registry[$dependency];

		if($class instanceof \Closure)
		{
			$val	= $class();
		}
		else if(is_object($class))
		{
			$val	= $class;
		}
		else if(!isset($class[1]))
		{
			$val	= new $class[0];
		}
		else
		{
			$reflection	= new \ReflectionClass($class[0]);
			$obj	= $reflection->newInstanceArgs($class[1]);

			$val	= $obj;
		}

		$this->storage[$dependency] = $val;

		return $this->storage[$dependency];

	}
}


?><commit_msg>added __get and __call method to DI container<commit_after><?php
namespace Exedra\Application;

class Di
{
	private $storage;
	private $registry = array();
	private $dependency = array();

	public function __construct($registries = null)
	{
		if($registries)
			$this->register($registries);
	}

	/**
	 * Register dependency
	 * @param mixed key
	 * @param mixed val
	 */
	public function register($key, $val = null)
	{
		if(is_array($key)) foreach($key as $k=>$v) $this->register($k, $v); else $this->registry[$key] = $val;
	}

	/**
	 * Check if the the registry has been registered.
	 * @param string
	 * @return boolean
	 */
	public function has($dependency)
	{
		return isset($this->registry[$dependency]);
	}

	/**
	 * Magically alias to get.
	 * @param string dependency
	 * @return this->get(dependency)
	 */
	public function __get($dependency)
	{
		return $this->get($dependency);
	}

	/**
	 * Magically you can pass additional argument you want to the dependency constructor.
	 */
	public function __call($dependency, $args)
	{
		if(isset($this->registry[$dependency]))
			return $this->get($dependency, $args);
	}

	/**
	 * Resolve the dependency
	 * @param string property
	 * @return mixed
	 */
	public function get($dependency, $args = array())
	{
		if(isset($this->storage[$dependency]))
			return $this->storage[$dependency];

		$class	= $this->registry[$dependency];

		if($class instanceof \Closure)
		{
			$val	= call_user_func_array($class, $args);
		}
		else if(is_object($class))
		{
			$val	= $class;
		}
		else if(!isset($class[1]))
		{
			if(count($args) > 0)
			{
				$reflection	= new \ReflectionClass($class[0]);
				$obj	= $reflection->newInstanceArgs($args);

				$val	= $obj;
			}
			else
			{
				$val = new $class[0];
			}
		}
		else
		{
			// merge with passed argument if has any.
			$args = array_merge($class[1], $args);
			$reflection	= new \ReflectionClass($class[0]);
			$obj	= $reflection->newInstanceArgs($args);

			$val	= $obj;
		}

		$this->storage[$dependency] = $val;

		return $this->storage[$dependency];

	}
}


?>
{'fraction_non_alphanumeric': 0.1706524948331857, 'fraction_numerical': 0.002952465308532625, 'mean_word_length': 3.6032608695652173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '7025396', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1131, 'n_words': 264}