<commit_before><?php
/**
 * Yadif
 * 
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so I can send you a copy immediately.
 */

require_once 'Exception.php';

/**
 * Yadif_Container
 *
 * @category   Yadif
 * @copyright  Copyright (c) 2008 Thomas McKelvey
 */
class Yadif_Container
{
	/**
	 * Char we prefix string arguments with to identify as strings
	 */
	const STRING_IDENTIFIER = '"';

	/**
	 * Char to preserve index of identical method calls
	 */
	const METHOD_TRIM_CHAR = '#';

	/**
	 * Class index key of component $config
	 */
	const CONFIG_CLASS = 'class';

	/**
	 * Arguments index key of component $config
	 */
	const CONFIG_ARGUMENTS = 'arguments';

	// container of component configurations
	protected $_container = array();

	// parameters which have been set, expected to be bound
	protected $_parameters = array();

	public function __construct(array $config = null)
	{
		if (isset($config)) {
			if (!is_array($config)) {
                throw new Yadif_Exception('$config not array, is ' . gettype($config));
            }

			foreach ($config as $componentName => $componentConfig) {
				$this->addComponent( $componentName, $componentConfig );
			}
		}
	}

	/**
	 * Create a container
	 *
	 * @param array|string A configuration array or the filename of a PHP 
	 * file that returns a configuration array
	 */
	static public function create($config = null)
	{
		if (is_string($config)) {
			$filename = (substr($config, -4, 4) === '.php') ? $config : $config . '.php';
			if (substr($filename, -13, 13) === 'Container.php' && is_array(include $filename)) {
				return new Yadif_Container(include $filename);
			} else {
				throw new Yadif_Exception("$filename not file");
			}
		} else if (is_array($config)) {
			return new Yadif_Container($config);
		}

		throw new Yadif_Exception('$config must be string or array, is ' . gettype($config));
	}

	/**
	 * Getter method for internal array of component configurations
	 *
	 * @return array
	 */
	public function getContainer()
	{
		return $this->_container;
	}

	/**
	 * Getter method for internal array of parameters<commit_msg>Refactored Yadif_Container::create to not include a config twice from file<commit_after><?php
/**
 * Yadif
 * 
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so I can send you a copy immediately.
 */

require_once 'Exception.php';

/**
 * Yadif_Container
 *
 * @category   Yadif
 * @copyright  Copyright (c) 2008 <NAME>
 */
class Yadif_Container
{
	/**
	 * Char we prefix string arguments with to identify as strings
	 */
	const STRING_IDENTIFIER = '"';

	/**
	 * Char to preserve index of identical method calls
	 */
	const METHOD_TRIM_CHAR = '#';

	/**
	 * Class index key of component $config
	 */
	const CONFIG_CLASS = 'class';

	/**
	 * Arguments index key of component $config
	 */
	const CONFIG_ARGUMENTS = 'arguments';

	// container of component configurations
	protected $_container = array();

	// parameters which have been set, expected to be bound
	protected $_parameters = array();

	public function __construct(array $config = null)
	{
		if (isset($config)) {
			if (!is_array($config)) {
                throw new Yadif_Exception('$config not array, is ' . gettype($config));
            }

			foreach ($config as $componentName => $componentConfig) {
				$this->addComponent( $componentName, $componentConfig );
			}
		}
	}

	/**
	 * Create a container
	 *
	 * @param array|string A configuration array or the filename of a PHP 
	 * file that returns a configuration array
	 */
	static public function create($config = null)
	{
		if (is_string($config)) {
			$filename = (substr($config, -4, 4) === '.php') ? $config : $config . '.php';
			if (substr($filename, -13, 13) === 'Container.php') {
                $config = include($filename);
                if(!is_array($config)) {
                    throw new Yadif_Exception('Container Config File '.$filename.' does not return an array.');
                }
				return new Yadif_Container($config);
			} else {
				throw new Yadif_Exception("$filename not file");
			}
		} else if (is_array($config)) {
			return new Yadif_Container($config);
		}

		throw new Yadif_Exception('$config must be string or array, is ' . gettype($config));
	}

	/**
	 * Getter method for internal array of component configurations
	 *
	 * @return array
	 */
	public function getContainer()
	{
		return $this->_container;
	}

	/**
	 * Getter method for internal array of parameters
{'fraction_non_alphanumeric': 0.11921343711593609, 'fraction_numerical': 0.004096681687832855, 'mean_word_length': 3.1842330762639244, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '4281182', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1394, 'n_words': 502}