Last active
December 21, 2015 02:08
-
-
Save BinaryKitten/6232299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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