webservice/application/Bootstrap.php

161 lines
4.8 KiB
PHP

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initConfig()
{
$config = new Zend_Config($this->getOptions());
Zend_Registry::set('config', $config);
//Load old config
require_once 'WsScore/Configure.php';
$oldconfig = new Configure();
return $config;
}
//Initialisation global des paramètres de vue
protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->setEncoding('UTF-8');
$view->doctype('HTML5');
$view->headMeta()
->appendName('viewport', 'width=device-width, initial-scale=1.0')
->appendHttpEquiv('X-UA-Compatible', 'IE=edge')
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'fr-FR');
//Favicon - Touch icon for iOS 2.0+ and Android 2.1+
$view->headLink()->headLink(array(
'rel' => 'apple-touch-icon-precomposed',
'href' => '/favicon-152.png'
));
//Favicon - targeted to any additional png size
$view->headLink()->headLink(array(
'rel' => 'icon',
'type' => 'image/png',
'href' => '/favicon-32.png'
));
$view->headLink()->headLink(array(
'rel' => 'shortcut icon',
'type' => 'image/x-icon',
'href' => '/favicon.ico')
);
$view->headLink()
->appendStylesheet('/libs/bootstrap-3.3.2/css/bootstrap.min.css', 'all')
->appendStylesheet('/themes/default/css/docs.css', 'all')
->appendStylesheet('/themes/default/css/main.css', 'all');
$view->headScript()
->appendFile('/libs/html5shiv.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/jquery-1.11.2.min.js', 'text/javascript')
->appendFile('/libs/bootstrap-3.3.2/js/bootstrap.min.js', 'text/javascript');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Web Service API - Scores & Decisions');
}
protected function _initRouter()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$router = $front->getRouter();
//Lire les services disponibles et créer les routes
$services = require_once APPLICATION_PATH . '/../library/WsScore/ServicesConfig.php';
foreach( $services 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 = new Zend_Controller_Router_Route('jsonrpc/'.$section.'/:version', array(
'controller' => 'jsonrpc',
'action' => 'index',
'service' => $section,
'version' => '',
));
$router->addRoute('jsonrpc-'.$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);
$fichierRoute = new Zend_Controller_Router_Route('fichier/:action/:fichier', array(
'controller' => 'fichier',
'fichier' => '',
));
$router->addRoute('fichier', $fichierRoute);
return $router;
}
protected function _initDb()
{
$c = Zend_Registry::get('config');
try {
$db = Zend_Db::factory($c->profil->db->metier);
} catch ( Exception $e ) {
if (APPLICATION_ENV == 'development') {
echo '<pre>'; print_r($e); echo '</pre>';
} else {
echo "Le service rencontre actuellement un problème technique.";
}
exit;
}
/**
* Set the default adapter to use with all model
*/
Zend_Db_Table::setDefaultAdapter($db);
}
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()
{
if ( APPLICATION_ENV!='development' ) {
//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);
}
}
}