Skip to content

Instantly share code, notes, and snippets.

@bognerf
Created June 19, 2013 08:33
Show Gist options
  • Save bognerf/5812667 to your computer and use it in GitHub Desktop.
Save bognerf/5812667 to your computer and use it in GitHub Desktop.
Zend Framework 1 Bootstrap for multimodule architecture
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected $config;
protected function _initConfig()
{
$this->config = $this->getOptions();
Zend_Registry::set('config', $this->config);
}
protected function initDB()
{
$db = Zend_Db::factory($this->config['resources']['db']['adapter'],
array('host' => $this->config['resources']['db']['params']['host'],
'dbname' => $this->config['resources']['db']['params']['dbname'],
'password' => $this->config['resources']['db']['params']['password'],
'username' => $this->config['resources']['db']['params']['username']));
Zend_Registry::set('db', $db);
}
protected function _initSession()
{
Zend_Session::setOptions(array(
'cookie_secure' => true,
'name' => 'XYZ_SSL',
'cookie_httponly' => true,
));
//Session starten
Zend_Session::start();
}
protected function _initDoctype()
{
$doctypeHelper = new Zend_View_Helper_Doctype();
$doctypeHelper->doctype('XHTML1_STRICT');
}
protected function _initLogging()
{
$this->initDB();
// configure caching logger
$db = Zend_Registry::get('db');
$columnMapping = array(
'lvl' => 'priority',
'msg' => 'message',
'created_at' => 'timestamp',
'address' => 'address',
'agent' => 'agent');
$writer = new Zend_Log_Writer_Db($db, "logs", $columnMapping);
$logger = new Zend_Log($writer);
$filter = new Zend_Log_Filter_Priority(Zend_Log::INFO);
// UserAgent ist leer, wenn CLI-basiert aufgerufen, ansonsten "Hacking" mittels User-Agent verhindern
if (isset($_SERVER['HTTP_USER_AGENT']))
{
$agent = addslashes($_SERVER['HTTP_USER_AGENT']);
}
else
{
$agent = "none";
}
$logger->addFilter($filter);
$logger->setEventItem('address', $_SERVER['REMOTE_ADDR']);
$logger->setEventItem('agent', $agent);
Zend_Registry::set('logger', $logger);
}
protected function _initCaching()
{
$frontendOptions = array(
'lifetime' => $this->config['caching']['lifetime'],
'automatic_serialization' => true;
'logging' => $this->config['caching']['logging'],
'logger' => Zend_Registry::get('logger')
);
$backendOptions = array(
'cache_dir' => realpath($this->config['caching']['filepath'])
);
// Ein Zend_Cache_Core Objekt erzeugen
$cache = Zend_Cache::factory('Core',
'File',
$frontendOptions,
$backendOptions);
Zend_Registry::set('cache', $cache);
}
protected function _initTranslation()
{
$cache = Zend_Registry::get('cache');
$cache_id = 'base_translation';
if (!$translate = $cache->load($cache_id))
{
$translate = new Zend_Translate(
array(
'adapter' => 'tmx',
'content' => $this->config['translation']['basedir'] . '/translations.tmx',
'locale' => 'de'
)
);
$cache->save($translate, $cache_id);
}
Zend_Registry::set('translation', $translate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment