<commit_before><?php

/*
 * This file is part of the Wilson web framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Wilson\Utils;

/**
 * Injector provides a simple Service Injection mechanism. Service Injection
 * allows us to define dependencies easily and lazily which can then be resolved
 * on an ad-hoc basis.
 */
class Injector
{
	/**
	 * @var callable[]
	 */
	protected $services = array();

	/**
	 * @var callable[]
	 */
	protected $extensions = array();

	/**
	 * @var mixed[]
	 */
	protected $resolved = array();

	/**
	 * @var string[]
	 */
	protected $beingResolved = array();

	/**
	 * Returns whether a service has been defined.
	 *
	 * @param string $name
	 * @return bool
	 */
	public function defined($name)
	{
		return isset($this->services[$name]) || isset($this->resolved[$name]);
	}

	/**
	 * Resolves the services for and executes the given callable. The result of
	 * the executed callable is returned to the caller, if applicable.
	 *
	 * @param callable $fn
	 * @return mixed
	 * @throws \InvalidArgumentException
	 */
	public function inject($fn)
	{
		return call_user_func_array($fn, $this->dependencies($fn));
	}

	/**
	 * Returns the dependencies for a function. These can then be invoked
	 * with call_user_func_array().
	 *
	 * @param callable $fn
	 * @return array
	 * @throws \InvalidArgumentException
	 */
	public function dependencies($fn)
	{
		if (!is_callable($fn)) {
			throw new \InvalidArgumentException("\$fn is expected to be a callable");
		}

		$args = array();
		foreach ($this->requires($fn) as $dependency) {
			$args[$dependency] = $this->resolve($dependency);
		}

		return $args;
	}<commit_msg>Micro optimisation: removed is_callable check from Injector::depedencies.<commit_after><?php

/*
 * This file is part of the Wilson web framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Wilson\Utils;

/**
 * Injector provides a simple Service Injection mechanism. Service Injection
 * allows us to define dependencies easily and lazily which can then be resolved
 * on an ad-hoc basis.
 */
class Injector
{
	/**
	 * @var callable[]
	 */
	protected $services = array();

	/**
	 * @var callable[]
	 */
	protected $extensions = array();

	/**
	 * @var mixed[]
	 */
	protected $resolved = array();

	/**
	 * @var string[]
	 */
	protected $beingResolved = array();

	/**
	 * Returns whether a service has been defined.
	 *
	 * @param string $name
	 * @return bool
	 */
	public function defined($name)
	{
		return isset($this->services[$name]) || isset($this->resolved[$name]);
	}

	/**
	 * Resolves the services for and executes the given callable. The result of
	 * the executed callable is returned to the caller, if applicable.
	 *
	 * @param callable $fn
	 * @return mixed
	 * @throws \InvalidArgumentException
	 */
	public function inject($fn)
	{
		return call_user_func_array($fn, $this->dependencies($fn));
	}

	/**
	 * Returns the dependencies for a function. These can then be invoked
	 * with call_user_func_array().
	 *
	 * @param callable $fn
	 * @return array
	 * @throws \InvalidArgumentException
	 */
	public function dependencies($fn)
	{
		$args = array();
		foreach ($this->requires($fn) as $dependency) {
			$args[$dependency] = $this->resolve($dependency);
		}

		return $args;
	}
{'fraction_non_alphanumeric': 0.13302883242934627, 'fraction_numerical': 0.0, 'mean_word_length': 3.475095785440613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '7190210', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1007, 'n_words': 353}