[TYPO3-core] Extension configuration object and ext_localconf.php

Steffen Müller typo3 at t3node.com
Thu Apr 17 00:46:44 CEST 2014


Hi.

I'd like to ask for your comment on below way of extension
configuration. Do you consider the practice of instantiating singleton
objects in ext_localconf.php harmful?

typo3conf/ext/testsuite/ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport'] = 'mbox';
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_mbox_file'] =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Stmllr\\Testsuite\\Configuration\\ExtensionConfiguration')->getMailboxPath();


typo3conf/ext/testsuite/Classes/Stmllr/Testsuite/Configuration/ExtensionConfiguration.php

<?php
namespace Stmllr\\Testsuite\\Configuration

class ExtensionConfiguration implements \TYPO3\CMS\Core\SingletonInterface {

	/**
	 * @var array
	 */
	protected $settings = array();

	/**
	 * @var string
	 */
	protected $fixturePath = '';

	/**
	 * @var string
	 */
	protected $mailboxPath = '';

	/**
	 * Constructor
	 */
	public function __construct() {
		$this->settings =
unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['testsuite']);
		$this->initializeProperties();
	}

	/**
	 * Initializes class properties
	 *
	 * @return string
	 */
	protected function initializeProperties() {
		// fixturePath
		$fixturePath = $this->settings['fixturePath'];
		if (substr($fixturePath, 0, 1) !== '/' && substr($fixturePath, 0, 8)
!== 'file:///') {
			$fixturePath = PATH_site . $fixturePath;
		}
		$this->fixturePath = rtrim($fixturePath, '/') . '/';

		// mailboxPath
		$this->mailboxPath =  $this->fixturePath .
$this->settings['mailboxFilename'];
	}

	/**
	 * Returns mailboxPath
	 *
	 * @return string
	 */
	public function getMailboxPath() {
		return $this->mailboxPath;
	}
}

see also: https://github.com/stmllr/testsuite

This code is tested and works with 6.2.

-- 
cheers,
Steffen

Active Contributor TYPO3 CMS

TYPO3 Blog: http://www.t3node.com/
Twitter: @t3node - http://twitter.com/t3node


More information about the TYPO3-team-core mailing list