Last active
December 7, 2016 10:34
-
-
Save Konafets/784f7cf5cee7accdcdabf41dc14bdee5 to your computer and use it in GitHub Desktop.
SettingsService for TYPO3
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 ; | |
| use TYPO3\CMS\Core\SingletonInterface; | |
| use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; | |
| use TYPO3\CMS\Extbase\Reflection\ObjectAccess; | |
| /** | |
| * Provide a way to get the configuration just everywhere | |
| * | |
| * Example | |
| * $pluginSettingsService = | |
| * $this->objectManager->get('Tx_News_Service_SettingsService'); | |
| * t3lib_div::print_array($pluginSettingsService->getSettings()); | |
| * | |
| * If objectManager is not available: | |
| * http://forge.typo3.org/projects/typo3v4-mvc/wiki/ | |
| * Dependency_Injection_%28DI%29#Creating-Prototype-Objects-through-the-Object-Manager | |
| * | |
| * @author Stefano Kowalke <[email protected]>, Skyfillers GmbH | |
| * @author Sebastian Schreiber <[email protected]> | |
| * @author Georg Ringer <[email protected]> | |
| */ | |
| class SettingsService implements SingletonInterface | |
| { | |
| /** | |
| * @var mixed | |
| */ | |
| protected $configuration; | |
| /** | |
| * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface | |
| */ | |
| protected $configurationManager; | |
| /** | |
| * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager | |
| * @return void | |
| */ | |
| public function injectConfigurationManager( | |
| \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager | |
| ) { | |
| $this->configurationManager = $configurationManager; | |
| } | |
| /** | |
| * Returns the TS configuration | |
| * | |
| * @return array|mixed | |
| */ | |
| public function getConfiguration() | |
| { | |
| if ($this->configuration === null) { | |
| $this->configuration = $this->configurationManager->getConfiguration( | |
| ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK | |
| ); | |
| } | |
| return $this->configuration; | |
| } | |
| /** | |
| * Returns the settings at path $path, which is separated by ".", | |
| * e.g. "pages.uid". | |
| * "pages.uid" would return $this->settings['pages']['uid']. | |
| * | |
| * If the path is invalid or no entry is found, false is returned. | |
| * | |
| * @param string $path | |
| * @return mixed | |
| */ | |
| public function getByPath($path) | |
| { | |
| $configuration = $this->getConfiguration(); | |
| $setting = ObjectAccess::getPropertyPath($configuration, $path); | |
| if ($setting === null) { | |
| $setting = ObjectAccess::getPropertyPath($configuration['settings'], $path); | |
| } | |
| return $setting; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment