/** * Constructor * * Parameter can be set in the phpunit xml configuration file: * <code> * <listeners> * <listener class="..." file="..."> * <arguments> * <string>...</string><!-- targetFile --> * * <string>...</string><!-- directory --> * * <array> * <element key="js/handle.gif"> * <string>###MENTA_ROOTDIR###/PHPUnit/Listener/Resources/Templates/files/handle.gif</string> * </element> * <element key="js/jquery.beforeafter-1.4.min.js"> * <string>###MENTA_ROOTDIR###/PHPUnit/Listener/Resources/Templates/files/jquery.beforeafter-1.4.min.js</string> * </element> * <!-- ... --> * </array> * </arguments> * </listener> * </listeners> * </code> * * @param string $targetFile * @param string $templateFile * @param array $additionalFiles * @throws Exception * @author Fabrizio Branca */ public function __construct($targetFile = NULL, $templateFile = NULL, array $additionalFiles = NULL) { if (!is_null($targetFile)) { $this->targetFile = $targetFile; $this->targetFile = Menta_Util_Div::replaceWithEnvironmentVariables($this->targetFile); } $dir = dirname($this->targetFile); if (!is_dir($dir)) { throw new Exception("Target dir '{$dir}' does not exist"); } // clean target dir foreach (glob($dir . "/*") as $file) { if (!is_dir($file)) { unlink($file); } } if (!is_null($templateFile)) { $this->templateFile = $templateFile; } $this->templateFile = str_replace('###MENTA_ROOTDIR###', MENTA_ROOTDIR, $this->templateFile); if (empty($this->templateFile)) { throw new Exception('No template file defined'); } if (!is_null($additionalFiles)) { $this->additionalFiles = $additionalFiles; } parent::__construct($this->targetFile); }
/** * Get configuration value * * @throws Exception if key is not found * @param string $key * @return string */ public function getValue($key, $throwException = true) { if (empty($GLOBALS[__CLASS__ . '_defaultsLoaded'])) { $this->loadDefaults(); } if (!$this->issetKey($key)) { if ($throwException) { throw new Exception(sprintf('Could not find configuration key "%s"', $key)); } return null; } $value = $GLOBALS[$key]; $value = Menta_Util_Div::replaceWithEnvironmentVariables($value); if (is_string($value)) { if (strpos($value, '[') !== false || strpos($value, '{') !== false) { // json decoding if possible $jsonDecoded = json_decode($value, true); if (!is_null($jsonDecoded)) { $value = $jsonDecoded; } } } return $value; }