<commit_before><?php
	require_once 'Lib/_Loader.php';

	trait ModuleManagerLoader
	{
		public function LoadModules()
		{
			Std::Out();
			Std::Out('[INFO] [MODULES] Loading');

			$Modules = Config::Get('Modules');

			if(is_array($Modules))
			{
				$Keys = array_keys($Modules);

				// $Loaded = array();

				foreach($Keys as $Key)
					foreach($Modules[$Key] as $Module)
						$this->LoadModule($Key, $Module); // $Loaded[$Key][$Module] = $this->LoadModule($Key, $Module) => illegal offset type if $Module is alias (array)

				Std::Out('[INFO] [MODULES] Ready!'); // ($N loaded modules)

				return true; // return $Loaded;
			}

			Std::Out('[WARNING] [MODULES] Config file is not an array');

			return false;
		}

		private function LoadModule($Key, $Name)
		{
			if(is_array($Name))
			{
				if(!empty($Name[0]) && !empty($Name[1]))
				{
					$Filename = $Name[1];
					$Name = $Name[0];
				}
				else
					return false;
			}
			else
				$Filename = $Name;

			if($this->KeyExists($Key))
			{
				$JPath = "class/Modules/{$Key}_{$Filename}.json";
				$PPath = "class/Modules/{$Key}_{$Filename}.php";

				if(basename(dirname(realpath($JPath))) === 'Modules')
				{
					$Json = Json::Decode($JPath);

					if($Json !== false)
					{
						if(is_readable($PPath))
						{
							// Lint

							$this->Modules[$Key][strtolower($Name)] = array
							(
								'Path' => $PPath,
								'File' => $Filename,
								'Data' => $Json
							);

							return true;
						}
						else
							Std::Out("[WARNING] [MODULES] Can't load {$Key}::{$Name}. PHP file is not readable");
					}
					else
						Std::Out("[WARNING] [MODULES] Can't load {$Key}::{$Name}. Json file is not readable");
				}
				else
					Std::Out("[WARNING] [MODULES] Can't load {$Key}::{$Name}. It is not in Modules folder");
			}

			return false;
		}

		public function LoadCommandModule($Name)
		{
			return $this->LoadModule('Command', $Name);
		}

		public function LoadDomainModule($Name)
		{
			return $this->LoadModule('Domain', $Name);
		}

		public function LoadExtensionModule($Name)
		{
			return $this->LoadModule('Extension', $Name);
		}

		public function LoadMediaModule($Name)
		{
			return $this->LoadModule('Media', $Name);
		}

		abstract protected function KeyExists($Key);<commit_msg>ModuleManagerLoader ready! (New POO Module system)<commit_after><?php
	require_once 'Lib/_Loader.php';

	require_once 'Module.php';

	trait ModuleManagerLoader
	{
		public function LoadModules()
		{
			Std::Out();
			Std::Out('[INFO] [MODULES] Loading');

			$Modules = Config::Get('Modules');

			if(is_array($Modules))
			{
				$Loaded = array();

				$Keys = array_keys($Modules);

				foreach($Keys as $Key)
				{
					foreach($Modules[$Key] as $Module)
					{
						if(is_string($Module))
							$Module = array($Module, $Module);

						if(is_array($Module) && !empty($Module[0]) && !empty($Module[1]))
						{
							$Name = strtolower($Module[0]);

							$Loaded[$Key][$Name] = $this->LoadModule($Key, $Name, $Module[1]);
						}
						else
						{
							Std::Out('[WARNING] [MODULES] {$Key}::');
							Std::Out(var_export($Module, true));
							Std::Out('0 => $Name');
							Std::Out('1 => $AliasOf');
						}
					}
				}

				Std::Out('[INFO] [MODULES] Ready!'); // ($N loaded modules)

				return $Loaded;
			}

			Std::Out('[WARNING] [MODULES] Config file is not an array');

			return false;
		}

		public function LoadModule($Key, $Name, $AliasOf)
		{
			if($this->KeyExists($Key))
			{
				$Name = strtolower($Name);
				$AliasOf = strtolower($AliasOf);

				$this->Modules[$Key][$Name] = new Module($this, $this->WhatsBot, $this->WhatsApp, $Key, $Name, $AliasOf);

				$Loaded = $this->Modules[$Key][$Name]->IsLoaded();

				if(!$Loaded)
					unset($this->Module[$Key][$Name]);

				return $Loaded;
			}

			return false;
		}

		public function UnloadModule($Key, $Name)
		{
			$Name = strtolower($Name);

			if($this->ModuleExists($Key, $Name))
			{
				unset($this->Modules[$Key][$Name]);

				return true;
			}

			return false;
		}

		abstract public function KeyExists($Key);
		abstract public function ModuleExists($Key, $Name, $ShowWarn = true);
{'fraction_non_alphanumeric': 0.1911517191632604, 'fraction_numerical': 0.0024044241404183697, 'mean_word_length': 3.050632911392405, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6411765', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1416, 'n_words': 284}