Skip to content

Commit

Permalink
Errors
Browse files Browse the repository at this point in the history
1. Set environment back to production
2. Modified error handling for db connection
3. Updated version number.
  • Loading branch information
deanblackborough committed Mar 26, 2015
1 parent 85e2bb6 commit d0be8fb
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 237 deletions.
298 changes: 148 additions & 150 deletions application/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,154 +9,152 @@
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Set PHP defaults, in this case the timesize, not safe to rely on the
* server setting
*
* @return void
*/
public function _initPhpDefaults()
{
// Not safe to relay on servers timezone
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('Europe/London');
}
}

/**
* Set doc type, set to HTML5, ensures that any code generated by the Zend
* view helper is correct
*/
public function _initDocType()
{
$this->bootstrap('layout');
$this->getResource('layout')->getView()->doctype('HTML5');
}

/**
* Set up namespaces for our library code, going to be serveral libraries,
* base library code will reside in Dlayer, specific module library code goes
* in a folder with the same name as the module
*
* @return void
*/
function _initNamespaces()
{
Zend_Loader_Autoloader::getInstance()->registerNamespace('Dlayer_');
}

/**
* Setup view helpers, view helpers exists only inside the Dlayer library,
* shared between all modules, this appears to be a Zend issue at the moment
* so just need to work around it
*
* @return void
*/
function _initViewHelpers()
{
$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'viewRenderer');
$renderer->initView();
$renderer->view->addHelperPath('Dlayer/View/',
'Dlayer_View');
}

/**
* Setup action helpers, exist only within the Dlayer library, shared between
* all the modules, as per view helpers this appears to be a Zend issue so
* just going to work with it
*
* @return void
*/
public function _initActionHelpers()
{
Zend_Controller_Action_HelperBroker::addPath('Dlayer/Action/',
'Dlayer_Action');
}

/**
* Connect to the default database and set the default adapter
*
* @return void
*/
public function _initDatabaseConnection()
{
/**
* Fetch the options from the application.ini file and create the
* data array for the database connection
*/
$config_options = $this->getApplication()->getOptions();

try {
$pdo_params = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;');

$db_config_array =
array('host' => $config_options['database']['default']['host'],
'username' => $config_options['database']['default']['user'],
'password' => $config_options['database']['default']['password'],
'dbname' => $config_options['database']['default']['name'],
'driver_options' => $pdo_params);

if(strlen($config_options['database']['default']['socket']) > 0) {
$db_config_array['unix_socket'] = $config_options['database']['default']['socket'];
}

$dbconn = Zend_Db::factory('Pdo_Mysql',
$db_config_array);

$dbconn->getConnection();
$dbconn->setFetchMode(PDO::FETCH_ASSOC);

// Assign default adapter
Zend_Db_Table_Abstract::setDefaultAdapter($dbconn);

} catch (Zend_Db_Adapter_Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
} catch (Zend_Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
}
}

/**
* Set up the session save handler, sessions are going to be stored in
* the database, not the filesystem
*
* @return void
*/
public function _initSessionHandler()
{
$session_config = array('name' => 'dlayer_session',
'primary' => array('session_id',
'save_path',
'name'),
'primaryAssignment' => array('sessionId',
'sessionSavePath',
'sessionName'),
'modifiedColumn' => 'modified',
'dataColumn' => 'session_data',
'lifetimeColumn' => 'lifetime');

$options = $this->getApplication()->getOption('session');

Zend_Session::setOptions(
array('gc_maxlifetime'=>intval($options['timeout']) + 1));
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(
$session_config));
}

/**
* Set up environment settings
*
* @return void
*/
public function _initEnvironmentSettings()
{
$this->bootstrap('layout');

$debug = $this->getApplication()->getOption('debug');

$this->getResource('layout')->assign('debug', $debug);
}
/**
* Set PHP defaults, in this case the timesize, not safe to rely on the
* server setting
*
* @return void
*/
public function _initPhpDefaults()
{
// Not safe to relay on servers timezone
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('Europe/London');
}
}

/**
* Set doc type, set to HTML5, ensures that any code generated by the Zend
* view helper is correct
*/
public function _initDocType()
{
$this->bootstrap('layout');
$this->getResource('layout')->getView()->doctype('HTML5');
}

/**
* Set up namespaces for our library code, going to be serveral libraries,
* base library code will reside in Dlayer, specific module library code goes
* in a folder with the same name as the module
*
* @return void
*/
function _initNamespaces()
{
Zend_Loader_Autoloader::getInstance()->registerNamespace('Dlayer_');
}

/**
* Setup view helpers, view helpers exists only inside the Dlayer library,
* shared between all modules, this appears to be a Zend issue at the moment
* so just need to work around it
*
* @return void
*/
function _initViewHelpers()
{
$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'viewRenderer');
$renderer->initView();
$renderer->view->addHelperPath('Dlayer/View/',
'Dlayer_View');
}

/**
* Setup action helpers, exist only within the Dlayer library, shared between
* all the modules, as per view helpers this appears to be a Zend issue so
* just going to work with it
*
* @return void
*/
public function _initActionHelpers()
{
Zend_Controller_Action_HelperBroker::addPath('Dlayer/Action/',
'Dlayer_Action');
}

/**
* Connect to the default database and set the default adapter
*
* @return void
*/
public function _initDatabaseConnection()
{
/**
* Fetch the options from the application.ini file and create the
* data array for the database connection
*/
$config_options = $this->getApplication()->getOptions();

$pdo_params = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;');

$db_config_array =
array('host' => $config_options['database']['default']['host'],
'username' => $config_options['database']['default']['user'],
'password' => $config_options['database']['default']['password'],
'dbname' => $config_options['database']['default']['name'],
'driver_options' => $pdo_params);

if(strlen($config_options['database']['default']['socket']) > 0) {
$db_config_array['unix_socket'] = $config_options['database']['default']['socket'];
}

$dbconn = Zend_Db::factory('Pdo_Mysql', $db_config_array);

try {
$dbconn->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
$e->getMessage();
$e->getTraceAsString();
} catch (Zend_Exception $e) {
$e->getMessage();
$e->getTraceAsString();
}

// Assign default adapter
$dbconn->setFetchMode(PDO::FETCH_ASSOC);
Zend_Db_Table_Abstract::setDefaultAdapter($dbconn);
}

/**
* Set up the session save handler, sessions are going to be stored in
* the database, not the filesystem
*
* @return void
*/
public function _initSessionHandler()
{
$session_config = array('name' => 'dlayer_session',
'primary' => array('session_id',
'save_path',
'name'),
'primaryAssignment' => array('sessionId',
'sessionSavePath',
'sessionName'),
'modifiedColumn' => 'modified',
'dataColumn' => 'session_data',
'lifetimeColumn' => 'lifetime');

$options = $this->getApplication()->getOption('session');

Zend_Session::setOptions(
array('gc_maxlifetime'=>intval($options['timeout']) + 1));
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(
$session_config));
}

/**
* Set up environment settings
*
* @return void
*/
public function _initEnvironmentSettings()
{
$this->bootstrap('layout');

$debug = $this->getApplication()->getOption('debug');

$this->getResource('layout')->assign('debug', $debug);
}
}
Loading

0 comments on commit d0be8fb

Please sign in to comment.