webservice/application/Bootstrap.php
2012-03-26 13:06:21 +00:00

156 lines
4.3 KiB
PHP

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
//Initialisation global des paramètres de vue
protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->setEncoding('UTF-8');
$view->doctype('XHTML1_STRICT');
$view->headMeta()
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'fr-FR');
$view->headLink()
->appendStylesheet('/styles/reset.css', 'all')
->appendStylesheet('/styles/main.css', 'all');
$view->headScript()->appendFile('/scripts/jquery.js', 'text/javascript');
$view->headScript()->appendFile('/scripts/scripts.js', 'text/javascript');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('WebService Scores & Decisions');
}
//Initialisation global des paramètres de log
protected function _initLogging()
{
require_once 'Zend/Log.php';
require_once 'Zend/Mail.php';
$WsLogger = new Zend_Log();
$WsFileWriter = new Zend_Log_Writer_Stream(LOG_PATH.'/wsentreprise.log');
$WsFileWriter->addFilter(Zend_Log::INFO);
$WsLogger->addWriter($WsFileWriter);
if (APPLICATION_ENV == 'production')
{
$WsMail = new Zend_Mail();
$WsMail->setFrom('production@scores-decisions.com')
->addTo('mricois@scores-decisions.com');
$WsMailWriter = new Zend_Log_Writer_Mail($WsMail);
$WsMailWriter->setSubjectPrependText('ERREUR');
$WsMailWriter->addFilter(Zend_Log::ERR);
$WsLogger->addWriter($WsMailWriter);
}
Zend_Registry::set('WsLogger', $WsLogger);
}
protected function _initNavigation()
{
$view = $this->bootstrap('layout')->getResource('layout')->getView();
//@todo : gérer les versions et les clients
$menu = array(
array(
'label' => 'Accueil',
'controller' => 'index',
'action' => 'index',
),
array(
'label' => 'Documentation',
'controller' => 'documentation',
'action' => 'index',
'pages' => array(
array(
'label' => 'Entreprise',
'controller' => 'documentation',
'action' => 'index',
),
array(
'label' => 'Code erreurs/messages',
'controller' => 'documentation',
'action' => 'erreur',
),
array(
'label' => 'Exemples',
'controller' => 'documentation',
'action' => 'exemples',
),
),
),
array(
'label' => 'Démonstration',
'controller' => 'demo',
'action' => 'index',
),
);
$view->navigation(new Zend_Navigation($menu));
}
protected function _initDb(){}
protected function _initRouter()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
//Lire les services disponibles et créer les routes
$services = new Zend_Config_Ini('WsScore/Services.ini');
foreach( $services->toArray() as $section => $params ){
if ($params['actif']) {
$route = new Zend_Controller_Router_Route($section.'/:version', array(
'controller' => 'service',
'action' => 'index',
'service' => $section,
'version' => '',
));
$router->addRoute($section, $route);
}
}
//Route pour WS Clients
$route = new Zend_Controller_Router_Route('clients/:client/:version', array(
'controller' => 'service',
'action' => 'index',
'service' => 'clients',
'client' => '',
'version' => ''
));
$router->addRoute('client', $route);
return $router;
}
protected function _initWsDebug()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('WsDebug');
$options = array(
'plugins' => array(
'Exception',
),
);
$debug = new WsDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
protected function _initCache()
{
//MetadataCache pour la base de données
$frontendOptions = array(
'lifetime' => 14400,
'automatic_serialization' => true
);
$backendOptions = array();
$cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
//Cache pour les données de la base à stocker
}
}