|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Model class |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Phile\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Phile\Core\Container; |
|
8
|
|
|
use Phile\Core\ServiceLocator; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Meta model |
|
12
|
|
|
* |
|
13
|
|
|
* @author Frank Nägler |
|
14
|
|
|
* @link https://philecms.com |
|
15
|
|
|
* @license http://opensource.org/licenses/MIT |
|
16
|
|
|
* @package Phile\Model |
|
17
|
|
|
*/ |
|
18
|
|
|
class Meta extends AbstractModel |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* the construtor |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $rawData the raw data to parse |
|
25
|
|
|
*/ |
|
26
|
24 |
|
public function __construct($rawData = null) |
|
27
|
|
|
{ |
|
28
|
24 |
|
if ($rawData !== null) { |
|
29
|
24 |
|
$this->setRawData($rawData); |
|
30
|
|
|
} |
|
31
|
24 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* set the raw data to parse |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $rawData the raw data |
|
37
|
|
|
*/ |
|
38
|
24 |
|
public function setRawData($rawData) |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @triggerEvent before_read_file_meta this event is triggered before the meta data readed and parsed |
|
42
|
|
|
* |
|
43
|
|
|
* @param string rawData the unparsed data |
|
44
|
|
|
* @param \Phile\Model\Meta meta the meta model |
|
45
|
|
|
*/ |
|
46
|
24 |
|
Container::getInstance()->get('Phile_EventBus')->trigger( |
|
47
|
24 |
|
'before_read_file_meta', |
|
48
|
24 |
|
['rawData' => &$rawData, 'meta' => &$this] |
|
49
|
|
|
); |
|
50
|
24 |
|
$this->parseRawData($rawData); |
|
51
|
|
|
/** |
|
52
|
|
|
* @triggerEvent after_read_file_meta this event is triggered after the meta data readed and parsed |
|
53
|
|
|
* |
|
54
|
|
|
* @param string rawData the unparsed data |
|
55
|
|
|
* @param \Phile\Model\Meta meta the meta model |
|
56
|
|
|
*/ |
|
57
|
24 |
|
Container::getInstance()->get('Phile_EventBus')->trigger( |
|
58
|
24 |
|
'after_read_file_meta', |
|
59
|
24 |
|
['rawData' => &$rawData, 'meta' => &$this] |
|
60
|
|
|
); |
|
61
|
24 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* get formatted date |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool|null|string |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getFormattedDate() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$config = Container::getInstance()->get('Phile_Config'); |
|
71
|
1 |
|
if (!isset($this->data['date'])) { |
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
1 |
|
$date = $this->data['date']; |
|
75
|
1 |
|
if (!is_numeric($date)) { |
|
76
|
1 |
|
$date = strtotime($date); |
|
77
|
|
|
} |
|
78
|
1 |
|
return date($config->get('date_format'), $date); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* parse the raw data |
|
83
|
|
|
* |
|
84
|
|
|
* @param $rawData |
|
85
|
|
|
*/ |
|
86
|
24 |
|
protected function parseRawData($rawData) |
|
87
|
|
|
{ |
|
88
|
|
|
/** |
|
89
|
|
|
* @var \Phile\ServiceLocator\MetaInterface $metaParser |
|
90
|
|
|
*/ |
|
91
|
24 |
|
$metaParser = ServiceLocator::getService('Phile_Parser_Meta'); |
|
92
|
24 |
|
$data = $metaParser->parse($rawData); |
|
93
|
|
|
|
|
94
|
24 |
|
foreach ($data as $key => $value) { |
|
95
|
22 |
|
$this->set($key, $value); |
|
96
|
|
|
} |
|
97
|
24 |
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|