src/Application.php
public function enable(Module $module, bool $recollect = true, bool $recursive = false): bool
    {
        $action = function (Module $module): bool {
            $installer = $module->installer();
            if ($installer === null) {
                return true;
            }

            if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
                return false;
            }

            /** @var Installer $installer */
            $installer = new $installer($module);
            try {
                $installer->enable();
                return true;
            } catch (Throwable $e) {
                $installer->enableError($e);
                return false;
            }
        };

        $callback = function (Module $module) use ($recollect) {
            $this->notify($module, 'enabled', true);

            if ($recollect) {
                $this->getCollector()->recollect();
            }

            $this->emit('module.enabled.' . $module->name());
        };

        $manager = $this->moduleManager();

        if ($recursive) {
            foreach ($manager->recursiveDependencies($module) as $dependency) {
                if (!$dependency->isInstalled()) {
                    if (!$this->install($dependency, $recollect, false)) {
                        return false;
                    }
                }
                if (!$dependency->isEnabled()) {
                    if (!$manager->enable($dependency, $action, $callback)) {
                        return false;
                    }
                }
            }

            if (!$module->isInstalled() && !$this->install($module, $recollect, false)) {
                return false;
            }
        }

        return $manager->enable($module, $action, $callback);
    }
public function enable(Module $module, bool $recollect = true, bool $recursive = false): bool
    {
        $action = function (Module $module): bool {
            $installer = $module->installer();
            if ($installer === null) {
                return true;
            }

            if (!class_exists($installer) || !is_subclass_of($installer, Installer::class, true)) {
                return false;
            }

            /** @var Installer $installer */
            $installer = new $installer($module);
            try {
                $installer->enable();
                return true;
            } catch (Throwable $e) {
                $installer->enableError($e);
                return false;
            }
        };

        $callback = function (Module $module) use ($recollect) {
            $this->notify($module, 'enabled', true);

            if ($recollect) {
                $this->getCollector()->recollect();
            }

            $this->emit('module.enabled.' . $module->name());
        };

        $manager = $this->moduleManager();

        if ($recursive) {
            foreach ($manager->recursiveDependencies($module) as $dependency) {
                if (!$dependency->isInstalled()) {
                    if (!$this->install($dependency, $recollect, false)) {
                        return false;
                    }
                }
                if (!$dependency->isEnabled()) {
                    if (!$manager->enable($dependency, $action, $callback)) {
                        return false;
                    }
                }
            }

            if (!$module->isInstalled() && !$this->install($module, $recollect, false)) {
                return false;
            }
        }

        return $manager->enable($module, $action, $callback);
    }
public function enable ( Module $ module , bool $ recollect = true , bool $ recursive = false ) : bool { $ action = function ( Module $ module ) : bool { $ installer = $ module -> installer ( ) ; if ( $ installer === null ) { return true ; } if ( ! class_exists ( $ installer ) || ! is_subclass_of ( $ installer , Installer :: class , true ) ) { return false ; } /** @var Installer $installer */ $ installer = new $ installer ( $ module ) ; try { $ installer -> enable ( ) ; return true ; } catch ( Throwable $ e ) { $ installer -> enableError ( $ e ) ; return false ; } } ; $ callback = function ( Module $ module ) use ( $ recollect ) { $ this -> notify ( $ module , 'enabled' , true ) ; if ( $ recollect ) { $ this -> getCollector ( ) -> recollect ( ) ; } $ this -> emit ( 'module.enabled.' . $ module -> name ( ) ) ; } ; $ manager = $ this -> moduleManager ( ) ; if ( $ recursive ) { foreach ( $ manager -> recursiveDependencies ( $ module ) as $ dependency ) { if ( ! $ dependency -> isInstalled ( ) ) { if ( ! $ this -> install ( $ dependency , $ recollect , false ) ) { return false ; } } if ( ! $ dependency -> isEnabled ( ) ) { if ( ! $ manager -> enable ( $ dependency , $ action , $ callback ) ) { return false ; } } } if ( ! $ module -> isInstalled ( ) && ! $ this -> install ( $ module , $ recollect , false ) ) { return false ; } } return $ manager -> enable ( $ module , $ action , $ callback ) ; }
Enable a module

@param   Module $module
@param   boolean $recollect (optional)
@param   boolean $recursive (optional)

@return  boolean
Enable a module