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));
     });
 }
예제 #2
0
 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);
 }
예제 #3
0
 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());
 }
예제 #5
0
 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);
 }
예제 #6
0
 public function __construct()
 {
     $settings = (require "../settings.php");
     if (isset($settings['model'])) {
         $this->data = $settings['model'];
     }
     parent::__construct($settings);
 }
예제 #7
0
 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);
 }
예제 #8
0
 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();
 }
예제 #9
0
 /**
  * @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();
 }
예제 #10
0
파일: ProducerTest.php 프로젝트: WTer/NJB
 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();
 }
예제 #11
0
 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);
 }
예제 #12
0
 /**
  * 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);
 }
예제 #13
0
파일: Tacit.php 프로젝트: vgrish/tacit
 /**
  * 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();
     });
 }
예제 #14
0
 /**
  * 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();
 }
예제 #15
0
 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();
 }
예제 #16
0
 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);
 }
예제 #17
0
 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'];
 }
예제 #18
0
파일: App.php 프로젝트: jamwaffles/pliers
 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();
 }
예제 #19
0
 /**
  * @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');
         }
     }
 }
예제 #20
0
 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  ******/
     /*******************************/
 }
예제 #21
0
파일: App.php 프로젝트: alnetosilva/novosga
 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');
     });
 }
예제 #22
0
 /**
  * コンストラクタ
  * 
  * @param type $config
  * @param type $loader
  */
 public function __construct($config = null, $loader = null)
 {
     $this->loader = $loader;
     parent::__construct($config);
 }
예제 #23
0
 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();
     });
 }
예제 #24
0
파일: App.php 프로젝트: netdust/ntdst-cms
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     parent::__construct($userSettings);
 }
예제 #25
0
파일: Core.php 프로젝트: JSchwehn/Slim
 public function __construct($config)
 {
     parent::__construct($config);
     $this->initApp();
     return $this;
 }
예제 #26
0
파일: api.php 프로젝트: aodkrisda/mayotin
 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();
     });
 }
예제 #27
0
 /**
  * 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;
 }
예제 #28
0
파일: App.php 프로젝트: NiusFramework/core
 public function __construct(array $userSettings)
 {
     parent::__construct($userSettings);
     $this->setRoutes();
 }
예제 #29
0
 /**
  * Constructeur par défaut de la class Main
  * #WeirdSyntax
  */
 public function __construct()
 {
     parent::__construct(['debug' => true]);
     $this->initWhoops();
 }
예제 #30
0
 /**
  * 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;
 }