1 | <?php |
||
17 | class PageView extends FrontMatterDocument |
||
18 | { |
||
19 | const REPEATER_TYPE = 'repeater'; |
||
20 | const DYNAMIC_TYPE = 'dynamic'; |
||
21 | const STATIC_TYPE = 'static'; |
||
22 | |||
23 | /** |
||
24 | * @var Filesystem |
||
25 | */ |
||
26 | private static $fileSys; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $type; |
||
32 | |||
33 | /** |
||
34 | * @var PageView[] |
||
35 | */ |
||
36 | private $children; |
||
37 | |||
38 | /** |
||
39 | * @var JailedDocument |
||
40 | */ |
||
41 | private $jailInstance; |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 32 | public function __construct($filePath) |
|
53 | |||
54 | // |
||
55 | // Twig Jail |
||
56 | // ========= |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 24 | public function createJail() |
|
62 | { |
||
63 | 24 | if (is_null($this->jailInstance)) |
|
64 | 24 | { |
|
65 | 24 | $this->jailInstance = (new JailedDocument($this, array_merge(self::$whiteListFunctions, array( |
|
66 | 24 | 'getUrl', |
|
67 | 24 | )), array('getChildren' => 'getJailedChildren'))); |
|
68 | 24 | } |
|
69 | |||
70 | 24 | return $this->jailInstance; |
|
71 | } |
||
72 | |||
73 | 3 | public function getJailedChildren() |
|
74 | { |
||
75 | 3 | $children = $this->children; |
|
76 | |||
77 | 3 | foreach ($children as &$child) |
|
78 | { |
||
79 | 3 | $child = $child->createJail(); |
|
80 | 3 | } |
|
81 | |||
82 | 3 | return $children; |
|
83 | } |
||
84 | |||
85 | // |
||
86 | // Getters |
||
87 | // ======= |
||
88 | |||
89 | /** |
||
90 | * Get child PageViews. |
||
91 | * |
||
92 | * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of |
||
93 | * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent. |
||
94 | * |
||
95 | * @return PageView[] |
||
96 | */ |
||
97 | 3 | public function &getChildren() |
|
101 | |||
102 | /** |
||
103 | * @return string Twig body |
||
104 | */ |
||
105 | 14 | public function getContent() |
|
109 | |||
110 | /** |
||
111 | * Returns the type of the PageView. |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 20 | public function getType() |
|
119 | |||
120 | /** |
||
121 | * A fallback for the site menus that use the `url` field. |
||
122 | * |
||
123 | * @deprecated 0.1.0 |
||
124 | * |
||
125 | * @todo Remove this in the next major release |
||
126 | */ |
||
127 | public function getUrl() |
||
131 | |||
132 | // |
||
133 | // Factory |
||
134 | // ======= |
||
135 | |||
136 | /** |
||
137 | * Create the appropriate object type when parsing a PageView. |
||
138 | * |
||
139 | * @param string $filePath The path to the file that will be parsed into a PageView |
||
140 | * |
||
141 | * @return DynamicPageView|PageView|RepeaterPageView |
||
142 | */ |
||
143 | 6 | public static function create($filePath) |
|
162 | |||
163 | // |
||
164 | // Virtual PageViews |
||
165 | // ================= |
||
166 | |||
167 | /** |
||
168 | * Create a virtual PageView. |
||
169 | * |
||
170 | * @param array $frontMatter The Front Matter that this virtual PageView will have |
||
171 | * @param string $body The body of the virtual PageView |
||
172 | * |
||
173 | * @return PageView |
||
174 | */ |
||
175 | 4 | public static function createVirtual($frontMatter, $body) |
|
189 | |||
190 | /** |
||
191 | * Create a virtual PageView to create redirect files. |
||
192 | * |
||
193 | * @param string $redirectFrom The URL that will be redirecting to the target location |
||
194 | * @param string $redirectTo The URL of the destination |
||
195 | * @param string|bool $redirectTemplate The path to the template |
||
196 | * |
||
197 | * @return PageView A virtual PageView with the redirection template |
||
198 | */ |
||
199 | 4 | public static function createRedirect($redirectFrom, $redirectTo, $redirectTemplate = false) |
|
223 | } |
||
224 |