<commit_before><?php

namespace Pagekit\Site;

use Pagekit\Application as App;
use Pagekit\Module\Module;
use Pagekit\Site\Entity\Node;

class SiteModule extends Module
{
    protected $types;
    protected $menus;
    protected $frontpage;

    /**
     * {@inheritdoc}
     */
    public function main(App $app)
    {
        $app['node'] = function ($app) {
            if ($id = $app['request']->attributes->get('_node') and $node = Node::find($id)) {
                return $node;
            }

            return new Node;
        };
    }

    /**
     * @param  string $type
     * @return array
     */
    public function getType($type)
    {
        $types = $this->getTypes();

        return isset($types[$type]) ? $types[$type] : null;
    }

    /**
     * @return array
     */
    public function getTypes()
    {
        if (!$this->types) {

            foreach (App::module() as $module) {
                foreach ((array) $module->get('nodes') as $type => $route) {
                    $this->registerType($type, $route);
                }
            }

            $this->registerType('alias', ['label' => __('Alias')]);

            App::trigger('site.types', [$this]);
        }

        return $this->types;
    }

    /**
     * Register a node type.
     *
     * @param string $type
     * @param array  $route
     */
    public function registerType($type, array $route)
    {
        $route['id'] = $type;
        $this->types[$type] = $route;
    }

    /**
     * @param  string $id
     * @return array
     */
    public function getMenu($id)
    {
        $menus = $this->getMenus();

        return isset($menus[$id]) ? $menus[$id] : null;
    }

    /**
     * @return array[]
     */
    public function getMenus()
    {
        if (!$this->menus) {

            foreach (App::module() as $module) {
                foreach ((array) $module->get('menus') as $id => $menu) {
                    $this->registerMenu($id, $menu, ['fixed' => true]);
                }
            }

            foreach ($this->config('menus') as $menu) {
                $this->registerMenu($menu['id'], $menu['label']);
            }

            App::trigger('site.menus', [$this]);
        }

        return $this->menus;
    }

    /**
     * Registers a menu.
     *
     * @param string $id
     * @param string $label
     * @param array  $options
     */
    public function registerMenu($id, $label, array $options = [])
    {
        $this->menus[$id] = array_merge($options, compact('id', 'label'));
    }

    /**<commit_msg>added "ghost" menus<commit_after><?php

namespace Pagekit\Site;

use Pagekit\Application as App;
use Pagekit\Module\Module;
use Pagekit\Site\Entity\Node;

class SiteModule extends Module
{
    protected $types;
    protected $menus;
    protected $frontpage;

    /**
     * {@inheritdoc}
     */
    public function main(App $app)
    {
        $app['node'] = function ($app) {
            if ($id = $app['request']->attributes->get('_node') and $node = Node::find($id)) {
                return $node;
            }

            return new Node;
        };
    }

    /**
     * @param  string $type
     * @return array
     */
    public function getType($type)
    {
        $types = $this->getTypes();

        return isset($types[$type]) ? $types[$type] : null;
    }

    /**
     * @return array
     */
    public function getTypes()
    {
        if (!$this->types) {

            foreach (App::module() as $module) {
                foreach ((array) $module->get('nodes') as $type => $route) {
                    $this->registerType($type, $route);
                }
            }

            $this->registerType('alias', ['label' => __('Alias')]);

            App::trigger('site.types', [$this]);
        }

        return $this->types;
    }

    /**
     * Register a node type.
     *
     * @param string $type
     * @param array  $route
     */
    public function registerType($type, array $route)
    {
        $route['id']        = $type;
        $this->types[$type] = $route;
    }

    /**
     * @param  string $id
     * @return array
     */
    public function getMenu($id)
    {
        $menus = $this->getMenus();

        return isset($menus[$id]) ? $menus[$id] : null;
    }

    /**
     * @return array[]
     */
    public function getMenus()
    {
        if (!$this->menus) {

            foreach (App::module() as $module) {
                foreach ((array) $module->get('menus') as $id => $menu) {
                    $this->registerMenu($id, $menu, ['fixed' => true]);
                }
            }

            foreach ($this->config('menus') as $menu) {
                $this->registerMenu($menu['id'], $menu['label']);
            }

            App::trigger('site.menus', [$this]);

            foreach (App::db()->createQueryBuilder()
                         ->from('@system_node')
                         ->where('menu <> ""')
                         ->whereIn('menu', array_keys($this->menus), true)
                         ->groupBy('menu')->execute('menu')
                         ->fetchAll(\PDO::FETCH_COLUMN) as $menu
            ) {
                $this->registerMenu($menu, $menu, ['ghost' => true]);
            }
        }

        return $this->menus;
    }

    /**
     * Registers a menu.
     *
     * @param string $id
     * @param string $label
     * @param array  $options
     */
    public function registerMenu($id, $label, array $options = [])
    {
        $this->menus[$id] = array_merge($options, compact('id', 'label'));
    }

    /**
{'fraction_non_alphanumeric': 0.1706704912154894, 'fraction_numerical': 0.0, 'mean_word_length': 1.6106691623771643, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 56, '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': '4141132', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1642, 'n_words': 349}