Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active December 21, 2015 02:08
Show Gist options
  • Select an option

  • Save BinaryKitten/6232299 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/6232299 to your computer and use it in GitHub Desktop.
<?php
namespace CustomTheme;
use Zend\Stdlib\ArrayUtils;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
class Module implements ServiceProviderInterface,
ViewHelperProviderInterface
{
protected $config = array();
protected $theme = null;
public function getConfig()
{
return $this->config;
}
public function getAutoloaderConfig()
{
$autoLoaderConfig = array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
$this->config = ArrayUtils::merge(
include __DIR__ . '/config/module.config.php',
include __DIR__ . '/config/theme.config.php'
);
$currentTheme = $this->config['CustomTheme']['current-theme'];
if (!empty($currentTheme)) {
require $this->config['CustomTheme']['theme-location'] . '/' . $currentTheme . '/Theme.php';
$className = '\\' . $currentTheme . '\Theme';
if (class_exists($className, false)) {
$this->theme = new $className();
if (method_exists($this->theme, 'getConfig')) {
$this->config = ArrayUtils::merge(
$this->config,
$this->theme->getConfig()
);
}
if (method_exists($this->theme, 'getAutoloaderConfig')) {
$autoLoaderConfig = ArrayUtils::merge(
$autoLoaderConfig,
$this->theme->getAutoloaderConfig()
);
}
}
}
return $autoLoaderConfig;
}
public function getServiceConfig()
{
if ($this->theme !== null && method_exists($this->theme, 'getServiceConfig')) {
return $this->theme->getServiceConfig();
}
return array();
}
public function getViewHelperConfig()
{
if ($this->theme !== null && method_exists($this->theme, 'getViewHelperConfig')) {
return $this->theme->getViewHelperConfig();
}
return array();
}
}
<?php
namespace CustomTheme;
use Zend\ModuleManager\ModuleManager;
class Module
{
public function init(ModuleManager $moduleManager) {
$theme = include __DIR__ . '/config/theme.config.php';
try {
$moduleManager->loadModule($theme);
} catch(Exception $e) {
//ignore "theme doesn't exist"
}
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php',
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment