<commit_before><?php

	/**
	 * The inKWell scaffolder
	 *
	 * @author <NAME> [mjs] <<EMAIL>>
	 * @copyright Copyright (c) 2011, <NAME>
	 * @license http://www.gnu.org/licenses/agpl.html GNU Affero General Public License
	 *
	 * @package inKWell
	 */
	class Scaffolder extends iw implements inkwell
	{

		const DEFAULT_SCAFFOLDING_ROOT = 'scaffolding';
		const DYNAMIC_SCAFFOLD_METHOD  = '__make';
		const FINAL_SCAFFOLD_METHOD    = '__build';

		/**
		 * The directory containing scaffolding templates
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $scaffoldingRoot = NULL;

		/**
		 * Whether or not we are in the process of building
		 *
		 * @static
		 * @access private
		 * @var boolean
		 */
		static private $isBuilding = FALSE;

		/**
		 * A list of classes to auto-scaffold
		 *
		 * @static
		 * @access private
		 * @var array
		 */
		static private $autoScaffoldClasses = array();

		/**
		 * Contains the last scaffolded code
		 *
		 * @static
		 * @access private
		 * @var array
		 */
		static private $lastScaffoldedCode = NULL;

		/**
		 * Initializses the Scaffolder class
		 *
		 * @static
		 * @access public
		 * @param array $config The configuration array
		 * @return void
		 */
		static public function __init(array $config = array(), $element = NULL)
		{
			if (isset($config['disabled']) && $config['disabled']) {
				return FALSE;
			}

			self::$scaffoldingRoot = implode(DIRECTORY_SEPARATOR, array(
				iw::getRoot(),
				($root_directory = iw::getRoot($element))
					? $root_directory
					: self::DEFAULT_SCAFFOLDING_ROOT
			));

			self::$scaffoldingRoot = new fDirectory(self::$scaffoldingRoot);
			$register_autoloader   = FALSE;

			foreach (iw::getConfig() as $element => $element_config) {
				if (isset($element_config['auto_scaffold'])) {
					if ($element_config['auto_scaffold']) {
						self::$autoScaffoldClasses[] = fGrammar::camelize(
							$element,
							TRUE
						);
						$register_autoloader = TRUE;
					}
				}
			}

			if ($register_autoloader) {
				spl_autoload_register(iw::makeTarget(__CLASS__, 'loadClass'));
			}

			return TRUE;
		}

		/**
		 * Attempts to load a class via Scaffolder, i.e. performs on the fly
		 * scaffolding.
		 *
		 * @static
		 * @access public
		 * @param string $class The class to be loaded
		 * @return mixed Whether or not the class was successfully loaded and initialized
		 */
		static public function loadClass($class)
		{
			foreach (self::$autoScaffoldClasses as $loader) {

				$test = iw::makeTarget($loader, self::MATCH_CLASS_METHOD);
				$make = iw::makeTarget($loader, self::DYNAMIC_SCAFFOLD_METHOD);

				if (is_callable($test) && is_callable($make)) {
					if (call_user_func($test, $class)) {
						if (call_user_func($make, $class)) {
							return self::initializeClass($class);
						}
					}
				}
			}

			return FALSE;
		}

		/**
		 * Builds and writes out the scaffolding for a configured builder.
		 * The builder can be a class or a template.  If a template is passed
		 * it is assumed to require no additional template variables.
		 *
		 * @static
		 * @access public
		 * @param string $builder A valid class or template name
		 * @param string $target A valid class name or file location
		 * @return void
		 */
		static public function build($builder, $target)
		{
			self::$isBuilding = TRUE;

			try {

				$root_directory = rtrim(implode(DIRECTORY_SEPARATOR, array(
					iw::getRoot(),
					iw::getRoot(fGrammar::underscorize($builder))
				)), '/\\');

				if (is_string($target)) {
					$output_file = implode(DIRECTORY_SEPARATOR, array(
						$root_directory,
						!($extension = pathinfo($target, PATHINFO_EXTENSION))
							? $target . '.php'
							: $target
					));
				} else {
					$output_file = NULL;
				}


				if (
					preg_match(iw::REGEX_VARIABLE, $builder)
					&& class_exists($builder)
				) {

					$make_method = iw::makeTarget(
						$builder,
						self::DYNAMIC_SCAFFOLD_METHOD
					);

					if (is_callable($make_method)) {
						$make_target = pathinfo($target, PATHINFO_FILENAME);
						call_user_func($make_method, $make_target);
					}

					$build_method = iw::makeTarget(
						$builder,
						self::FINAL_SCAFFOLD_METHOD
					);

					if (is_callable($build_method)) {
						call_user_func(
							$build_method,
							$target,
							$output_file,
							self::$lastScaffoldedCode
						);
					} else {
						$file = fFile::create(
							$output_file,
							self::$lastScaffoldedCode
						);
					}

					self::$lastScaffoldedCode = NULL;

				} else {

				}

				self::$isBuilding = FALSE;
			} catch (Exception $e) {
				self::$isBuilding = FALSE;
				throw $e;
			}<commit_msg>- Changed scaffolder to throw a simple exception for non-class build attempts.<commit_after><?php

	/**
	 * The inKWell scaffolder
	 *
	 * @author <NAME> [mjs] <<EMAIL>>
	 * @copyright Copyright (c) 2011, <NAME>
	 * @license http://www.gnu.org/licenses/agpl.html GNU Affero General Public License
	 *
	 * @package inKWell
	 */
	class Scaffolder extends iw implements inkwell
	{

		const DEFAULT_SCAFFOLDING_ROOT = 'scaffolding';
		const DYNAMIC_SCAFFOLD_METHOD  = '__make';
		const FINAL_SCAFFOLD_METHOD    = '__build';

		/**
		 * The directory containing scaffolding templates
		 *
		 * @static
		 * @access private
		 * @var string|fDirectory
		 */
		static private $scaffoldingRoot = NULL;

		/**
		 * Whether or not we are in the process of building
		 *
		 * @static
		 * @access private
		 * @var boolean
		 */
		static private $isBuilding = FALSE;

		/**
		 * A list of classes to auto-scaffold
		 *
		 * @static
		 * @access private
		 * @var array
		 */
		static private $autoScaffoldClasses = array();

		/**
		 * Contains the last scaffolded code
		 *
		 * @static
		 * @access private
		 * @var array
		 */
		static private $lastScaffoldedCode = NULL;

		/**
		 * Initializses the Scaffolder class
		 *
		 * @static
		 * @access public
		 * @param array $config The configuration array
		 * @return void
		 */
		static public function __init(array $config = array(), $element = NULL)
		{
			if (isset($config['disabled']) && $config['disabled']) {
				return FALSE;
			}

			self::$scaffoldingRoot = implode(DIRECTORY_SEPARATOR, array(
				iw::getRoot(),
				($root_directory = iw::getRoot($element))
					? $root_directory
					: self::DEFAULT_SCAFFOLDING_ROOT
			));

			self::$scaffoldingRoot = new fDirectory(self::$scaffoldingRoot);
			$register_autoloader   = FALSE;

			foreach (iw::getConfig() as $element => $element_config) {
				if (isset($element_config['auto_scaffold'])) {
					if ($element_config['auto_scaffold']) {
						self::$autoScaffoldClasses[] = fGrammar::camelize(
							$element,
							TRUE
						);
						$register_autoloader = TRUE;
					}
				}
			}

			if ($register_autoloader) {
				spl_autoload_register(iw::makeTarget(__CLASS__, 'loadClass'));
			}

			return TRUE;
		}

		/**
		 * Attempts to load a class via Scaffolder, i.e. performs on the fly
		 * scaffolding.
		 *
		 * @static
		 * @access public
		 * @param string $class The class to be loaded
		 * @return mixed Whether or not the class was successfully loaded and initialized
		 */
		static public function loadClass($class)
		{
			foreach (self::$autoScaffoldClasses as $loader) {

				$test = iw::makeTarget($loader, self::MATCH_CLASS_METHOD);
				$make = iw::makeTarget($loader, self::DYNAMIC_SCAFFOLD_METHOD);

				if (is_callable($test) && is_callable($make)) {
					if (call_user_func($test, $class)) {
						if (call_user_func($make, $class)) {
							return self::initializeClass($class);
						}
					}
				}
			}

			return FALSE;
		}

		/**
		 * Builds and writes out the scaffolding for a configured builder.
		 * The builder can be a class or a template.  If a template is passed
		 * it is assumed to require no additional template variables.
		 *
		 * @static
		 * @access public
		 * @param string $builder A valid class or template name
		 * @param string $target A valid class name or file location
		 * @return void
		 */
		static public function build($builder, $target)
		{
			self::$isBuilding = TRUE;

			try {

				$root_directory = rtrim(implode(DIRECTORY_SEPARATOR, array(
					iw::getRoot(),
					iw::getRoot(fGrammar::underscorize($builder))
				)), '/\\');

				if (is_string($target)) {
					$output_file = implode(DIRECTORY_SEPARATOR, array(
						$root_directory,
						!($extension = pathinfo($target, PATHINFO_EXTENSION))
							? $target . '.php'
							: $target
					));
				} else {
					$output_file = NULL;
				}


				if (
					preg_match(iw::REGEX_VARIABLE, $builder)
					&& class_exists($builder)
				) {

					$make_method = iw::makeTarget(
						$builder,
						self::DYNAMIC_SCAFFOLD_METHOD
					);

					if (is_callable($make_method)) {
						$make_target = pathinfo($target, PATHINFO_FILENAME);
						call_user_func($make_method, $make_target);
					}

					$build_method = iw::makeTarget(
						$builder,
						self::FINAL_SCAFFOLD_METHOD
					);

					if (is_callable($build_method)) {
						call_user_func(
							$build_method,
							$target,
							$output_file,
							self::$lastScaffoldedCode
						);
					} else {
						$file = fFile::create(
							$output_file,
							self::$lastScaffoldedCode
						);
					}

					self::$lastScaffoldedCode = NULL;

				} else {
					throw new fException(
						'Non-class scaffolding not supported by build.'
					);
				}

				self::$isBuilding = FALSE;
			} catch (Exception $e) {
				self::$isBuilding = FALSE;
				throw $e;
			}
{'fraction_non_alphanumeric': 0.12448829642069907, 'fraction_numerical': 0.0008397186942374305, 'mean_word_length': 2.823434991974318, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1524394', 'n_tokens_mistral': 4035, 'n_tokens_neox': 2984, 'n_words': 724}