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 | * {@inheritdoc} |
||
56 | */ |
||
57 | 16 | public function getObjectName() |
|
61 | |||
62 | // |
||
63 | // Twig Jail |
||
64 | // ========= |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 24 | public function createJail() |
|
70 | { |
||
71 | 24 | if (is_null($this->jailInstance)) |
|
72 | 24 | { |
|
73 | 24 | $this->jailInstance = (new JailedDocument($this, array_merge(self::$whiteListFunctions, array( |
|
74 | 24 | 'getUrl', |
|
75 | 24 | )), array('getChildren' => 'getJailedChildren'))); |
|
76 | 24 | } |
|
77 | |||
78 | 24 | return $this->jailInstance; |
|
79 | } |
||
80 | |||
81 | 3 | public function getJailedChildren() |
|
82 | { |
||
83 | 3 | $children = $this->children; |
|
84 | |||
85 | 3 | foreach ($children as &$child) |
|
86 | { |
||
87 | 3 | $child = $child->createJail(); |
|
88 | 3 | } |
|
89 | |||
90 | 3 | return $children; |
|
91 | } |
||
92 | |||
93 | // |
||
94 | // Getters |
||
95 | // ======= |
||
96 | |||
97 | /** |
||
98 | * Get child PageViews. |
||
99 | * |
||
100 | * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of |
||
101 | * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent. |
||
102 | * |
||
103 | * @return PageView[] |
||
104 | */ |
||
105 | 3 | public function &getChildren() |
|
109 | |||
110 | /** |
||
111 | * @return string Twig body |
||
112 | */ |
||
113 | 14 | public function getContent() |
|
117 | |||
118 | /** |
||
119 | * Returns the type of the PageView. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 20 | public function getType() |
|
127 | |||
128 | /** |
||
129 | * A fallback for the site menus that use the `url` field. |
||
130 | * |
||
131 | * @deprecated 0.1.0 |
||
132 | * |
||
133 | * @todo Remove this in the next major release |
||
134 | */ |
||
135 | public function getUrl() |
||
139 | |||
140 | // |
||
141 | // Factory |
||
142 | // ======= |
||
143 | |||
144 | /** |
||
145 | * Create the appropriate object type when parsing a PageView. |
||
146 | * |
||
147 | * @param string $filePath The path to the file that will be parsed into a PageView |
||
148 | * |
||
149 | * @return DynamicPageView|PageView|RepeaterPageView |
||
150 | */ |
||
151 | 6 | public static function create($filePath) |
|
170 | |||
171 | // |
||
172 | // Virtual PageViews |
||
173 | // ================= |
||
174 | |||
175 | /** |
||
176 | * Create a virtual PageView. |
||
177 | * |
||
178 | * @param array $frontMatter The Front Matter that this virtual PageView will have |
||
179 | * @param string $body The body of the virtual PageView |
||
180 | * |
||
181 | * @return PageView |
||
182 | */ |
||
183 | 4 | public static function createVirtual($frontMatter, $body) |
|
197 | |||
198 | /** |
||
199 | * Create a virtual PageView to create redirect files. |
||
200 | * |
||
201 | * @param string $redirectFrom The URL that will be redirecting to the target location |
||
202 | * @param string $redirectTo The URL of the destination |
||
203 | * @param string|bool $redirectTemplate The path to the template |
||
204 | * |
||
205 | * @return PageView A virtual PageView with the redirection template |
||
206 | */ |
||
207 | 4 | public static function createRedirect($redirectFrom, $redirectTo, $redirectTemplate = false) |
|
231 | } |
||
232 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.