Enable hook.

@param $name

@throws \Larapack\Hooks\Exceptions\HookNotFoundException
@throws \Larapack\Hooks\Exceptions\HookNotInstalledException
@throws \Larapack\Hooks\Exceptions\HookAlreadyEnabledException
2687
public function enable($name)
    {
        // Check if exists
        if (!$this->downloaded($name)) {
            throw new Exceptions\HookNotFoundException("Hook [{$name}] not found.");
        }

        if (!$this->installed($name)) {
            throw new Exceptions\HookNotInstalledException("Hook [{$name}] not installed.");
        }

        if ($this->enabled($name)) {
            throw new Exceptions\HookAlreadyEnabledException("Hook [{$name}] already enabled.");
        }

        $hook = $this->hook($name);

        $hook->loadJson();

        event(new Events\EnablingHook($hook));

        $this->hooks[$name]->update(['enabled' => true]);

        $this->remakeJson();

        event(new Events\EnabledHook($hook));
    }
773381
public function setDefaultHandler($name)
    {
        if (!array_key_exists($name, $this->logRegistry)) {
            throw new \Exception('LogHandler named ['.$name.'] does not exist');
        }
        $this->defaultLogHandler = $name;
    }
996491
protected static function trigger($name)
    {
        if (isset(static::$_hooks[$name])) {
            $events = [];
            
            foreach (static::$_hooks[$name] as $hookEvent) {
                if ($hookEvent->isHandled) {
                    continue;
                }
                
                if (is_array($hookEvent->handler)) {
                    $hookEvent->output = call_user_func_array($hookEvent->handler, [$hookEvent]);
                } elseif (is_callable($hookEvent->handler)) {
                    $hookEvent->output = call_user_func($hookEvent->handler, $hookEvent);
                } else {
                    throw new Exception("The provided hook event handler is not valid.");
                }
                
                $hookEvent->isHandled = true;
                
                if ($hookEvent->isValid) {
                    $events[] = $hookEvent;
                }
            }

            return $events;
        }

        return [];
    }
193680
public function applyChain($name, $hookArg = null)
    {
        $hooks = $this->app->getHooks();

        if (!isset($hooks[$name])) {
            $hooks[$name] = array(array());
        }
        if (!empty($hooks[$name])) {
            // Sort by priority, low to high, if there's more than one priority
            if (count($hooks[$name]) > 1) {
                ksort($hooks[$name]);
            }
            foreach ($hooks[$name] as $priority) {
                if (!empty($priority)) {
                    foreach ($priority as $callable) {
                        $value = call_user_func($callable, $hookArg);
                        if ($value !== null) {
                            return $value;
                        }
                    }
                }
            }
        }
    }
1168033
public function enableFilter($name) {
        if ( ! is_array($name)) {
            $name = [$name];
        }

        $this->getRoutesMatcher()->getFiltersMatcher()
            ->enableFilters($name);

        return $this;
    }
1056248
public function assertIsInjectable(string $name)
    {
        $injectable = true;

        $message = "The class '$name' couldn't be automatically injected.";

        try {
            $class = $this->makeInjectableClass($name);
            $this->assertInstanceOf($name, $class->getInjectedObject());
        } catch (Exception $e) {
            $injectable = false;
            if ($msg = $e->getMessage()) {
                $message .= " $msg";
            }
        }

        $this->assertTrue($injectable, $message);
    }
408306
protected function setPluginRootFile(string $name)
    {
        $this->info('Set plugin root file...');
        $this->files->move($this->path($name.'/plugin-name.php'), $this->path($name.'/'.$name.'.php'));
    }
877824
public function configureHook(Config\Hook $config, string $name) : void
    {
        $answer = $this->io->ask('  <info>Enable \'' . $name . '\' hook?</info> <comment>[y,n]</comment> ', 'n');
        $enable = IOUtil::answerToBool($answer);

        $config->setEnabled($enable);

        if ($enable) {
            $addAction = $this->io->ask('  <info>Add a validation action?</info> <comment>[y,n]</comment> ', 'n');

            while (IOUtil::answerToBool($addAction)) {
                $config->addAction($this->getActionConfig());
                // add another action?
                $addAction = $this->io->ask(
                    '  <info>Add another validation action?</info> <comment>[y,n]</comment> ',
                    'n'
                );
            }
        }
    }
38842
public function enable(string $name) : BsonFilter
    {
        if (! $this->has($name)) {
            throw new InvalidArgumentException("Filter '" . $name . "' does not exist.");
        }

        if (! $this->isEnabled($name)) {
            $filterClass      = $this->config->getFilterClassName($name);
            $filterParameters = $this->config->getFilterParameters($name);
            $filter           = new $filterClass($this->dm);

            foreach ($filterParameters as $param => $value) {
                $filter->setParameter($param, $value);
            }

            $this->enabledFilters[$name] = $filter;
        }

        return $this->enabledFilters[$name];
    }
914512
public function getHooks($name = null)
    {
        if ($name == null) {
            return $this->hooks;
        }
        return isset($this->hooks[$name]) ? $this->hooks[$name] : array();
    }
732508
protected function callHooks($name)
    {
        $hooks = Arr::get($this->hooks, $name, []);

        foreach ($hooks as $func) {
            if (!$func instanceof Closure) {
                continue;
            }

            $response = call_user_func($func, $this);

            if ($response instanceof Response) {
                return $response;
            }
        }
    }
893041
public function isEnabled($name)
    {
        foreach ($this->modules as $module) {
            if ($name === $module->title) {
                return true;
            }
        }
        return false;
    }
1210831
protected function setTagItem(string $name): void
    {
        if (!empty($this->tag)) {
            foreach ($this->tag as $tag) {
                $tagName = $this->getTagKey($tag);
                if ($this->handler->has($tagName)) {
                    $this->handler->append($tagName, ',' . $name);
                } else {
                    $this->handler->set($tagName, $name);
                }
            }

            $this->tag = null;
        }
    }
626436
public function enableFilters(array $names) {
        foreach ($names as $name) {
            $filter = array_get($this->filters, $name);

            if ( ! $filter instanceof IRouteFilter) {
                throw new FilterNotFoundException(
                    s('Filter with name %s not found.', $name)
                );
            }

            $filter->setEnabled(true);
        }
    }
945714
public function runHooks($name, AbstractContext $context, $reverse = false)
    {
        $parent = $this->getParent();
        $hooks = $this->hooks[$name];

        if ($reverse) { 
            foreach (array_reverse($hooks) as $hook) {
                $hook->run($context); 
            }
            if ($parent) {
                $parent->runHooks($name, $context, $reverse);
            }
        } else {
            if ($parent) {
                $parent->runHooks($name, $context, $reverse);
            }
            foreach ($hooks as $hook) {
                $hook->run($context); 
            }
        } 
    }
601047
public function enableSearchOperator($name)
    {
        if (isset($this->_config['operators'][":{$name}"])) {
            $this->_config['operators'][$name] = $this->_config['operators'][":{$name}"];
            unset($this->_config['operators'][":{$name}"]);
        }
    }
688517
public function uninstall($name)
    {
        $name = Container::get('hooks')->fire('model.plugin.uninstall.name', $name);
        $activePlugins = $this->manager->getActivePlugins();

        // Check if plugin is disabled, for security
        if (!in_array($name, $activePlugins)) {
            $plugin = DB::forTable('plugins')->where('name', $name)->find_one();

            if ($plugin) {
                $plugin->delete();
            }

            // Allow additional uninstalling functions
            $this->manager->uninstall($name);

            if (file_exists(ForumEnv::get('FORUM_ROOT').'plugins'.DIRECTORY_SEPARATOR.$name)) {
                AdminUtils::deleteFolder(ForumEnv::get('FORUM_ROOT').'plugins'.DIRECTORY_SEPARATOR.$name);
            }

            $this->manager->setActivePlugins();
        }
        return true;
    }