/** * Convert variable format * * @param string $varName Name of the variable * @param array $parameter Array contains format parameters * @param array $pool Data that may needed for compile * @param DataContainer $dataContainer Parser data container * * @throws Exception\VariableDateMustSet * @throws Exception\VariableDateFormatNotFound * * @return string Compiled PHP code */ public static function convert($varName, array $parameter, array $pool, DataContainer $dataContainer) { $phpCode = ''; if (!isset($parameter[0]) || !$parameter[0]) { throw new Exception\VariableDateMustSet($varName); } if (!isset($pool['LanguageMap']['FORMAT_DATE_' . $parameter[0]])) { throw new Exception\VariableDateFormatNotFound($parameter[0], $varName); } if (!$dataContainer->hasDefineBlock('Header', 'Variable:InitDateTime')) { $dataContainer->setDefineBlock('Header', 'Variable:InitDateTime', '<?php $____dateTimeZones_____ = ' . var_export(static::$timeZones, true) . '; $____dateTime_____ = new DateTime(); ?>'); $dataContainer->setDefineBlock('Footer', 'Variable:DeInitDateTime', '<?php unset($____dateTimeZones_____); unset($____dateTime_____); ?>'); $dataContainer->setMutex('Overwrite!$____dateTimeZones_____'); $dataContainer->setMutex('Overwrite!$____dateTime_____'); } $phpCode .= '<?php '; if (isset($parameter[1]) && $parameter[1]) { $parameters = new Parameters('var="' . $parameter[1] . '"', array('var' => 'variable')); $phpCode .= 'if (isset(' . $parameters->get('var') . ', $____dateTimeZones_____[' . $parameters->get('var') . '])) {'; $phpCode .= '$____dateTime_____->setTimezone(new DateTimeZone('; $phpCode .= '$____dateTimeZones_____[' . $parameters->get('var') . '])'; $phpCode .= '); }'; } $phpCode .= '$____dateTime_____->setTimestamp((int)' . $varName . '); ' . 'echo($____dateTime_____->format(\'' . str_replace('\'', '\\\'', $pool['LanguageMap']['FORMAT_DATE_' . $parameter[0]]) . '\')); ?>'; return $phpCode; }
/** * Get time displaying code * * @param string $varName Name of the variable * @param array $parameter Array contains format parameters * @param array $pool Data that may needed for compile * * @throws Exception\VariableDateFormatNotFound * * @return string Compiled PHP code */ protected static function getTimeCode($varName, array &$parameter, array &$pool) { $timeFormatType = 'DEFAULTTIME'; $phpCode = ''; if (isset($parameter[0]) && $parameter[0]) { $timeFormatType = $parameter[0]; } if (!isset($pool['LanguageMap']['FORMAT_DATE_' . $timeFormatType])) { throw new Exception\VariableDateFormatNotFound($timeFormatType, $varName); } if (isset($parameter[1]) && $parameter[1]) { $parameters = new Parameters('var="' . $parameter[1] . '"', array('var' => 'variable')); $phpCode .= 'if (isset(' . $parameters->get('var') . ', $____dateTimeZones_____[' . $parameters->get('var') . '])) {'; $phpCode .= '$____dateTime_____->setTimezone(new DateTimeZone('; $phpCode .= '$____dateTimeZones_____[' . $parameters->get('var') . '])'; $phpCode .= '); }'; } $phpCode .= '$____dateTime_____->setTimestamp((int)' . $varName . '); ' . 'echo($____dateTime_____->format(\'' . str_replace('\'', '\\\'', $pool['LanguageMap']['FORMAT_DATE_' . $timeFormatType]) . '\')); '; return $phpCode; }