<commit_before><?php
App::uses('AppModel', 'Model');
class Dashboard extends AppModel
{
    public $useTable = false;

    public function loadWidget($name)
    {
        if (file_exists(APP . 'Lib/Dashboard/' . $name . '.php')) {
            App::uses($name, 'Dashboard');
        } else if (file_exists(APP . 'Lib/Dashboard/Custom/' . $name . '.php')) {
            App::uses($name, 'Dashboard/Custom');
        } else {
            throw new NotFoundException(__('Invalid widget or widget not found.'));
        }
        $widget = new $name();
        return $widget;
    }

    public function loadAllWidgets()
    {
        $dir = new Folder(APP . 'Lib/Dashboard');
        $customdir = new Folder(APP . 'Lib/Dashboard/Custom');
        $widgetFiles = $dir->find('.*Widget\.php');
        $customWidgetFiles = $customdir->find('.*Widget\.php');
        $widgets = array();
        foreach ($widgetFiles as $widgetFile) {
            $className = substr($widgetFile, 0, strlen($widgetFile) -4);
            $widgets[$className] = $this->__extractMeta($className, false);
        }
        foreach ($customWidgetFiles as $widgetFile) {
            $className = substr($widgetFile, 0, strlen($widgetFile) -4);
            $widgets[$className] = $this->__extractMeta($className, true);
        }
        return $widgets;
    }

    private function __extractMeta($className, $custom)
    {
        debug($className);
        debug('Dashboard' . $custom ? '/Custom' : '');
        App::uses($className, 'Dashboard' . $custom ? '/Custom' : '');
        $widgetClass = new $className();
        $widget = array(
            'widget' => $className,
            'title' => $widgetClass->title,
            'render' => $widgetClass->render,
            'params' => empty($widgetClass->params) ? array() : $widgetClass->params,
            'description' => empty($widgetClass->description) ?  $widgetClass->title : $widgetClass->description,
            'height' => empty($widgetClass->height) ? 1 : $widgetClass->height,
            'width' => empty($widgetClass->width) ? 1 : $widgetClass->width,
            'placeholder' => empty($widgetClass->placeholder) ? '' : $widgetClass->placeholder
        );
        return $widget;
    }
}<commit_msg>fix: [dashboard] custom routing fixed<commit_after><?php
App::uses('AppModel', 'Model');
class Dashboard extends AppModel
{
    public $useTable = false;

    public function loadWidget($name)
    {
        if (file_exists(APP . 'Lib/Dashboard/' . $name . '.php')) {
            App::uses($name, 'Dashboard');
        } else if (file_exists(APP . 'Lib/Dashboard/Custom/' . $name . '.php')) {
            App::uses($name, 'Dashboard/Custom');
        } else {
            throw new NotFoundException(__('Invalid widget or widget not found.'));
        }
        $widget = new $name();
        return $widget;
    }

    public function loadAllWidgets()
    {
        $dir = new Folder(APP . 'Lib/Dashboard');
        $customdir = new Folder(APP . 'Lib/Dashboard/Custom');
        $widgetFiles = $dir->find('.*Widget\.php');
        $customWidgetFiles = $customdir->find('.*Widget\.php');
        $widgets = array();
        foreach ($widgetFiles as $widgetFile) {
            $className = substr($widgetFile, 0, strlen($widgetFile) -4);
            $widgets[$className] = $this->__extractMeta($className, false);
        }
        foreach ($customWidgetFiles as $widgetFile) {
            $className = substr($widgetFile, 0, strlen($widgetFile) -4);
            $widgets[$className] = $this->__extractMeta($className, true);
        }
        return $widgets;
    }

    private function __extractMeta($className, $custom)
    {
        App::uses($className, 'Dashboard' . ($custom ? '/Custom' : ''));
        $widgetClass = new $className();
        $widget = array(
            'widget' => $className,
            'title' => $widgetClass->title,
            'render' => $widgetClass->render,
            'params' => empty($widgetClass->params) ? array() : $widgetClass->params,
            'description' => empty($widgetClass->description) ?  $widgetClass->title : $widgetClass->description,
            'height' => empty($widgetClass->height) ? 1 : $widgetClass->height,
            'width' => empty($widgetClass->width) ? 1 : $widgetClass->width,
            'placeholder' => empty($widgetClass->placeholder) ? '' : $widgetClass->placeholder
        );
        return $widget;
    }
}
{'fraction_non_alphanumeric': 0.16681715575620767, 'fraction_numerical': 0.002708803611738149, 'mean_word_length': 2.4536243180046764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '6475347', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1243, 'n_words': 258}