extranet/application/Bootstrap.php

182 lines
4.5 KiB
PHP
Raw Normal View History

2010-11-22 13:50:12 +01:00
<?php
2017-02-13 13:53:40 +01:00
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\IntrospectionProcessor;
use Monolog\Handler\BrowserConsoleHandler;
2010-11-22 13:50:12 +01:00
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
2012-07-30 11:13:34 +02:00
{
2015-10-05 17:38:02 +02:00
/**
* Set config available in all apps
*/
protected function _initConfig()
{
$config = new Zend_Config($this->getOptions());
Zend_Registry::set('config', $config);
return $config;
}
2015-10-05 17:38:02 +02:00
/**
* Init controller with modules
*/
protected function _initController()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$front->setControllerDirectory(array(
'default' => __DIR__ . '/modules/default/controllers',
'admin' => __DIR__ . '/modules/admin/controllers',
'file' => __DIR__ . '/modules/file/controllers',
2015-10-05 17:38:02 +02:00
));
return $front;
}
/**
* Initialisation global des paramètres de vue
*/
2010-11-22 13:50:12 +01:00
protected function _initViewSettings()
{
2011-01-11 09:43:13 +01:00
$this->bootstrap('view');
2012-07-30 11:13:34 +02:00
$view = $this->getResource('view');
$view->setEncoding('UTF-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Extranet Scores & Décisions');
2010-11-22 13:50:12 +01:00
}
2015-10-05 17:38:02 +02:00
/**
* Some specific route
* @return unknown
*/
2011-01-05 10:59:49 +01:00
protected function _initRouter()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
2014-12-09 12:28:12 +01:00
2011-04-28 12:24:53 +02:00
$localauthRoute = new Zend_Controller_Router_Route('localauth/', array(
2015-10-27 09:31:20 +01:00
'module' => 'default',
2011-04-28 12:24:53 +02:00
'controller' => 'user',
2015-10-27 09:31:20 +01:00
'action' => 'login'
2011-01-05 10:59:49 +01:00
));
2014-12-09 12:28:12 +01:00
$router->addRoute('localauth', $localauthRoute);
2011-04-28 12:24:53 +02:00
$printRoute = new Zend_Controller_Router_Route('editer/:action/:fichier', array(
2015-10-27 09:31:20 +01:00
'module' => 'default',
2011-04-28 12:24:53 +02:00
'controller' => 'print',
'fichier' => '',
));
$router->addRoute('print', $printRoute);
2014-12-09 12:28:12 +01:00
2014-12-12 11:04:17 +01:00
$ssoRoute = new Zend_Controller_Router_Route('sso/:partner/', array(
2015-10-27 09:31:20 +01:00
'module' => 'default',
2014-12-09 12:28:12 +01:00
'controller' => 'auth',
'action' => 'index',
));
$router->addRoute('sso', $ssoRoute);
2011-01-05 10:59:49 +01:00
return $router;
}
protected function _initLogging()
{
2012-07-30 11:13:34 +02:00
//Firebug
2011-01-07 18:16:07 +01:00
$writer = new Zend_Log_Writer_Firebug();
2011-09-27 11:13:13 +02:00
if(APPLICATION_ENV=='production') {
2012-07-30 11:13:34 +02:00
$writer->setEnabled(false);
2011-09-27 11:13:13 +02:00
}
2011-01-07 18:16:07 +01:00
$logger = new Zend_Log($writer);
Zend_Registry::set('firebug', $logger);
//Application Logger en Production
$AppLogger = new Zend_Log();
if (APPLICATION_ENV == 'production')
{
$Mail = new Zend_Mail();
$Mail->setFrom('production@scores-decisions.com')
->addTo('supportdev@scores-decisions.com');
$AppMailWriter = new Zend_Log_Writer_Mail($Mail);
$AppMailWriter->setSubjectPrependText('ERREUR');
$AppMailWriter->addFilter(Zend_Log::ERR);
$AppLogger->addWriter($AppMailWriter);
}
Zend_Registry::set('log', $AppLogger);
}
2017-02-10 16:54:46 +01:00
/**
* Logs and Debug
*/
protected function _initLogger()
{
$config = new Zend_Config($this->getOptions());
$logFile = $config->profil->path->shared.'/log/application.log';
$log = new Logger('APP');
// Console Handler
if (in_array(APPLICATION_ENV, array('development', 'staging'))) {
$log->pushHandler(new BrowserConsoleHandler());
}
// File Handler
if (APPLICATION_ENV == 'development') {
$level = Logger::DEBUG;
} else {
$level = Logger::INFO;
}
$log->pushHandler(new StreamHandler($logFile), $level);
// Processor
$log->pushProcessor(new IntrospectionProcessor());
Zend_Registry::set('logger', $log);
}
2015-10-05 17:38:02 +02:00
/**
* Init database
*/
protected function _initDb()
{
$c = Zend_Registry::get('config');
try {
$db = Zend_Db::factory($c->profil->db->sdv1);
2012-07-30 11:13:34 +02:00
$db->getConnection();
} catch ( Exception $e ) {
2012-07-30 11:13:34 +02:00
if (APPLICATION_ENV == 'development') {
echo '<pre>'; print_r($e); echo '</pre>';
2012-07-30 11:13:34 +02:00
} else {
echo "Le service rencontre actuellement un problème technique.";
}
exit;
}
2012-07-30 11:13:34 +02:00
/**
* Set the default adapter to use with all model
*/
Zend_Db_Table::setDefaultAdapter($db);
2012-07-30 11:13:34 +02:00
/**
* Set Firebug Database profiler
*/
if (APPLICATION_ENV == 'development') {
$profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
$profiler->setEnabled(true);
$db->setProfiler($profiler);
}
}
2015-10-05 17:38:02 +02:00
/**
* Init cache
*/
2012-03-15 16:56:06 +01:00
protected function _initCache()
{
2017-01-05 11:06:18 +01:00
// @todo : Remove for PHP7 Compatibility
2012-03-15 16:56:06 +01:00
//MetadataCache pour la base de données
2015-10-05 17:38:02 +02:00
$cache = Zend_Cache::factory('Core', 'Apc',
array('lifetime' => 28800, 'automatic_serialization' => true),
2013-06-03 09:17:05 +02:00
array()
);
2013-05-29 15:10:19 +02:00
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
2012-03-15 16:56:06 +01:00
}
2013-05-29 15:10:19 +02:00
}