public function __construct(array $userSettings = array(), $configDirectory = 'config') { // Slim initialization parent::__construct($userSettings); $this->config('debug', false); $this->notFound(function () { $this->handleNotFound(); }); $this->error(function ($e) { $this->handleException($e); }); // Config $this->configDirectory = __DIR__ . '/../../' . $configDirectory; $this->config = $this->initConfig(); // /features $this->get('/features', function () { $features = new Features($this->config['features']); $this->response->headers->set('Content-Type', 'application/json'); $this->response->setBody(json_encode($features->getFeatures())); }); $this->get('/features/:id', function ($id) { $features = new Features($this->config['features']); $feature = $features->getFeature($id); if ($feature === null) { return $this->notFound(); } $this->response->headers->set('Content-Type', 'application/json'); $this->response->setBody(json_encode($feature)); }); }
function __construct($config) { parent::__construct(); $this->config = $config; $dsn = "{$config['db_host']}:{$config['db_port']}"; $this->conn = new Crate\PDO\PDO($dsn, null, null, null); }
public function __construct(array $userSettings = array()) { $this->schemaPath = $userSettings['propelToSlim']['schemaPath']; $this->schemaMap = new SchemaMap($this->schemaPath); $this->propelToSlimSettings = $userSettings['propelToSlim']; return parent::__construct($userSettings); }
public function __construct() { parent::__construct(array('mode' => getMode())); self::$_INSTANCE = $this; # add the exception middleware $this->add(new Exception_Middleware()); }
public function __construct($config) { parent::__construct(); $this->config = $config; $this->routingManager = new RoutingManager(array("cache" => dirname(__FILE__) . "/../../cache", "controllers" => dirname(__FILE__) . "/Controllers", "controller_namespace" => "App\\Controllers")); $this->add($this->routingManager); }
public function __construct() { $settings = (require "../settings.php"); if (isset($settings['model'])) { $this->data = $settings['model']; } parent::__construct($settings); }
function __construct($namespace) { parent::__construct(); $this->config('debug', true); $error_handler = array($this, 'error_handler'); $this->error($error_handler); $this->get('(/)', array($this, 'displayServiceDoc')); $this->get('/\\$metadata', array($this, 'displayMetadata')); $this->serviceDoc = new ODataServiceDoc(); $this->metadataDoc = new CSDLSchema($namespace); }
public function __construct(array $userSettings = array()) { $settings = array_unique(array_merge($this->defaultSettings, $userSettings)); parent::__construct($settings); $this->view()->parserExtensions = array(new TwigExtension()); $this->registerErrorHandler(); $this->registerHooks(); $this->registerServices(); $this->registerControllers(); $this->registerRoutes(); }
/** * @param $basePath */ public function __construct($basePath) { $this->basePath = rtrim($basePath, '/'); $dotenv = new Dotenv($this->basePath); $dotenv->load(); $config = $this->loadConfigFile('config') ?: []; parent::__construct($config); $this->loadRoutes(); $this->setupServices(); //$this->setupErrorHandler(); //$this->setupNotFound(); }
public function __construct(array $userSettings = array()) { parent::__construct($userSettings); $this->get('Product/Image/:id', function ($id) { echo "hello {$name}"; })->name('id'); echo '===__construct 0<br>'; flush(); $this->curlHandler = curl_init(); echo '===__construct 1<br>'; flush(); }
public function __construct($mode = null) { if ($mode === null) { $mode = $this->inferMode(); } parent::__construct(array('mode' => $mode)); call_user_func(function ($app) { include self::$privateDir . '/config.php'; }, $this); $this->setupServices($this); $this->setupRoutes($this); }
/** * Register all the application services, routes and middleware * * @param array $options Associative array of application settings */ public function __construct(array $options = array()) { parent::__construct($options); $container = new SlimContainer(new EwalletWebContainer($options, $this)); $this->container = $container->merge($this->container); $resolver = new Resolver(); $services = new Services($resolver, $options); $services->configure($this); $controllers = new Controllers($resolver); $controllers->register($this); $middleware = new Middleware(); $middleware->configure($this); }
/** * Construct a new instance of Tacit. * * @param string|array|null $configuration An array or file that returns an * array when included. */ public function __construct($configuration = null) { $configuration = $this->loadConfiguration($configuration); parent::__construct($configuration); $connection = $this->config('connection'); $this->configureMode('production', function () { $this->config(['log.enable' => true, 'debug' => false]); }); $this->configureMode('development', function () { $this->config(['log.enable' => false, 'debug' => true]); }); if ($connection !== null) { $this->container->singleton('repository', function () use($connection) { $dbClass = $connection['class']; return new $dbClass($connection); }); } $this->add(new ContentTypes()); $this->error(function (\Exception $e) { $resource = ['status' => 500, 'code' => $e->getCode(), 'message' => $e->getMessage()]; if ($e instanceof RestfulException) { if ($e instanceof NotFoundException) { $this->notFound(); } $resource['status'] = $e->getStatus(); $resource['description'] = $e->getDescription(); $resource['property'] = $e->getProperty(); } /* @var \Slim\Http\Response $response */ $response = $this->response; $response->headers->set('Content-Type', 'application/json'); $response->setStatus($resource['status']); if ($this->config('debug') === true) { $resource['request_duration'] = microtime(true) - $this->config('startTime'); } $response->setBody(json_encode($resource)); $this->stop(); }); $this->notFound(function () { $resource = ['status' => 404, 'message' => 'Resource not found']; /* @var \Slim\Http\Response $response */ $response = $this->response; $response->headers->set('Content-Type', 'application/json'); $response->setStatus(404); if ($this->config('debug') === true) { $resource['request_duration'] = microtime(true) - $this->config('startTime'); } $response->setBody(json_encode($resource)); $this->stop(); }); }
/** * Constructor * * @param array $settings null */ public function __construct(array $settings = null) { if (version_compare(phpversion(), '5.4.0', '<')) { throw new \RuntimeException('Slimore require PHP version >= 5.4.0'); } require __DIR__ . "/../Helper/Functions.php"; $settings = array_merge($this->defaults, $settings); if ($settings['x-framework-header']) { header('X-Framework-By: Slimore/' . $this->version); } parent::__construct($settings); date_default_timezone_set($this->config('timezone')); $this->init(); }
public function __construct($userSettings = array()) { parent::__construct($userSettings); ZiFacade::setFacadeApplication($this); ZiFacade::registerAliases(); $this->view(new \Slim\Views\Twig()); $this->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('zi/templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true); $this->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new ZiTwigExtension()); $this->container->singleton('db', function ($c) { return require ZICONFIG . '/database.php'; }); $this->setORM(); $this->setAuth(); }
public function __construct() { parent::__construct(['mode' => 'production']); // setup database connection $capsule = new \Illuminate\Database\Capsule\Manager(); $capsule->addConnection(array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'resapi', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => '')); $capsule->setAsGlobal(); $capsule->bootEloquent(); // add middleware $this->add(new MiddlewareMediatype()); $this->add(new MiddlewareAuthenticator()); // add error message $this->notFound(function () { echo json_encode(['errmsg' => 'Not Found Request']); }); Routing::setupRouting($this); }
public function __construct($config = array()) { //init slim, by default with /app/Config/* arrays if (empty($config)) { $config = (include __DIR__ . '/../App/Config/config.php'); parent::__construct($config); $this->setupDatabase(); $this->setupView(); $this->setupForms(); $this->setupWidgets(); //custom call, nothing to setup } else { parent::__construct($config); } $this->url = new \Rapyd\Helpers\Url($this); $this->url->from = $config['url_method']; }
public function __construct($routes = null) { $appConfig = array('templates.path' => realpath('../views'), 'mode' => isset($_SERVER['PLIERS_ENV']) ? $_SERVER['PLIERS_ENV'] : 'development'); if ($appConfig['mode'] === 'development') { $appConfig['debug'] = true; } else { $appConfig['debug'] = false; } parent::__construct($appConfig); if ($routes !== null) { self::$initialRoutes = $routes; } $this->addRoutes(); $this->setupConfig(); // Set up RedBean R::setup($this->conf->db->dsn, $this->conf->db->username, $this->conf->db->password); $this->app = self::getInstance(); $this->utils = new Utils(); }
/** * @param array $config * @param bool $initErrorHandler */ function __construct(array $config, $initErrorHandler = true) { // Initiate error handler if ($initErrorHandler) { ErrorHandler::init($config); } parent::__construct($config); // Bind events defined in config if (!empty($config['application.events'])) { foreach ($config['application.events'] as $arr) { $this->bind(key($arr), current($arr)); } } // Add filters defined in config if (!empty($config['application.filters'])) { foreach ($config['application.filters'] as $arr) { $this->bind(key($arr), current($arr), 'filter'); } } }
public function __construct(array $userSettings = array(), $configDirectory = 'config') { // Slim initialization parent::__construct($userSettings); $this->config('debug', false); $this->notFound(function () { $this->handleNotFound(); }); $this->error(function ($e) { $this->handleException($e); }); // Config $this->configDirectory = __DIR__ . '/../../' . $configDirectory; $this->config = $this->initConfig(); /*******************************/ /**** HERE ARE MY CLASSES ****/ /**** FEATURES ***************/ $this->get('/features', function () { // Here I get dom datas $features = new Features($this->config['features']); // Here I send to front ;-) $this->response->headers->set('Content-Type', 'application/json'); $this->response->setBody(json_encode($features->getFeatures())); }); $this->get('/features/:id', function ($id) { // Here I get dom datas $features = new Features($this->config['features']); $feature = $features->getFeature($id); if ($feature === null) { return $this->notFound(); } // Here I send to front $this->response->headers->set('Content-Type', 'application/json'); $this->response->setBody(json_encode($feature)); }); /**** OTHER STUFFS ***********/ /* ... */ /**** END OF MY CLASSES ******/ /*******************************/ }
public function __construct(array $userSettings = []) { $twig = new \Slim\Views\Twig(); $userSettings = array_merge($userSettings, ['debug' => NOVOSGA_DEV, 'cache' => NOVOSGA_CACHE, 'templates.path' => NOVOSGA_TEMPLATES, 'view' => $twig]); if (!$userSettings['debug']) { $twig->parserOptions = ['cache' => $userSettings['cache']]; } parent::__construct($userSettings); $this->view()->set('version', self::VERSION); $this->view()->parserExtensions = [new \Slim\Views\TwigExtension(), new \Twig_Extensions_Extension_I18n(), new Twig\Extensions()]; if ($userSettings['debug']) { $this->view()->parserExtensions[] = new \Twig_Extension_Debug(); } $app = $this; $app->notFound(function () use($app) { $app->render(NOVOSGA_TEMPLATES . '/error/404.html.twig'); }); $app->error(function (\Exception $e) use($app) { $app->view()->set('exception', $e); $app->render(NOVOSGA_TEMPLATES . '/error/500.html.twig'); }); }
/** * コンストラクタ * * @param type $config * @param type $loader */ public function __construct($config = null, $loader = null) { $this->loader = $loader; parent::__construct($config); }
public function __construct(array $userSettings = array()) { parent::__construct($userSettings); $this->container->singleton('user', function ($c) { return new WebUser(); }); $this->container->singleton('orm', function ($c) { require_once __DIR__ . '/../venders/NotORM/lib.php'; return NotORM::getInstance(); }); $this->container->singleton('session', function ($c) { return new WebSession(); }); }
/** * Constructor * @param array $userSettings Associative array of application settings */ public function __construct(array $userSettings = array()) { parent::__construct($userSettings); }
public function __construct($config) { parent::__construct($config); $this->initApp(); return $this; }
public function __construct(array $userSettings = array()) { parent::__construct($userSettings); $this->container->singleton('auth', function ($c) { return new AppUser(); }); $this->container->singleton('orm', function ($c) { return NotORM::getInstance(); }); $this->container->singleton('session', function ($c) { return new Session(); }); }
/** * 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']); } // =============== 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(); // ===================================== // // ========== 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->addCustomStringFunction('string_agg', 'MapasCulturais\\DoctrineMappings\\Functions\\StringAgg'); $doctrine_config->addCustomStringFunction('unaccent', 'MapasCulturais\\DoctrineMappings\\Functions\\Unaccent'); $doctrine_config->addCustomStringFunction('recurring_event_occurrence_for', 'MapasCulturais\\DoctrineMappings\\Functions\\RecurringEventOcurrenceFor'); $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\\DoctrineMappings\\Functions\\STDWithin'); $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\\DoctrineMappings\\Functions\\STMakePoint'); $doctrine_config->setQueryCacheImpl($this->_cache); // obtaining the entity manager $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config); \MapasCulturais\DoctrineMappings\Types\Frequency::register(); \MapasCulturais\DoctrineMappings\Types\Point::register(); \MapasCulturais\DoctrineMappings\Types\Geography::register(); \MapasCulturais\DoctrineMappings\Types\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'); // ============= 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'; } // ===================================== // // run plugins foreach ($config['plugins.enabled'] as $plugin) { include PLUGINS_PATH . $plugin . '.php'; } // ===================================== // if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) { $this->_dbUpdates(); } return $this; }
public function __construct(array $userSettings) { parent::__construct($userSettings); $this->setRoutes(); }
/** * Constructeur par défaut de la class Main * #WeirdSyntax */ public function __construct() { parent::__construct(['debug' => true]); $this->initWhoops(); }
/** * 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 = []) { if ($this->_initiated) { return $this; } $this->_initiated = true; if ($config['slim.debug']) { error_reporting(E_ALL ^ E_STRICT); } session_start(); if ($config['app.offline']) { $bypass_callable = $config['app.offlineBypassFunction']; if (!is_callable($bypass_callable) || !$bypass_callable()) { http_response_code(307); header('Location: ' . $config['app.offlineUrl']); } } // =============== 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(); } $this->_cache->setNamespace($config['app.cache.namespace']); spl_autoload_register(function ($class) use($config) { $cache_id = "AUTOLOAD_CLASS:{$class}"; if ($config['app.useRegisteredAutoloadCache'] && $this->cache->contains($cache_id)) { $path = $this->cache->fetch($cache_id); require_once $path; return true; } foreach ($config['namespaces'] as $namespace => $base_dir) { if (strpos($class, $namespace) === 0) { $path = str_replace('\\', '/', str_replace($namespace, $base_dir, $class) . '.php'); if (\file_exists($path)) { require_once $path; if ($config['app.useRegisteredAutoloadCache']) { $this->cache->save($cache_id, $path, $config['app.registeredAutoloadCache.lifetime']); } return true; } } } }); // extende a config with theme config files $theme_class = "\\" . $config['themes.active'] . '\\Theme'; $theme_path = $theme_class::getThemeFolder() . '/'; if (file_exists($theme_path . 'conf-base.php')) { $theme_config = (require $theme_path . 'conf-base.php'); $config = array_merge($config, $theme_config); } if (file_exists($theme_path . 'config.php')) { $theme_config = (require $theme_path . 'config.php'); $config = array_merge($config, $theme_config); } $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; } $theme_class = $config['themes.active'] . '\\Theme'; parent::__construct(['log.level' => $config['slim.log.level'], 'log.enabled' => $config['slim.log.enabled'], 'debug' => $config['slim.debug'], 'templates.path' => $this->_config['path.templates'], 'view' => new $theme_class($config['themes.assetManager']), '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']); } // creates runtime cache component $this->_rcache = new \Doctrine\Common\Cache\ArrayCache(); // ===================================== // // ========== 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([__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->addCustomStringFunction('string_agg', 'MapasCulturais\\DoctrineMappings\\Functions\\StringAgg'); $doctrine_config->addCustomStringFunction('unaccent', 'MapasCulturais\\DoctrineMappings\\Functions\\Unaccent'); $doctrine_config->addCustomStringFunction('recurring_event_occurrence_for', 'MapasCulturais\\DoctrineMappings\\Functions\\RecurringEventOcurrenceFor'); $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\\DoctrineMappings\\Functions\\STDWithin'); $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\\DoctrineMappings\\Functions\\STMakePoint'); $doctrine_config->setMetadataCacheImpl($this->_cache); $doctrine_config->setQueryCacheImpl($this->_cache); $doctrine_config->setResultCacheImpl($this->_cache); // obtaining the entity manager $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config); \MapasCulturais\DoctrineMappings\Types\Frequency::register(); \MapasCulturais\DoctrineMappings\Types\Point::register(); \MapasCulturais\DoctrineMappings\Types\Geography::register(); \MapasCulturais\DoctrineMappings\Types\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'); // ============= 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'] : []); $this->applyHookBoundTo($this, 'mapasculturais.init'); $this->register(); // =============== AUTH ============== // if ($token = $this->request()->headers->get('authorization')) { $this->_auth = new AuthProviders\JWT(['token' => $token]); } else { $auth_class_name = strpos($config['auth.provider'], '\\') !== false ? $config['auth.provider'] : 'MapasCulturais\\AuthProviders\\' . $config['auth.provider']; $this->_auth = new $auth_class_name($config['auth.config']); $this->_auth->setCookies(); } // initialize theme $this->view->init(); // ===================================== // // run plugins foreach ($config['plugins.enabled'] as $plugin) { include PLUGINS_PATH . $plugin . '.php'; } // ===================================== // if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) { $this->_dbUpdates(); } return $this; }