| 1 |
lars |
1 |
<?php
|
|
|
2 |
require_once 'XML/Query2XML/Data/Processor.php';
|
|
|
3 |
|
|
|
4 |
class Year2UnixTime extends XML_Query2XML_Data_Processor
|
|
|
5 |
{
|
|
|
6 |
/**
|
|
|
7 |
* Create a new instance of this class.
|
|
|
8 |
*
|
|
|
9 |
* @param mixed $preProcessor The pre-processor to be used. An instance of
|
|
|
10 |
* XML_Query2XML_Data or null.
|
|
|
11 |
* @param string $configPath The configuration path within the $options
|
|
|
12 |
* array.
|
|
|
13 |
*
|
|
|
14 |
* @return XML_Query2XML_Data_Processor_Base64
|
|
|
15 |
*/
|
|
|
16 |
public function create($preProcessor, $configPath)
|
|
|
17 |
{
|
|
|
18 |
$processor = new Year2UnixTime($preProcessor);
|
|
|
19 |
$processor->setConfigPath($configPath);
|
|
|
20 |
return $processor;
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Called by XML_Query2XML for every record in the result set.
|
|
|
25 |
*
|
|
|
26 |
* @param array $record An associative array.
|
|
|
27 |
*
|
|
|
28 |
* @return string The base64-encoded version the string returned
|
|
|
29 |
* by the pre-processor.
|
|
|
30 |
* @throws XML_Query2XML_ConfigException If the pre-processor returns
|
|
|
31 |
* something that cannot be converted to a string
|
|
|
32 |
* (i.e. an object or an array).
|
|
|
33 |
*/
|
|
|
34 |
public function execute(array $record)
|
|
|
35 |
{
|
|
|
36 |
$data = $this->runPreProcessor($record);
|
|
|
37 |
if (is_array($data) || is_object($data)) {
|
|
|
38 |
throw new XML_Query2XML_ConfigException(
|
|
|
39 |
$this->getConfigPath()
|
|
|
40 |
. ': XML_Query2XML_Data_Processor_Base64: string '
|
|
|
41 |
. 'expected from pre-processor, but ' . gettype($data) . ' returned.'
|
|
|
42 |
);
|
|
|
43 |
}
|
|
|
44 |
return DateTime::createFromFormat('Y-m-d H:i:s', $data . '-01-01 00:00:00', new DateTimeZone('Etc/GMT+0'))->format('U');
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
?>
|