<commit_before><?php

namespace Contentify;

use Cache;
use RuntimeException;
use View;

/**
 * Backend navigation generator class - generates the navigation of the backend 
 * automatically based upon the settings of the available modules. Caches the result
 * to increase the performance.
 */
class BackendNavGenerator
{

    /**
     * How many navigation categories are there?
     */
    const MAX_NAVCATS = 4;

    /**
     * Name of the cache key
     */
    const CACHE_KEY = 'app.backNavTemplate';

    /**
     * The current locale, for example 'en'
     *
     * @var string
     */
    protected $locale = null;

    public function __construct()
    {
        $session = app('session');
        $this->locale = $session->get('app.locale');
    }

    /**
     * Returns the navigation items
     * 
     * @return mixed[][] Array with arrays of navigation items
     */
    public function getItems() : array
    {
        $translator = app('translator');
        $moduleBase = app()['modules'];
        $modules = $moduleBase->all(); // Retrieve all module info objects

        $navItems = [];
        foreach ($modules as $module) {
            if (! $module['enabled']) continue;

            if (isset($module['admin-nav'])) {
                $moduleNavItems = $module['admin-nav'];

                $counter = 0;
                foreach ($moduleNavItems as $moduleNavItem) {
                    /*
                     * Set default values for... well for everything.
                     */
                    if (! isset($moduleNavItem['url'])) {
                        $counter++;
                        if ($counter > 1) {
                            throw new RuntimeException(
                                'Module "'.$module['slug'].'" tries to provide two navigation items with the same URL.'
                            );
                        }
                        $moduleNavItem['url'] = 'admin/'.strtolower($module['slug']);
                    }
                    if (! isset($moduleNavItem['title'])) {
                        $moduleNavItem['title'] = $module['slug'];
                    }
                    if (! isset($moduleNavItem['position'])) {
                        $moduleNavItem['position'] = 999;
                    }
                    if (! isset($moduleNavItem['category'])) {
                        $moduleNavItem['category'] = 1;
                    }
                    if (! isset($moduleNavItem['icon'])) {
                        $moduleNavItem['icon'] = 'newspaper.png';
                    }

                    if (! isset($moduleNavItem['translate']) or $moduleNavItem['translate'] === false) {
                        $key = 'app.object_'.snake_case($moduleNavItem['title']);
                        if ($translator->has($key)) {
                            $moduleNavItem['title'] = $translator->get($key);
                        }
                    } else {
                        $key = $moduleNavItem['translate'];
                        if ($translator->has($key)) {
                            $moduleNavItem['title'] = $translator->get($key);
                        }
                    }

                    $navItems[] = $moduleNavItem;
                }
            }
        }
        return $navItems;<commit_msg>Added event<commit_after><?php

namespace Contentify;

use Cache;
use RuntimeException;
use View;

/**
 * Backend navigation generator class - generates the navigation of the backend 
 * automatically based upon the settings of the available modules. Caches the result
 * to increase the performance.
 */
class BackendNavGenerator
{
    /**
     * Name of the event when the items for the navigation are collected
     */
    const EVENT_NAME_GET_ITEMS = 'contentify.backendNavGenerator.getItems';

    /**
     * How many navigation categories are there?
     */
    const MAX_NAVCATS = 4;

    /**
     * Name of the cache key
     */
    const CACHE_KEY = 'app.backNavTemplate';

    /**
     * The current locale, for example 'en'
     *
     * @var string
     */
    protected $locale = null;

    public function __construct()
    {
        $session = app('session');
        $this->locale = $session->get('app.locale');
    }

    /**
     * Returns the navigation items
     * 
     * @return mixed[][] Array with arrays of navigation items
     */
    public function getItems() : array
    {
        $translator = app('translator');
        $moduleBase = app()['modules'];
        $modules = $moduleBase->all(); // Retrieve all module info objects

        $navItems = [];
        foreach ($modules as $module) {
            if (! $module['enabled']) continue;

            if (isset($module['admin-nav'])) {
                $moduleNavItems = $module['admin-nav'];

                $counter = 0;
                foreach ($moduleNavItems as $moduleNavItem) {
                    /*
                     * Set default values for... well for everything.
                     */
                    if (! isset($moduleNavItem['url'])) {
                        $counter++;
                        if ($counter > 1) {
                            throw new RuntimeException(
                                'Module "'.$module['slug'].'" tries to provide two navigation items with the same URL.'
                            );
                        }
                        $moduleNavItem['url'] = 'admin/'.strtolower($module['slug']);
                    }
                    if (! isset($moduleNavItem['title'])) {
                        $moduleNavItem['title'] = $module['slug'];
                    }
                    if (! isset($moduleNavItem['position'])) {
                        $moduleNavItem['position'] = 999;
                    }
                    if (! isset($moduleNavItem['category'])) {
                        $moduleNavItem['category'] = 1;
                    }
                    if (! isset($moduleNavItem['icon'])) {
                        $moduleNavItem['icon'] = 'newspaper.png';
                    }

                    if (! isset($moduleNavItem['translate']) or $moduleNavItem['translate'] === false) {
                        $key = 'app.object_'.snake_case($moduleNavItem['title']);
                        if ($translator->has($key)) {
                            $moduleNavItem['title'] = $translator->get($key);
                        }
                    } else {
                        $key = $moduleNavItem['translate'];
                        if ($translator->has($key)) {
                            $moduleNavItem['title'] = $translator->get($key);
                        }
                    }

                    $navItems[] = $moduleNavItem;
                }
            }
        }
        
        event(self::EVENT_NAME_GET_ITEMS, [$navItems]);
        
        return $navItems;
{'fraction_non_alphanumeric': 0.1256735109946119, 'fraction_numerical': 0.0020387359836901123, 'mean_word_length': 1.3368492684586595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '4649504', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1601, 'n_words': 387}