HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Zend_Application bootstrapper

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
zend_applicationbootstrapperstackoverflow

Problem

This seems a bit wrong because there's a lot of business logic going on inside the bootstrapper. Is there a better way to accomplish what's going on here?

```
getOption('ldapserver'), $this->getOption('ldapsearchbase'));
}

protected function _initLayout()
{
$layout = Zend_Layout::startMvc();
$layout->setLayoutPath(APPLICATION_PATH . '/layouts/scripts');
$layout->setLayout('layout');
return $layout;
}

protected function _initView()
{
$this->bootstrap('db');
$view = new Zend_View();

//Set the version string with subversion revision if found.
$version = '0.1';
$svnPath = APPLICATION_PATH . '/../.svnrev';
if (file_exists($svnPath))
{
$hFile = fopen($svnPath, 'r');
$version .= '.' . fgets($hFile);
fclose($hFile);
$lastModTime = filemtime($svnPath);
$dateTime = new DateTime('@' . $lastModTime, new DateTimeZone('America/New_York'));
$version .= ' ' . $dateTime->format('o-n-j G:i') . 'Z';
}
$view->version = $version;

// Setup Navigation

$nav = array();
$nav[] = array(
'label' => 'Welcome',
'controller' => 'index',
'action' => 'index',
'order' => -1
);

$loggedIn = Cas_Users_User::LoggedIn();

$logxLink = array('controller' => 'User', 'order' => 1000);
$logxLink['label'] = $loggedIn ? 'Logout' : 'Login';
$logxLink['action'] = strtolower($logxLink['label']);
$logxLink['pages'] = array(array(
'controller' => 'User',
'action' => 'AccessDenied',
'visible' => false,
'label' => 'Access Denied'
));
$nav[] = $logxLink;

$adminPermission = Cas_Acl_Privilege::CreateExisting('refreshAdmin');
unset($hasAdmin);
$hasAdmin = (bool)Cas_Users_User::CurrentPrivilegeCheck($adminPermissio

Solution

Resource plugins allow one to encapsulate a plugin class to perform one purpose & can be unit tested. Otherwise the bootstrap becomes a GOD class. Plugins have hooks too.

Worst case at least split up your '_initView' method as it is massive.

Context

StackExchange Code Review Q#678, answer score: 2

Revisions (0)

No revisions yet.