config = $app['config']; $this->files = $app['files']; $this->modulesStatuses = $this->getModulesStatuses(); $this->path = $path; } /** * Get modules statuses, from the database * * @return array */ private function getModulesStatuses(): array { try { $modules = \App\Models\Module::all(); $retVal = []; foreach ($modules as $i) { $retVal[$i->name] = $i->enabled; } return $retVal; } catch (Exception $e) { return []; } } /** * {@inheritdoc} */ public function reset(): void { (new \App\Models\Module())->truncate(); } /** * {@inheritdoc} */ public function enable(Module $module): void { $this->setActiveByName($module->getName(), true); } /** * {@inheritdoc} */ public function disable(Module $module): void { $this->setActiveByName($module->getName(), false); } /** * \Nwidart\Modules\Module instance passed * {@inheritdoc} */ public function hasStatus(Module $module, bool $status): bool { try { $module = (new \App\Models\Module())->where('name', $module->getName()); if ($module->exists()) { return $module->first()->enabled == 1; } return false; } catch (Exception $e) { return false; } } /** * {@inheritdoc} */ public function setActive(Module $module, bool $active): void { $this->setActiveByName($module->getName(), $active); } /** * {@inheritdoc} */ public function setActiveByName(string $name, bool $status): void { $module = (new \App\Models\Module())->where('name', $name); if ($module->exists()) { $module->update([ 'status' => $status, ]); } } /** * {@inheritdoc} */ public function delete(Module $module): void { $name = $module->getName(); try { (new \App\Models\Module())->where([ 'name' => $name, ])->delete(); } catch (Exception $e) { Log::error('Module '.$module.' Delete failed! Exception : '.$e->getMessage()); return; } } }