<commit_before><?php
/**
 * @author <NAME> <<EMAIL>>
 */

namespace WS\Tools;

use Bitrix\Main\Application;
use Bitrix\Main\Data\CacheEngineFiles;
use WS\Tools\Cache\CacheManager;
use WS\Tools\ClassLoader\ClassLoader;
use WS\Tools\ClassLoader\PSR0ClassLoaderDriver;
use WS\Tools\ClassLoader\PSR4ClassLoaderDriver;
use WS\Tools\Events\EventsManager;
use WS\Tools\Mail\MailService;
use WS\Tools\ORM\Db\Manager;
use WS\Tools\Services\ServicesLocator;

/**
 * Class Module
 * namespace WS\Tools
 * pattern Singleton
 */

class Module {

    const MODULE_ID = 'ws.tools';
    const ITEMS_ID = 'ws_tools_menu';
    const MODULE_NAME = 'ws.tools';
    const FALLBACK_LOCALE = 'ru';

    private $localizePath = null;
    private $localizations = array();
    private static  $name = self::MODULE_NAME;

    /**
     * @var ServicesLocator
     */
    private $_servicesLocator;

    private function __construct() {
        $this->localizePath = __DIR__.'/../lang/'.LANGUAGE_ID;

        if (!file_exists($this->localizePath)) {
            $this->localizePath = __DIR__.'/../lang/'.self::FALLBACK_LOCALE;
        }

        $this->_servicesLocator = new ServicesLocator();
        $this->_servicesLocator->willUse('eventManager', new EventsManager());
        $this->_servicesLocator->willUse('classLoader', new ClassLoader(array(
            'drivers' => array(
                "psr4" => new PSR4ClassLoaderDriver(),
                "psr0" => new PSR0ClassLoaderDriver()
            )
        )));
        $this->_servicesLocator->willUse('cache', new CacheManager(array(
            'engine' => new CacheEngineFiles()
        )));
        $this->_servicesLocator->willUse('mail', new MailService());
    }

    /**
     * Setup params to configure module
     * @param $params
     */
    public function config($params) {
        foreach ($params as $name => $value) {
            $this->configSection($name, $value);
        }
    }

    /**
     * Setup params section to configure
     * @param $name
     * @param $value
     */
    public function configSection($name, $value) {
        if ($name == 'services') {
            $this->_servicesLocator->configure($value);
        }
        if ($name == 'autoload') {
            $this->classLoader()->configure($value);
        }
    }

    /**<commit_msg>ORM сервис. Определение в сервиса в модуле по умолчанию.<commit_after><?php
/**
 * @author <NAME> <<EMAIL>>
 */

namespace WS\Tools;

use Bitrix\Main\Application;
use Bitrix\Main\Data\CacheEngineFiles;
use WS\Tools\Cache\CacheManager;
use WS\Tools\ClassLoader\ClassLoader;
use WS\Tools\ClassLoader\PSR0ClassLoaderDriver;
use WS\Tools\ClassLoader\PSR4ClassLoaderDriver;
use WS\Tools\Events\EventsManager;
use WS\Tools\Mail\MailService;
use WS\Tools\ORM\Db\Manager;
use WS\Tools\Services\ServicesLocator;

/**
 * Class Module
 * namespace WS\Tools
 * pattern Singleton
 */

class Module {

    const MODULE_ID = 'ws.tools';
    const ITEMS_ID = 'ws_tools_menu';
    const MODULE_NAME = 'ws.tools';
    const FALLBACK_LOCALE = 'ru';

    private $localizePath = null;
    private $localizations = array();
    private static  $name = self::MODULE_NAME;

    /**
     * @var ServicesLocator
     */
    private $_servicesLocator;

    private function __construct() {
        $this->localizePath = __DIR__.'/../lang/'.LANGUAGE_ID;

        if (!file_exists($this->localizePath)) {
            $this->localizePath = __DIR__.'/../lang/'.self::FALLBACK_LOCALE;
        }

        $this->_servicesLocator = new ServicesLocator();
        $this->_servicesLocator->willUse('eventManager', new EventsManager());
        $this->_servicesLocator->willUse('classLoader', new ClassLoader(array(
            'drivers' => array(
                "psr4" => new PSR4ClassLoaderDriver(),
                "psr0" => new PSR0ClassLoaderDriver()
            )
        )));
        $this->_servicesLocator->willUse('cache', new CacheManager(array(
            'engine' => new CacheEngineFiles()
        )));
        $this->_servicesLocator->willUse('mail', new MailService());
        $this->_servicesLocator->willUse('orm', new Manager($this->cacheManager()));
    }

    /**
     * Setup params to configure module
     * @param $params
     */
    public function config($params) {
        foreach ($params as $name => $value) {
            $this->configSection($name, $value);
        }
    }

    /**
     * Setup params section to configure
     * @param $name
     * @param $value
     */
    public function configSection($name, $value) {
        if ($name == 'services') {
            $this->_servicesLocator->configure($value);
        }
        if ($name == 'autoload') {
            $this->classLoader()->configure($value);
        }
    }

    /**
{'fraction_non_alphanumeric': 0.1451476793248945, 'fraction_numerical': 0.002531645569620253, 'mean_word_length': 2.60532319391635, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1946476', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1421, 'n_words': 277}