1 | <?php |
||
16 | class PageView extends FrontMatterObject |
||
17 | { |
||
18 | const TEMPLATE = "---\n%s\n---\n\n%s"; |
||
19 | |||
20 | const REPEATER_TYPE = 0; |
||
21 | const DYNAMIC_TYPE = 1; |
||
22 | const STATIC_TYPE = 2; |
||
23 | |||
24 | /** |
||
25 | * @var vfsStreamDirectory |
||
26 | */ |
||
27 | private static $vfsRoot; |
||
28 | |||
29 | /** |
||
30 | * @var Filesystem |
||
31 | */ |
||
32 | private static $fileSys; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $type; |
||
38 | |||
39 | /** |
||
40 | * @var PageView[] |
||
41 | */ |
||
42 | private $children; |
||
43 | |||
44 | /** |
||
45 | * @var JailObject |
||
46 | */ |
||
47 | private $jailInstance; |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 23 | public function __construct($filePath) |
|
59 | |||
60 | // |
||
61 | // Twig Jail |
||
62 | // ========= |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 17 | public function createJail() |
|
78 | |||
79 | 3 | public function getJailedChildren() |
|
90 | |||
91 | // |
||
92 | // Getters |
||
93 | // ======= |
||
94 | |||
95 | /** |
||
96 | * Get child PageViews. |
||
97 | * |
||
98 | * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of |
||
99 | * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent. |
||
100 | * |
||
101 | * @return PageView[] |
||
102 | */ |
||
103 | 3 | public function &getChildren() |
|
107 | |||
108 | /** |
||
109 | * @return string Twig body |
||
110 | */ |
||
111 | 5 | public function getContent() |
|
115 | |||
116 | /** |
||
117 | * Returns the type of the PageView. |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 11 | public function getType() |
|
125 | |||
126 | /** |
||
127 | * A fallback for the site menus that use the `url` field. |
||
128 | * |
||
129 | * @deprecated 0.1.0 |
||
130 | * |
||
131 | * @todo Remove this in the next major release |
||
132 | */ |
||
133 | public function getUrl() |
||
137 | |||
138 | // |
||
139 | // Factory |
||
140 | // ======= |
||
141 | |||
142 | /** |
||
143 | * Create the appropriate object type when parsing a PageView. |
||
144 | * |
||
145 | * @param string $filePath The path to the file that will be parsed into a PageView |
||
146 | * |
||
147 | * @return DynamicPageView|PageView|RepeaterPageView |
||
148 | */ |
||
149 | 6 | public static function create($filePath) |
|
167 | |||
168 | // |
||
169 | // Virtual PageViews |
||
170 | // ================= |
||
171 | |||
172 | /** |
||
173 | * Create a virtual PageView. |
||
174 | * |
||
175 | * @param array $frontMatter The Front Matter that this virtual PageView will have |
||
176 | * @param string $body The body of the virtual PageView |
||
177 | * |
||
178 | * @return PageView |
||
179 | */ |
||
180 | public static function createVirtual($frontMatter, $body) |
||
194 | |||
195 | /** |
||
196 | * Create a virtual PageView to create redirect files. |
||
197 | * |
||
198 | * @param string $redirectFrom The URL that will be redirecting to the target location |
||
199 | * @param string $redirectTo The URL of the destination |
||
200 | * @param string|bool $redirectTemplate The path to the template |
||
201 | * |
||
202 | * @return PageView A virtual PageView with the redirection template |
||
203 | */ |
||
204 | public static function createRedirect($redirectFrom, $redirectTo, $redirectTemplate = false) |
||
228 | } |
||
229 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.