<commit_before><?php
namespace MapasCulturais;

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
 * MapasCulturais Application class.
 *
 *
 * @property-read \Doctrine\ORM\EntityManager $em The Doctrine Entity Manager
 * @property-read \Slim\Log $log Slim Logger
 * @property-read \Doctrine\Common\Cache\CacheProvider $cache Cache Provider
 * @property-read \Doctrine\Common\Cache\ArrayCache $rcache Runtime Cache Provider
 * @property-read \MapasCulturais\AuthProvider $auth The Authentication Manager Component.
 * @property-read \MapasCulturais\View $view The MapasCulturais View object
 * @property-read \MapasCulturais\Storage\FileSystem $storage File Storage Component.
 * @property-read \MapasCulturais\Entities\User $user The Logged in user.
 * @property-read String $projectRegistrationAgentRelationGroupName Project Registration Agent Relation Group Name
 *
 * From Slim Class Definition
 * @property-read array[\Slim] $apps = array()
 * @property-read string $name The Slim Application name
 * @property-read array $environment
 * @property-read \Slim\Http\Request $request
 * @property-read \Slim\Http\Response $response
 * @property-read \Slim\Router $router
 * @property-read array $settings
 * @property-read string $mode
 * @property-read array $middleware
 * @property-read mixed $error Callable to be invoked if application error
 * @property-read mixed $notFound Callable to be invoked if no matching routes are found
 *
 * @property-read array $config
 *
 * @method \MapasCulturais\App i() Returns the application object
 */
class App extends \Slim\Slim{
    use \MapasCulturais\Traits\MagicGetter,
        \MapasCulturais\Traits\Singleton;

    /**
     * Is the App initiated?
     * @var boolean
     */
    protected $_initiated = false;

    /**
     * Doctrine Entity Manager
     * @var \Doctrine\ORM\EntityManager
     */
    protected $_em = null;

    /**
     * Cache Component
     * @var \Doctrine\Common\Cache\CacheProvider
     */
    protected $_cache = null;

    /**
     * Runtime Cache
     * @var \Doctrine\Common\Cache\ArrayCache
     */
    protected $_rcache = null;

    /**
     * The MapasCulturais Auth Manager.
     * @var \MapasCulturais\Auth
     */
    protected $_auth = null;

    /**
     * The Route Manager.
     * @var \MapasCulturais\RouteManager
     */
    protected $_routesManager = null;

    /**
     * File Storage Component
     * @var \MapasCulturais\Storage
     */
    protected $_storage = null;


    protected $_debugbar = null;

    /**
     * App Configuration.
     * @var array
     */
    protected $_config = array();

    /**
     *
     * @var type
     */
    protected $_enqueuedScripts = array();

    /**
     *
     * @var type
     */
    protected $_enqueuedStyles = array();

    protected $_runningUpdates = false;

    /**
     * The Application Registry.
     *
     * Here is stored the registered controllers, entity types, entity type groups, entity metadata definitions, file groups definitions and taxonomy definitions.
     *
     * @var type
     */
    public $_register = array();

    protected $_registerLocked = true;



	protected $_hooks = array();
	protected $_excludeHooks = array();


    /**
     * Initializes the application instance.
     *
     * This method
     * starts the session,
     * call Slim constructor,
     * set the custom log writer (if is defined in config),
     * bootstraps the Doctrine,
     * bootstraps the Auth Manager,
     * creates the cache and rcache components,
     * sets the file storage,
     * adds midlewares,
     * instantiates the Route Manager and
     * includes the theme.php file of the active theme if the file exists.
     *
     *
     * If the application was previously initiated, this method returns the application in the first line.
     *
     * @return \MapasCulturais\App
     */
    public function init($config = array()){

        if($this->_initiated)
            return $this;

        $this->_initiated = true;

        if($config['slim.debug'])
            error_reporting(E_ALL ^ E_STRICT);

        session_start();

        $config['app.mode'] = key_exists('app.mode', $config) ? $config['app.mode'] : 'production';

        $this->_config = $config;

        $this->_config['path.layouts'] = APPLICATION_PATH.'themes/active/layouts/';
        $this->_config['path.templates'] = APPLICATION_PATH.'themes/active/views/';
        $this->_config['path.metadata_inputs'] = APPLICATION_PATH.'themes/active/metadata-inputs/';

        if(!key_exists('app.sanitize_filename_function', $this->_config))
                $this->_config['app.sanitize_filename_function'] = null;

        parent::__construct(array(
            'log.level' => $config['slim.log.level'],
            'log.enabled' => $config['slim.log.enabled'],
            'debug' => $config['slim.debug'],
            'templates.path' => $this->_config['path.templates'],
            'view' => new View(),
            'mode' => $this->_config['app.mode']
        ));

        $config = $this->_config;

        // custom log writer
        if(isset($config['slim.log.writer']) && is_object($config['slim.log.writer']) && method_exists($config['slim.log.writer'], 'write')){
            $log = $this->getLog();
            $log->setWriter($config['slim.log.writer']);
        }


        if(key_exists('app.debugbar', $config) && $config['app.debugbar'] && !$this->request->isAjax()){
            $this->_debugbar = new \DebugBar\StandardDebugBar();

            $log = $this->getLog();
            $log->setWriter(new \MapasCulturais\Loggers\Slim\DebugBar());

            $debugbarRenderer = $this->_debugbar->getJavascriptRenderer();
            $debugbarRenderer->setBaseUrl($this->getAssetUrl().'/debugbar/');

            $this->_debugbar["messages"]->addMessage("DebugBar inicializando...!");

            $this->hook('mapasculturais.scripts', function() use ($debugbarRenderer) {
                echo $debugbarRenderer->renderHead();
            });

            $this->hook('mapasculturais.body:after', function() use ($debugbarRenderer) {
                echo $debugbarRenderer->render();
            });
        }


        // ========== BOOTSTRAPING DOCTRINE ========== //
        // annotation driver
        $doctrine_config = Setup::createConfiguration($config['doctrine.isDev']);

        $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
        $classLoader->register();

        $driver = new AnnotationDriver(new AnnotationReader());

        $driver->addPaths(array(__DIR__ . '/Entities/'));

        // tells the doctrine to ignore hook annotation.
        AnnotationReader::addGlobalIgnoredName('hook');

        // driver must be pdo_pgsql
        $config['doctrine.database']['driver'] = 'pdo_pgsql';

        // registering noop annotation autoloader - allow all annotations by default
        AnnotationRegistry::registerLoader('class_exists');
        $doctrine_config->setMetadataDriverImpl($driver);

        $proxy_dir = APPLICATION_PATH . 'lib/MapasCulturais/DoctrineProxies';
        $proxy_namespace = 'MapasCulturais\DoctrineProxies';

        $doctrine_config->setProxyDir($proxy_dir);
        $doctrine_config->setProxyNamespace($proxy_namespace);
        \Doctrine\ORM\Proxy\Autoloader::register($proxy_dir, $proxy_namespace);

        /** DOCTRINE2 SPATIAL */

        $doctrine_config->addCustomStringFunction('st_asbinary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsBinary');
        $doctrine_config->addCustomStringFunction('st_astext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText');
        $doctrine_config->addCustomNumericFunction('st_area', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea');
        $doctrine_config->addCustomStringFunction('st_centroid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid');
        $doctrine_config->addCustomStringFunction('st_closestpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint');
        $doctrine_config->addCustomNumericFunction('st_contains', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains');
        $doctrine_config->addCustomNumericFunction('st_containsproperly', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContainsProperly');
        $doctrine_config->addCustomNumericFunction('st_covers', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCovers');
        $doctrine_config->addCustomNumericFunction('st_coveredby', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCoveredBy');
        $doctrine_config->addCustomNumericFunction('st_crosses', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCrosses');
        $doctrine_config->addCustomNumericFunction('st_disjoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDisjoint');
        $doctrine_config->addCustomNumericFunction('st_distance', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistance');
        $doctrine_config->addCustomStringFunction('st_envelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STEnvelope');
        $doctrine_config->addCustomStringFunction('st_geomfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText');
        $doctrine_config->addCustomNumericFunction('st_length', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength');
        $doctrine_config->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineCrossingDirection');
        $doctrine_config->addCustomStringFunction('st_startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint');
        $doctrine_config->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary');


        $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\Types\DoctrineMap\STDWithin');
        $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\Types\DoctrineMap\STMakePoint');

        $doctrine_config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());

        // obtaining the entity manager
        $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config);

        \MapasCulturais\Types\DoctrineMap\Frequency::register();

        \MapasCulturais\Types\DoctrineMap\Point::register();
        \MapasCulturais\Types\DoctrineMap\Geography::register();
        \MapasCulturais\Types\DoctrineMap\Geometry::register();




        if(@$config['app.log.query'])
            $doctrine_config->setSQLLogger($config['app.queryLogger']);

        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'geography');
        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'geometry');


        // =============== CACHE =============== //
        if(key_exists('app.cache', $config) && is_object($config['app.cache'])  && is_subclass_of($config['app.cache'], '\Doctrine\Common\Cache\CacheProvider')){
            $this->_cache = $config['app.cache'];
        }else{
            $this->_cache = new \Doctrine\Common\Cache\ArrayCache ();
        }



        // creates runtime cache component
        $this->_rcache = new \Doctrine\Common\Cache\ArrayCache ();

        // ===================================== //



        // ============= STORAGE =============== //
        if(key_exists('storage.driver', $config) && class_exists($config['storage.driver']) && is_subclass_of($config['storage.driver'], '\MapasCulturais\Storage')){
            $storage_class = $config['storage.driver'];
            $this->_storage = key_exists('storage.config', $config) ? $storage_class::i($config['storage.config']) : $storage_class::i();
        }else{
            $this->_storage = \MapasCulturais\Storage\FileSystem::i();
        }
        // ===================================== //



        // add middlewares
        if(is_array($config['slim.middlewares']))
            foreach($config['slim.middlewares'] as $middleware)
                $this->add($middleware);

        // instantiate the route manager
        $this->_routesManager = new RoutesManager(key_exists('routes', $config) ? $config['routes'] : array());


        // run theme theme.php
        if(file_exists(ACTIVE_THEME_PATH . 'theme.php'))
                include ACTIVE_THEME_PATH . 'theme.php';

        $this->applyHookBoundTo($this, 'mapasculturais.init');


        $this->register();

                // =============== AUTH ============== //
        $auth_class_name = $config['auth.provider'][0] === '\\' ? $config['auth.provider'] : 'MapasCulturais\AuthProviders\\' . $config['auth.provider'];

        $this->_auth = new $auth_class_name($config['auth.config']);


        $this->_auth->setCookies();

        // ===================================== //


        // don't run dbUpdates anymore
        $this->_dbUpdates();

        return $this;
    }
<commit_msg>include theme.php after instantiate authentication provider<commit_after><?php
namespace MapasCulturais;

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
 * MapasCulturais Application class.
 *
 *
 * @property-read \Doctrine\ORM\EntityManager $em The Doctrine Entity Manager
 * @property-read \Slim\Log $log Slim Logger
 * @property-read \Doctrine\Common\Cache\CacheProvider $cache Cache Provider
 * @property-read \Doctrine\Common\Cache\ArrayCache $rcache Runtime Cache Provider
 * @property-read \MapasCulturais\AuthProvider $auth The Authentication Manager Component.
 * @property-read \MapasCulturais\View $view The MapasCulturais View object
 * @property-read \MapasCulturais\Storage\FileSystem $storage File Storage Component.
 * @property-read \MapasCulturais\Entities\User $user The Logged in user.
 * @property-read String $projectRegistrationAgentRelationGroupName Project Registration Agent Relation Group Name
 *
 * From Slim Class Definition
 * @property-read array[\Slim] $apps = array()
 * @property-read string $name The Slim Application name
 * @property-read array $environment
 * @property-read \Slim\Http\Request $request
 * @property-read \Slim\Http\Response $response
 * @property-read \Slim\Router $router
 * @property-read array $settings
 * @property-read string $mode
 * @property-read array $middleware
 * @property-read mixed $error Callable to be invoked if application error
 * @property-read mixed $notFound Callable to be invoked if no matching routes are found
 *
 * @property-read array $config
 *
 * @method \MapasCulturais\App i() Returns the application object
 */
class App extends \Slim\Slim{
    use \MapasCulturais\Traits\MagicGetter,
        \MapasCulturais\Traits\Singleton;

    /**
     * Is the App initiated?
     * @var boolean
     */
    protected $_initiated = false;

    /**
     * Doctrine Entity Manager
     * @var \Doctrine\ORM\EntityManager
     */
    protected $_em = null;

    /**
     * Cache Component
     * @var \Doctrine\Common\Cache\CacheProvider
     */
    protected $_cache = null;

    /**
     * Runtime Cache
     * @var \Doctrine\Common\Cache\ArrayCache
     */
    protected $_rcache = null;

    /**
     * The MapasCulturais Auth Manager.
     * @var \MapasCulturais\Auth
     */
    protected $_auth = null;

    /**
     * The Route Manager.
     * @var \MapasCulturais\RouteManager
     */
    protected $_routesManager = null;

    /**
     * File Storage Component
     * @var \MapasCulturais\Storage
     */
    protected $_storage = null;


    protected $_debugbar = null;

    /**
     * App Configuration.
     * @var array
     */
    protected $_config = array();

    /**
     *
     * @var type
     */
    protected $_enqueuedScripts = array();

    /**
     *
     * @var type
     */
    protected $_enqueuedStyles = array();

    protected $_runningUpdates = false;

    /**
     * The Application Registry.
     *
     * Here is stored the registered controllers, entity types, entity type groups, entity metadata definitions, file groups definitions and taxonomy definitions.
     *
     * @var type
     */
    public $_register = array();

    protected $_registerLocked = true;



	protected $_hooks = array();
	protected $_excludeHooks = array();


    /**
     * Initializes the application instance.
     *
     * This method
     * starts the session,
     * call Slim constructor,
     * set the custom log writer (if is defined in config),
     * bootstraps the Doctrine,
     * bootstraps the Auth Manager,
     * creates the cache and rcache components,
     * sets the file storage,
     * adds midlewares,
     * instantiates the Route Manager and
     * includes the theme.php file of the active theme if the file exists.
     *
     *
     * If the application was previously initiated, this method returns the application in the first line.
     *
     * @return \MapasCulturais\App
     */
    public function init($config = array()){

        if($this->_initiated)
            return $this;

        $this->_initiated = true;

        if($config['slim.debug'])
            error_reporting(E_ALL ^ E_STRICT);

        session_start();

        $config['app.mode'] = key_exists('app.mode', $config) ? $config['app.mode'] : 'production';

        $this->_config = $config;

        $this->_config['path.layouts'] = APPLICATION_PATH.'themes/active/layouts/';
        $this->_config['path.templates'] = APPLICATION_PATH.'themes/active/views/';
        $this->_config['path.metadata_inputs'] = APPLICATION_PATH.'themes/active/metadata-inputs/';

        if(!key_exists('app.sanitize_filename_function', $this->_config))
                $this->_config['app.sanitize_filename_function'] = null;

        parent::__construct(array(
            'log.level' => $config['slim.log.level'],
            'log.enabled' => $config['slim.log.enabled'],
            'debug' => $config['slim.debug'],
            'templates.path' => $this->_config['path.templates'],
            'view' => new View(),
            'mode' => $this->_config['app.mode']
        ));

        $config = $this->_config;

        // custom log writer
        if(isset($config['slim.log.writer']) && is_object($config['slim.log.writer']) && method_exists($config['slim.log.writer'], 'write')){
            $log = $this->getLog();
            $log->setWriter($config['slim.log.writer']);
        }


        if(key_exists('app.debugbar', $config) && $config['app.debugbar'] && !$this->request->isAjax()){
            $this->_debugbar = new \DebugBar\StandardDebugBar();

            $log = $this->getLog();
            $log->setWriter(new \MapasCulturais\Loggers\Slim\DebugBar());

            $debugbarRenderer = $this->_debugbar->getJavascriptRenderer();
            $debugbarRenderer->setBaseUrl($this->getAssetUrl().'/debugbar/');

            $this->_debugbar["messages"]->addMessage("DebugBar inicializando...!");

            $this->hook('mapasculturais.scripts', function() use ($debugbarRenderer) {
                echo $debugbarRenderer->renderHead();
            });

            $this->hook('mapasculturais.body:after', function() use ($debugbarRenderer) {
                echo $debugbarRenderer->render();
            });
        }


        // ========== BOOTSTRAPING DOCTRINE ========== //
        // annotation driver
        $doctrine_config = Setup::createConfiguration($config['doctrine.isDev']);

        $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
        $classLoader->register();

        $driver = new AnnotationDriver(new AnnotationReader());

        $driver->addPaths(array(__DIR__ . '/Entities/'));

        // tells the doctrine to ignore hook annotation.
        AnnotationReader::addGlobalIgnoredName('hook');

        // driver must be pdo_pgsql
        $config['doctrine.database']['driver'] = 'pdo_pgsql';

        // registering noop annotation autoloader - allow all annotations by default
        AnnotationRegistry::registerLoader('class_exists');
        $doctrine_config->setMetadataDriverImpl($driver);

        $proxy_dir = APPLICATION_PATH . 'lib/MapasCulturais/DoctrineProxies';
        $proxy_namespace = 'MapasCulturais\DoctrineProxies';

        $doctrine_config->setProxyDir($proxy_dir);
        $doctrine_config->setProxyNamespace($proxy_namespace);
        \Doctrine\ORM\Proxy\Autoloader::register($proxy_dir, $proxy_namespace);

        /** DOCTRINE2 SPATIAL */

        $doctrine_config->addCustomStringFunction('st_asbinary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsBinary');
        $doctrine_config->addCustomStringFunction('st_astext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText');
        $doctrine_config->addCustomNumericFunction('st_area', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea');
        $doctrine_config->addCustomStringFunction('st_centroid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid');
        $doctrine_config->addCustomStringFunction('st_closestpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint');
        $doctrine_config->addCustomNumericFunction('st_contains', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains');
        $doctrine_config->addCustomNumericFunction('st_containsproperly', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContainsProperly');
        $doctrine_config->addCustomNumericFunction('st_covers', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCovers');
        $doctrine_config->addCustomNumericFunction('st_coveredby', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCoveredBy');
        $doctrine_config->addCustomNumericFunction('st_crosses', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCrosses');
        $doctrine_config->addCustomNumericFunction('st_disjoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDisjoint');
        $doctrine_config->addCustomNumericFunction('st_distance', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STDistance');
        $doctrine_config->addCustomStringFunction('st_envelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STEnvelope');
        $doctrine_config->addCustomStringFunction('st_geomfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText');
        $doctrine_config->addCustomNumericFunction('st_length', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength');
        $doctrine_config->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineCrossingDirection');
        $doctrine_config->addCustomStringFunction('st_startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint');
        $doctrine_config->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary');


        $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\Types\DoctrineMap\STDWithin');
        $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\Types\DoctrineMap\STMakePoint');

        $doctrine_config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());

        // obtaining the entity manager
        $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config);

        \MapasCulturais\Types\DoctrineMap\Frequency::register();

        \MapasCulturais\Types\DoctrineMap\Point::register();
        \MapasCulturais\Types\DoctrineMap\Geography::register();
        \MapasCulturais\Types\DoctrineMap\Geometry::register();




        if(@$config['app.log.query'])
            $doctrine_config->setSQLLogger($config['app.queryLogger']);

        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'geography');
        $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'geometry');


        // =============== CACHE =============== //
        if(key_exists('app.cache', $config) && is_object($config['app.cache'])  && is_subclass_of($config['app.cache'], '\Doctrine\Common\Cache\CacheProvider')){
            $this->_cache = $config['app.cache'];
        }else{
            $this->_cache = new \Doctrine\Common\Cache\ArrayCache ();
        }



        // creates runtime cache component
        $this->_rcache = new \Doctrine\Common\Cache\ArrayCache ();

        // ===================================== //



        // ============= STORAGE =============== //
        if(key_exists('storage.driver', $config) && class_exists($config['storage.driver']) && is_subclass_of($config['storage.driver'], '\MapasCulturais\Storage')){
            $storage_class = $config['storage.driver'];
            $this->_storage = key_exists('storage.config', $config) ? $storage_class::i($config['storage.config']) : $storage_class::i();
        }else{
            $this->_storage = \MapasCulturais\Storage\FileSystem::i();
        }
        // ===================================== //



        // add middlewares
        if(is_array($config['slim.middlewares']))
            foreach($config['slim.middlewares'] as $middleware)
                $this->add($middleware);

        // instantiate the route manager
        $this->_routesManager = new RoutesManager(key_exists('routes', $config) ? $config['routes'] : array());


        

        $this->applyHookBoundTo($this, 'mapasculturais.init');


        $this->register();

                // =============== AUTH ============== //
        $auth_class_name = $config['auth.provider'][0] === '\\' ? $config['auth.provider'] : 'MapasCulturais\AuthProviders\\' . $config['auth.provider'];

        $this->_auth = new $auth_class_name($config['auth.config']);


        $this->_auth->setCookies();

        // run theme theme.php
        if(file_exists(ACTIVE_THEME_PATH . 'theme.php'))
            include ACTIVE_THEME_PATH . 'theme.php';
        
        // ===================================== //


        // don't run dbUpdates anymore
        $this->_dbUpdates();

        return $this;
    }

{'fraction_non_alphanumeric': 0.15411062414991689, 'fraction_numerical': 0.0001511258878645912, 'mean_word_length': 3.257519704037317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 177, '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': '1786013', 'n_tokens_mistral': 7813, 'n_tokens_neox': 7634, 'n_words': 1245}