<commit_before><?php
/**
 * @package    Fuel\Dependency
 * @version    2.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2013 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Fuel\Dependency;

use ArrayAccess;
use Closure;

class Container implements ArrayAccess, ResourceAwareInterface
{
	/**
	 * @var  array  $resources  resources
	 */
	protected $resources = array();

	/**
	 * @var  array  $instances  resolved instances
	 */
	protected $instances = array();

	/**
	 * @var  array  $services  service providers
	 */
	protected $services = array();

	/**
	 * @var  array  $extensions  resource extensions
	 */
	protected $extensions = array();

	/**
	 * Register a resource
	 *
	 * @param   string  $identifier  resource identifier
	 * @param   mixed   $resource  resource
	 * @return  $this
	 */
	public function register($identifier, $resource)
	{
		if ( ! $resource instanceof Resource)
		{
			$resource = new Resource($resource);
		}

		$this->resources[$identifier] = $resource;

		return $resource;
	}

	/**
	 * Register a singleton resource
	 *
	 * @param   string  $identifier  resource identifier
	 * @param   mixed   $resource  resource
	 * @return  $this
	 */
	public function registerSingleton($identifier, $resource)
	{
		$resource = $this->register($identifier, $resource);
		$resource->preferSingleton(true);

		return $resource;
	}

	/**
	 * Register a service provider
	 *
	 * @param   ServiceProvider  $service
	 * @return  $this
	 */
	public function registerService(ServiceProvider $service)
	{
		$service->setContainer($this);

		if ($service->provides === true)
		{
			$service->provide();
			$service->provides = false;
		}

		$this->services[get_class($service)] = $service;

		return $this;
	}

	/**
	 * Register service providers
	 *
	 * @param   ServiceProvider[] $service
	 * @return  $this
	 */
	public function registerServices(array $services)
	{
		foreach ($services as $service)
		{
			$this->registerService($service);
		}

		return $this;
	}

	public function getStack($identifier)
	{
		return new Stack($this, $identifier);
	}

	/**
	 * Inject an instance
	 *
	 * @param   string  $identifier  instance identifier
	 * @param   mixed   $instance  instance
	 * @return  $this
	 */
	public function inject($identifier, $instance)
	{
		$this->instances[$identifier] = $instance;

		return $this;
	}

	/**
	 * Remove an instance
	 *
	 * @param   string  $identifier  instance identifier
	 * @param   mixed   $instance  instance
	 * @return  $this
	 */
	public function remove($identifier)
	{
		if (isset($this->instances[$identifier]))
		{
			unset($this->instances[$identifier]);<commit_msg>made identifier optional on getStack()<commit_after><?php
/**
 * @package    Fuel\Dependency
 * @version    2.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2013 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Fuel\Dependency;

use ArrayAccess;
use Closure;

class Container implements ArrayAccess, ResourceAwareInterface
{
	/**
	 * @var  array  $resources  resources
	 */
	protected $resources = array();

	/**
	 * @var  array  $instances  resolved instances
	 */
	protected $instances = array();

	/**
	 * @var  array  $services  service providers
	 */
	protected $services = array();

	/**
	 * @var  array  $extensions  resource extensions
	 */
	protected $extensions = array();

	/**
	 * Register a resource
	 *
	 * @param   string  $identifier  resource identifier
	 * @param   mixed   $resource  resource
	 * @return  $this
	 */
	public function register($identifier, $resource)
	{
		if ( ! $resource instanceof Resource)
		{
			$resource = new Resource($resource);
		}

		$this->resources[$identifier] = $resource;

		return $resource;
	}

	/**
	 * Register a singleton resource
	 *
	 * @param   string  $identifier  resource identifier
	 * @param   mixed   $resource  resource
	 * @return  $this
	 */
	public function registerSingleton($identifier, $resource)
	{
		$resource = $this->register($identifier, $resource);
		$resource->preferSingleton(true);

		return $resource;
	}

	/**
	 * Register a service provider
	 *
	 * @param   ServiceProvider  $service
	 * @return  $this
	 */
	public function registerService(ServiceProvider $service)
	{
		$service->setContainer($this);

		if ($service->provides === true)
		{
			$service->provide();
			$service->provides = false;
		}

		$this->services[get_class($service)] = $service;

		return $this;
	}

	/**
	 * Register service providers
	 *
	 * @param   ServiceProvider[] $service
	 * @return  $this
	 */
	public function registerServices(array $services)
	{
		foreach ($services as $service)
		{
			$this->registerService($service);
		}

		return $this;
	}

	public function getStack($identifier = null)
	{
		return $identifier === null ? new Stack($this) : new ObjectStack($this, $identifier);
	}

	/**
	 * Inject an instance
	 *
	 * @param   string  $identifier  instance identifier
	 * @param   mixed   $instance  instance
	 * @return  $this
	 */
	public function inject($identifier, $instance)
	{
		$this->instances[$identifier] = $instance;

		return $this;
	}

	/**
	 * Remove an instance
	 *
	 * @param   string  $identifier  instance identifier
	 * @param   mixed   $instance  instance
	 * @return  $this
	 */
	public function remove($identifier)
	{
		if (isset($this->instances[$identifier]))
		{
			unset($this->instances[$identifier]);
{'fraction_non_alphanumeric': 0.13196480938416422, 'fraction_numerical': 0.0036656891495601175, 'mean_word_length': 3.2900943396226414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908426', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1580, 'n_words': 424}