|
1
|
|
|
<?php namespace FlatPlan; |
|
2
|
|
|
|
|
3
|
|
|
use FlatPlan\Components\AbstractComponent; |
|
4
|
|
|
use FlatPlan\Components\Ad; |
|
5
|
|
|
use FlatPlan\Components\Audio; |
|
6
|
|
|
use FlatPlan\Components\Gallery; |
|
7
|
|
|
use FlatPlan\Components\Image; |
|
8
|
|
|
use FlatPlan\Components\Location; |
|
9
|
|
|
use FlatPlan\Components\Social; |
|
10
|
|
|
use FlatPlan\Components\Structure; |
|
11
|
|
|
use FlatPlan\Components\Table; |
|
12
|
|
|
use FlatPlan\Components\Text; |
|
13
|
|
|
use FlatPlan\Components\Video; |
|
14
|
|
|
|
|
15
|
|
|
class Article { |
|
16
|
|
|
|
|
17
|
|
|
private $components = array(); |
|
18
|
|
|
private $defer; |
|
19
|
|
|
private $articleId; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct($articleId, $defer = false) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->articleId = $articleId; |
|
24
|
|
|
$this->defer = $defer; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getJson() |
|
28
|
|
|
{ |
|
29
|
|
|
$article = new \stdClass(); |
|
30
|
|
|
$article->publisher_article_id = $this->articleId; |
|
31
|
|
|
$article->defer = $this->defer; |
|
32
|
|
|
$article->components = $this->getComponents(); |
|
33
|
|
|
|
|
34
|
|
|
return json_encode($article); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getComponents($format = null) |
|
38
|
|
|
{ |
|
39
|
|
|
return $format === 'json' ? json_encode($this->components) : $this->components; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param AbstractComponent $component |
|
44
|
|
|
* @throws \ErrorException |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function addComponent($component) |
|
48
|
|
|
{ |
|
49
|
|
|
if ($component instanceof AbstractComponent) { |
|
|
|
|
|
|
50
|
|
|
array_push($this->components, $component); |
|
51
|
|
|
} else { |
|
52
|
|
|
throw new \ErrorException('Invalid component supplied.'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|