<commit_before><?php
/**
 * Part of CoolMS Content Management System
 *
 * @copyright (c) 2011 <NAME> (http://www.slamecka.cz)
 * 
 * License within file license.txt in the root folder.
 * 
 */

namespace Application;

class ModuleManager extends \Nette\Object
{

    /** @var \Nette\DI\Container */
    private $container;

    /** @var \Nette\Caching\Cache */
    private $cache;

    /* ----------------------- CONSTRUCTOR, DESIGN -------------------------- */

    public function __construct(\Nette\DI\Container $container)
    {
        $this->container = $container;

        $linkableModules = $this->getLinkableModules();
        if ($linkableModules === null) {
            $this->buildLinkableModulesCache();
        }

        $modulesNames = $this->getModulesInfo();
        if ($modulesNames === null) {
            $this->buildModulesInfoCache();
        }
    }

    /**
     * @return Nette\Caching\Cache
     */
    private function getCache()
    {
        if ($this->cache === null)
            $this->cache = new \Nette\Caching\Cache($this->container->cacheStorage, 'ModulesCache');

        return $this->cache;
    }

    /* ----------------------------- METHODS -------------------------------- */

    /**
     * Returns views of given module
     * @param string $name
     * @return array
     */
    public function getModuleViews($name)
    {
        $modules = $this->getModulesInfo();
        return $modules[$name]['methods'];
    }

    /**
     * Calls get<$view>ViewPossibleParams from given module
     * @param string $module
     * @param string $view
     * @return mixed
     */
    public function getModuleViewParams($module, $view)
    {
        $presenter_name = "{$module}Module\\FrontendPresenter";
        $presenter = new $presenter_name($this->container);

        $method_name = 'get' . ucfirst($view) . 'ViewPossibleParams';
        return $presenter->$method_name();
    }

    public function getLinkableModules()
    {
        return $this->getCache()->load('linkableModules');
    }

    /**
     * Returns array. Key is an actual name of a presenter and value is its formal name
     * @return array
     */
    public function buildLinkableModulesCache()
    {
        $presenters = $this->container->getService('presenterTree');
        $presenters = $presenters->getPresenters();

        $links = array();
        foreach ($presenters as $presenter) {
            if ($presenter->getPresenterReflection()->hasAnnotation('module')) {
                $links[$presenter->module] = $presenter->getPresenterReflection()->getAnnotation('module')->name;
            }
        }<commit_msg>ModuleManager: Searching for CMS modules now uses list of (Nette) modules. (Not presenters as before)<commit_after><?php
/**
 * Part of CoolMS Content Management System
 *
 * @copyright (c) 2011 <NAME> (http://www.slamecka.cz)
 * 
 * License within file license.txt in the root folder.
 * 
 */

namespace Application;

class ModuleManager extends \Nette\Object
{

    /** @var \Nette\DI\Container */
    private $container;

    /** @var \Nette\Caching\Cache */
    private $cache;

    /* ----------------------- CONSTRUCTOR, DESIGN -------------------------- */

    public function __construct(\Nette\DI\Container $container)
    {
        $this->container = $container;

        $linkableModules = $this->getLinkableModules();
        if ($linkableModules === null) {
            $this->buildLinkableModulesCache();
        }

        $modulesNames = $this->getModulesInfo();
        if ($modulesNames === null) {
            $this->buildModulesInfoCache();
        }
    }

    /**
     * @return Nette\Caching\Cache
     */
    private function getCache()
    {
        if ($this->cache === null)
            $this->cache = new \Nette\Caching\Cache($this->container->cacheStorage, 'ModulesCache');

        return $this->cache;
    }

    /* ----------------------------- METHODS -------------------------------- */

    /**
     * Returns views of given module
     * @param string $name
     * @return array
     */
    public function getModuleViews($name)
    {
        $modules = $this->getModulesInfo();
        return $modules[$name]['methods'];
    }

    /**
     * Calls get<$view>ViewPossibleParams from given module
     * @param string $module
     * @param string $view
     * @return mixed
     */
    public function getModuleViewParams($module, $view)
    {
        $presenter_name = "{$module}Module\\FrontendPresenter";
        $presenter = new $presenter_name($this->container);

        $method_name = 'get' . ucfirst($view) . 'ViewPossibleParams';
        return $presenter->$method_name();
    }

    public function getLinkableModules()
    {
        return $this->getCache()->load('linkableModules');
    }

    /**
     * Returns array. Key is an actual name of a presenter and value is its formal name
     * @return array
     */
    public function buildLinkableModulesCache()
    {
        $presenterTree = $this->container->getService('presenterTree');        
        $modules = $presenterTree->getModules();

        $links = array();
        foreach ($modules as $module) {
            $presenter_name = $module . 'Module\\FrontendPresenter';
            if (class_exists($presenter_name)) {
                $presenter = new $presenter_name($this->container);
                $reflection = $presenter->getReflection();

                if ($reflection->hasAnnotation('module'))
                    $links[$module] = $reflection->getAnnotation('module')->name;
            }
        }
{'fraction_non_alphanumeric': 0.17232704402515722, 'fraction_numerical': 0.0014375561545372866, 'mean_word_length': 2.066666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '912704', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1505, 'n_words': 332}