<commit_before><?php
namespace application\nutsNBolts
{
	use nutshell\Nutshell;
	use nutshell\core\loader\Loader;
	use nutshell\core\application\Application;
	use nutshell\core\exception\NutshellException;
	use \DirectoryIterator;

	/**
	 * Nuts n Bolts
	 * 
	 * @version 1.0.0
	 * @author <NAME> <<EMAIL>>
	 */
	class NutsNBolts extends Application
	{
		const VERSION					='1.0.0-dev';
		const VERSION_MAJOR				=1;
		const VERSION_MINOR				=0;
		const VERSION_MICRO				=0;
		const VERSION_STAGE				='dev';
		const VERSION_STAGE_NUM			=0;
		
		private $siteBindings=array();
		
		public $widget=null;
		
		public function init()
		{
			// print_r(Nutshell::getInstance()->config);exit();
			// Set the application path.
			// Nutshell::setAppPath(__DIR__);
			// Nutshell::registerApplication('nutsnbolts',__DIR__);

			//get the nutshell instance (create nutshell).
			$this->nutshell	= Nutshell::getInstance();
			
			$this->widget=new Loader();
			$this->widget->registerContainer('widget',__DIR__._DS_.'widget'._DS_,'application\nutsnbolts\widget\\');
			
			if (defined('TESTRUNNER') && TESTRUNNER && NS_INTERFACE!==Nutshell::INTERFACE_PHPUNIT)
			{
				throw new Exception('Nuts n Bolts testrunner interface can only be used with PHP Unit.');
			}
			else if (NS_INTERFACE!==Nutshell::INTERFACE_PHPUNIT)
			{
				header('X-NutsNBolts-Version:'.self::VERSION);
				header('X-Nutshell-Version:'.Nutshell::VERSION);
			}
			
			//Load helpers that belong to the application.
			$this->loadApplicationHelpers();
			
			$this->loadPHPPatches();

			//Load Exception Handlers that belong to the application.
			// $this->loadApplicationExceptionHandlers();
		}
		
		public function exec()
		{
			//Initiate the MVC.
			try
			{
				if (NS_INTERFACE!=Nutshell::INTERFACE_CLI
				&& NS_INTERFACE!= Nutshell::INTERFACE_PHPUNIT)
				{
					header('Content-Type:text/html;');
				}
				if (NS_INTERFACE!= Nutshell::INTERFACE_PHPUNIT)
				{
					$this->plugin->Mvc('nutsNBolts');
				}
			}
			catch(NutshellException $exception)//TODO: Change this - its not always a 404 (It can sometimes be a 500).
			{
				//exit('mvc failed');
				if(NS_INTERFACE != Nutshell::INTERFACE_CLI)
				{
					header('HTTP/1.1 404 Controller Not Found');
				}
				if ($this->config->application->mode == 'development')
				{
					throw $exception;
				}
			}
		}
		
		/**
		 * This method runs a "require_once" for each file in the folder.
		 * @param string $folder
		 */
		public static function loadAllFilesFromFolder($folder)
		{
			if (is_dir($folder))
			{
				foreach (new DirectoryIterator($folder) as $iteration)
				{
					//We don't load folders or files from within folders.
					if ($iteration->isFile() && !$iteration->isDot())
					{
						require_once($iteration->getPathname());
					}
				}
			}
		}
		
		/**
		 * This method loads all application helpers.
		 */
		private function loadApplicationHelpers()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'helper' . _DS_);
		}

		/**
		 * This method loads all application Exception Handlers.
		 */
		private function loadApplicationExceptionHandlers()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'exception' . _DS_);
		}

		/**
		 * This method loads all patches.
		 */
		private function loadPatches()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'patches' . _DS_);
		}
		
		public function bindToSite($application,$site)
		{
			$this->siteBindings[]=array
			(
				'application'	=>$application,
				'site'			=>$site
			);
			return $this;
		}
		
		public function getSiteBinding($site)
		{
			for($i=0,$j=count($this->siteBindings); $i<$j; $i++)
			{
				if ($this->siteBindings[$i]['site']==$site)
				{
					return $this->siteBindings[$i];
				}
			}
			return false;
		}
		
		public function getWidgetList()
		{
			//preg_match_all('/((?:^|[A-Z])[a-z]+)/',$str,$matches);
			$folder	=__DIR__._DS_.'widget';
			$list	=array();
			foreach (new DirectoryIterator($folder) as $iteration)
			{
				//We don't load folders or files from within folders.
				if ($iteration->isDir() && !$iteration->isDot()
				&& $iteration->getFilename()!='base')
				{
					$list[]=array
					(
						'namespace'	=>'application\\nutsnbolts\\widget\\'.$iteration->getFilename(),
						'name'		=>ucwords($iteration->getFilename())
					);
				}
			}
			//TODO: Registered widgets from other applications.
			
			return $list;
		}
		
		public function loadPHPPatches()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'patch' . _DS_);
		}
	}
}
?><commit_msg>Fix for invalid widget namespaces being saved.<commit_after><?php
namespace application\nutsNBolts
{
	use nutshell\Nutshell;
	use nutshell\core\loader\Loader;
	use nutshell\core\application\Application;
	use nutshell\core\exception\NutshellException;
	use \DirectoryIterator;

	/**
	 * Nuts n Bolts
	 * 
	 * @version 1.0.0
	 * @author <NAME> <<EMAIL>>
	 */
	class NutsNBolts extends Application
	{
		const VERSION					='1.0.0-dev';
		const VERSION_MAJOR				=1;
		const VERSION_MINOR				=0;
		const VERSION_MICRO				=0;
		const VERSION_STAGE				='dev';
		const VERSION_STAGE_NUM			=0;
		
		private $siteBindings=array();
		
		public $widget=null;
		
		public function init()
		{
			// print_r(Nutshell::getInstance()->config);exit();
			// Set the application path.
			// Nutshell::setAppPath(__DIR__);
			// Nutshell::registerApplication('nutsnbolts',__DIR__);

			//get the nutshell instance (create nutshell).
			$this->nutshell	= Nutshell::getInstance();
			
			$this->widget=new Loader();
			$this->widget->registerContainer('widget',__DIR__._DS_.'widget'._DS_,'application\nutsnbolts\widget\\');
			
			if (defined('TESTRUNNER') && TESTRUNNER && NS_INTERFACE!==Nutshell::INTERFACE_PHPUNIT)
			{
				throw new Exception('Nuts n Bolts testrunner interface can only be used with PHP Unit.');
			}
			else if (NS_INTERFACE!==Nutshell::INTERFACE_PHPUNIT)
			{
				header('X-NutsNBolts-Version:'.self::VERSION);
				header('X-Nutshell-Version:'.Nutshell::VERSION);
			}
			
			//Load helpers that belong to the application.
			$this->loadApplicationHelpers();
			
			$this->loadPHPPatches();

			//Load Exception Handlers that belong to the application.
			// $this->loadApplicationExceptionHandlers();
		}
		
		public function exec()
		{
			//Initiate the MVC.
			try
			{
				if (NS_INTERFACE!=Nutshell::INTERFACE_CLI
				&& NS_INTERFACE!= Nutshell::INTERFACE_PHPUNIT)
				{
					header('Content-Type:text/html;');
				}
				if (NS_INTERFACE!= Nutshell::INTERFACE_PHPUNIT)
				{
					$this->plugin->Mvc('nutsNBolts');
				}
			}
			catch(NutshellException $exception)//TODO: Change this - its not always a 404 (It can sometimes be a 500).
			{
				//exit('mvc failed');
				if(NS_INTERFACE != Nutshell::INTERFACE_CLI)
				{
					header('HTTP/1.1 404 Controller Not Found');
				}
				if ($this->config->application->mode == 'development')
				{
					throw $exception;
				}
			}
		}
		
		/**
		 * This method runs a "require_once" for each file in the folder.
		 * @param string $folder
		 */
		public static function loadAllFilesFromFolder($folder)
		{
			if (is_dir($folder))
			{
				foreach (new DirectoryIterator($folder) as $iteration)
				{
					//We don't load folders or files from within folders.
					if ($iteration->isFile() && !$iteration->isDot())
					{
						require_once($iteration->getPathname());
					}
				}
			}
		}
		
		/**
		 * This method loads all application helpers.
		 */
		private function loadApplicationHelpers()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'helper' . _DS_);
		}

		/**
		 * This method loads all application Exception Handlers.
		 */
		private function loadApplicationExceptionHandlers()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'exception' . _DS_);
		}

		/**
		 * This method loads all patches.
		 */
		private function loadPatches()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'patches' . _DS_);
		}
		
		public function bindToSite($application,$site)
		{
			$this->siteBindings[]=array
			(
				'application'	=>$application,
				'site'			=>$site
			);
			return $this;
		}
		
		public function getSiteBinding($site)
		{
			for($i=0,$j=count($this->siteBindings); $i<$j; $i++)
			{
				if ($this->siteBindings[$i]['site']==$site)
				{
					return $this->siteBindings[$i];
				}
			}
			return false;
		}
		
		public function getWidgetList()
		{
			//preg_match_all('/((?:^|[A-Z])[a-z]+)/',$str,$matches);
			$folder	=__DIR__._DS_.'widget';
			$list	=array();
			foreach (new DirectoryIterator($folder) as $iteration)
			{
				//We don't load folders or files from within folders.
				if ($iteration->isDir() && !$iteration->isDot()
				&& $iteration->getFilename()!='base')
				{
					$list[]=array
					(
						'namespace'	=>'application\\nutsNBolts\\widget\\'.$iteration->getFilename(),
						'name'		=>ucwords($iteration->getFilename())
					);
				}
			}
			//TODO: Registered widgets from other applications.
			
			return $list;
		}
		
		public function loadPHPPatches()
		{
			$this->loadAllFilesFromFolder(__DIR__ . _DS_ . 'patch' . _DS_);
		}
	}
}
?>
{'fraction_non_alphanumeric': 0.15178275747875042, 'fraction_numerical': 0.0048570482393200136, 'mean_word_length': 3.1107078039927405, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 77, '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': '1820567', 'n_tokens_mistral': 3839, 'n_tokens_neox': 3031, 'n_words': 604}