Skip to content

Commit

Permalink
Various cleanup to module manager / options
Browse files Browse the repository at this point in the history
- Cleaned up documentation on ManagerOptions
- Organized methods in ManagerOptions for consistency
- Replaced term "self installation" with "auto installation" everwhere
  • Loading branch information
EvanDotPro committed Oct 11, 2011
1 parent 9c9da86 commit c32a275
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 43 deletions.
12 changes: 6 additions & 6 deletions library/Zend/Module/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public function loadModule($moduleName)
$this->addProvision($module);
$this->addDependency($module);
}
if ($this->getOptions()->getEnableSelfInstallation() &&
in_array($moduleName,$this->getOptions()->getSelfInstallWhitelist()->toArray())) {
$this->installModule($module);
if ($this->getOptions()->getEnableAutoInstallation()
&& in_array($moduleName, $this->getOptions()->getAutoInstallWhitelist())) {
$this->autoInstallModule($module);
}
$this->runModuleInit($module);
$this->mergeModuleConfig($module);
Expand All @@ -152,7 +152,7 @@ public function loadModule($moduleName)
*
* @param Module $module
*/
public function installModule($module)
public function autoInstallModule($module)
{
if (is_callable(array($module, 'getProvides'))) {
$this->loadInstallationManifest();
Expand All @@ -163,7 +163,7 @@ public function installModule($module)
$this->manifest->{$moduleName} = $data;
$this->manifest->{'_dirty'} = true;
} else { // if $result is false then throw Exception
throw new \RuntimeException("Self installation for {$moduleName} failed");
throw new \RuntimeException("Auto installation for {$moduleName} failed");
}
}
} elseif (isset($this->manifest->{$moduleName}) && // does exists in manifest
Expand All @@ -174,7 +174,7 @@ public function installModule($module)
$this->manifest->{$moduleName} = $data;
$this->manifest->{'_dirty'} = true;
} else { // if $result is false then throw Exception
throw new \RuntimeException("Self upgrade for {$moduleName} failed");
throw new \RuntimeException("Auto upgrade for {$moduleName} failed");
}
}
}
Expand Down
89 changes: 52 additions & 37 deletions library/Zend/Module/ManagerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class ManagerOptions
/**
* @var bool
*/
protected $enableSelfInstallation = false;
protected $enableAutoInstallation = false;

/**
* array of modules that have been whitelisted to allow self installation
* array of modules that have been whitelisted to allow auto installation
*
* @var array
*/
protected $selfInstallWhiteList = array();
protected $autoInstallWhiteList = array();

/**
* Check if the config cache is enabled
Expand All @@ -50,9 +50,9 @@ public function getEnableConfigCache()
}

/**
* Set configCacheEnabled.
* Set if the config cache should be enabled or not
*
* @param bool $enabled the value to be set
* @param bool $enabled
* @return ManagerConfig
*/
public function setEnableConfigCache($enabled)
Expand All @@ -62,7 +62,7 @@ public function setEnableConfigCache($enabled)
}

/**
* Get cacheDir.
* Get the path where cache file(s) are stored
*
* @return string
*/
Expand All @@ -72,7 +72,7 @@ public function getCacheDir()
}

/**
* Set cacheDir.
* Set the path where cache files can be stored
*
* @param string $cacheDir the value to be set
* @return ManagerConfig
Expand All @@ -82,7 +82,7 @@ public function setCacheDir($cacheDir)
if (null === $cacheDir) {
$this->cacheDir = $cacheDir;
} else {
$this->cacheDir = rtrim(rtrim($cacheDir, '/'), '\\');
$this->cacheDir = static::normalizePath($cacheDir);
}
return $this;
}
Expand All @@ -108,13 +108,13 @@ public function setManifestDir($manifestDir)
if (null === $manifestDir) {
$this->manifestDir = $manifestDir;
} else {
$this->manifestDir = rtrim(rtrim($manifestDir, '/'), '\\');
$this->manifestDir = static::normalizePath($manifestDir);
}
return $this;
}

/**
* getCacheFilePath
* Get the path to the config cache
*
* Should this be an option, or should the dir option include the
* filename, or should it simply remain hard-coded? Thoughts?
Expand All @@ -127,74 +127,89 @@ public function getCacheFilePath()
}

/**
* set if dependency checking should be enabled
* Check if dependency checking is enabled
*
* @param bool $bool
* @return bool
*/
public function getEnableDependencyCheck()
{
return $this->enableDependencycheck;
}

/**
* Set if dependency checking is enabled
*
* @param bool $enabled
* @return Manager
*/
public function setEnableDependencyCheck($bool)
public function setEnableDependencyCheck($enabled)
{
$this->enableDependencycheck = (bool) $bool;
$this->enableDependencycheck = (bool) $enabled;
return $this;
}

/**
* get if dependency checking is enabled
* Check if auto installation is enabled
*
* @return bool
*/
public function getEnableDependencyCheck()
public function getEnableAutoInstallation()
{
return $this->enableDependencycheck;
return $this->enableAutoInstallation;
}

/**
* set if self installation is enabled
* Set if auto installation is enabled application-wide. If this is
* disabled, no auto install/upgrades will be ran; even if the modules are
* in the whitelist.
*
* @param bool $bool
* @param bool $enabled
* @return Manager
*/
public function setEnableSelfInstallation($bool)
public function setEnableAutoInstallation($enabled)
{
$this->enableSelfInstallation = (bool) $bool;
$this->enableAutoInstallation = (bool) $enabled;
return $this;
}

/**
* gets if self installation is enabled
* Get the array of modules enabled for auto install or upgrade
*
* @return bool
* @return array
*/
public function getSelfInstallWhitelist()
public function getAutoInstallWhitelist()
{
return $this->selfInstallWhitelist;
}

/**
* set if self installation is enabled
* Set auto installation whitelist
*
* @param bool $bool
* @param array $list An array of module names which to allow auto install or upgrade
* @return Manager
*/
public function setSelfInstallWhitelist($list)
public function setAutoInstallWhitelist($list)
{
$this->selfInstallWhitelist = $list;
return $this;
}

public function getApplicationEnv()
{
return defined('APPLICATION_ENV') ? APPLICATION_ENV : NULL;
}

/**
* gets if self installation is enabled
* Normalize a path for insertion in the stack
*
* @return bool
* @param string $path
* @return string
*/
public function getEnableSelfInstallation()
{
return $this->enableSelfInstallation;
}

public function getApplicationEnv()
public static function normalizePath($path)
{
return defined('APPLICATION_ENV') ? APPLICATION_ENV : NULL;
$path = rtrim($path, '/');
$path = rtrim($path, '\\');
return $path;
}

/**
Expand Down

0 comments on commit c32a275

Please sign in to comment.