1 | <?php |
||
11 | class PageView extends FrontMatterObject |
||
12 | { |
||
13 | const TEMPLATE = "---\n%s\n---\n\n%s"; |
||
14 | |||
15 | const REPEATER_TYPE = 0; |
||
16 | const DYNAMIC_TYPE = 1; |
||
17 | const STATIC_TYPE = 2; |
||
18 | |||
19 | /** |
||
20 | * @var vfsStreamDirectory |
||
21 | */ |
||
22 | private static $vfsRoot; |
||
23 | |||
24 | /** |
||
25 | * @var Filesystem |
||
26 | */ |
||
27 | private static $fileSys; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $type; |
||
33 | |||
34 | /** |
||
35 | * @var PageView[] |
||
36 | */ |
||
37 | private $children; |
||
38 | |||
39 | /** |
||
40 | * @var JailObject |
||
41 | */ |
||
42 | private $jailInstance; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 23 | public function __construct($filePath) |
|
54 | |||
55 | // |
||
56 | // Twig Jail |
||
57 | // ========= |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 12 | public function createJail () |
|
73 | |||
74 | 3 | public function getJailedChildren () |
|
85 | |||
86 | // |
||
87 | // Getters |
||
88 | // ======= |
||
89 | |||
90 | /** |
||
91 | * Get child PageViews |
||
92 | * |
||
93 | * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of |
||
94 | * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent. |
||
95 | * |
||
96 | * @return PageView[] |
||
97 | */ |
||
98 | 3 | public function &getChildren () |
|
102 | |||
103 | /** |
||
104 | * @return string Twig body |
||
105 | */ |
||
106 | 5 | public function getContent () |
|
110 | |||
111 | /** |
||
112 | * Returns the type of the PageView |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 11 | public function getType () |
|
120 | |||
121 | /** |
||
122 | * A fallback for the site menus that use the `url` field. |
||
123 | * |
||
124 | * @deprecated 0.1.0 |
||
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) |
|
144 | { |
||
145 | 6 | $instance = new self($filePath); |
|
146 | |||
147 | 6 | if (isset($instance->getFrontMatter(false)['collection'])) |
|
148 | 6 | { |
|
149 | 4 | return (new DynamicPageView($filePath)); |
|
150 | } |
||
151 | |||
152 | 2 | $instance->getFrontMatter(); |
|
153 | |||
154 | 2 | if ($instance->hasExpandedFrontMatter()) |
|
155 | 2 | { |
|
156 | return (new RepeaterPageView($filePath)); |
||
157 | } |
||
158 | |||
159 | 2 | return $instance; |
|
160 | } |
||
161 | |||
162 | // |
||
163 | // Virtual PageViews |
||
164 | // ================= |
||
165 | |||
166 | /** |
||
167 | * Create a virtual PageView |
||
168 | * |
||
169 | * @param array $frontMatter The Front Matter that this virtual PageView will have |
||
170 | * @param string $body The body of the virtual PageView |
||
171 | * |
||
172 | * @return PageView |
||
173 | */ |
||
174 | public static function createVirtual ($frontMatter, $body) |
||
188 | |||
189 | /** |
||
190 | * Create a virtual PageView to create redirect files |
||
191 | * |
||
192 | * @param string $redirectFrom The URL that will be redirecting to the target location |
||
193 | * @param string $redirectTo The URL of the destination |
||
194 | * @param string|bool $redirectTemplate The path to the template |
||
195 | * |
||
196 | * @return PageView A virtual PageView with the redirection template |
||
197 | */ |
||
198 | public static function createRedirect ($redirectFrom, $redirectTo, $redirectTemplate = false) |
||
222 | } |
||
223 |
This check looks
TODO
comments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.