@@ -32,14 +32,16 @@ discard block |
||
32 | 32 | */ |
33 | 33 | final public function getTargetFile($permalink = null): string |
34 | 34 | { |
35 | - if ($permalink === null) { |
|
35 | + if ($permalink === null) |
|
36 | + { |
|
36 | 37 | $permalink = $this->getPermalink(); |
37 | 38 | } |
38 | 39 | |
39 | 40 | $missingFile = substr((string)$permalink, -1) == '/'; |
40 | 41 | $permalink = str_replace('/', DIRECTORY_SEPARATOR, (string)$permalink); |
41 | 42 | |
42 | - if ($missingFile) { |
|
43 | + if ($missingFile) |
|
44 | + { |
|
43 | 45 | $permalink = rtrim($permalink, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'index.html'; |
44 | 46 | } |
45 | 47 | |
@@ -65,7 +67,8 @@ discard block |
||
65 | 67 | */ |
66 | 68 | final public function getRedirects(): array |
67 | 69 | { |
68 | - if ($this->redirects === null) { |
|
70 | + if ($this->redirects === null) |
|
71 | + { |
|
69 | 72 | $this->getPermalink(); |
70 | 73 | } |
71 | 74 | |
@@ -85,14 +88,16 @@ discard block |
||
85 | 88 | $cleanPath = ltrim($cleanPath, DIRECTORY_SEPARATOR); |
86 | 89 | |
87 | 90 | // Handle vfs:// paths by replacing their forward slashes with the OS appropriate directory separator |
88 | - if (DIRECTORY_SEPARATOR !== '/') { |
|
91 | + if (DIRECTORY_SEPARATOR !== '/') |
|
92 | + { |
|
89 | 93 | $cleanPath = str_replace('/', DIRECTORY_SEPARATOR, $cleanPath); |
90 | 94 | } |
91 | 95 | |
92 | 96 | // Check the first folder and see if it's a data folder (starts with an underscore) intended for stakx |
93 | 97 | $folders = explode(DIRECTORY_SEPARATOR, $cleanPath); |
94 | 98 | |
95 | - if (str_starts_with($folders[0], '_')) { |
|
99 | + if (str_starts_with($folders[0], '_')) |
|
100 | + { |
|
96 | 101 | array_shift($folders); |
97 | 102 | } |
98 | 103 | |
@@ -117,7 +122,8 @@ discard block |
||
117 | 122 | // Remove all disallowed characters |
118 | 123 | $permalink = preg_replace('/[^0-9a-zA-Z-_\/\\\.]/', '', $permalink); |
119 | 124 | |
120 | - if (in_array(fs::getExtension($permalink), self::$extensionsToStrip)) { |
|
125 | + if (in_array(fs::getExtension($permalink), self::$extensionsToStrip)) |
|
126 | + { |
|
121 | 127 | $permalink = fs::removeExtension($permalink); |
122 | 128 | } |
123 | 129 | |
@@ -125,7 +131,8 @@ discard block |
||
125 | 131 | $permalink = preg_replace('/^[^0-9a-zA-Z-_]*/', '', $permalink); |
126 | 132 | |
127 | 133 | // Convert permalinks to lower case |
128 | - if (!Service::hasRunTimeFlag(RuntimeStatus::COMPILER_PRESERVE_CASE)) { |
|
134 | + if (!Service::hasRunTimeFlag(RuntimeStatus::COMPILER_PRESERVE_CASE)) |
|
135 | + { |
|
129 | 136 | $permalink = mb_strtolower($permalink, 'UTF-8'); |
130 | 137 | } |
131 | 138 |
@@ -58,17 +58,21 @@ discard block |
||
58 | 58 | $parser->addComplexVariables($complexVariables); |
59 | 59 | $parser->parse(); |
60 | 60 | |
61 | - if (!is_null($parser) && $parser->hasExpansion()) { |
|
61 | + if (!is_null($parser) && $parser->hasExpansion()) |
|
62 | + { |
|
62 | 63 | throw new LogicException('The permalink for this item has not been set.'); |
63 | 64 | } |
64 | 65 | |
65 | 66 | $permalink = $this->frontMatter['permalink']; |
66 | 67 | |
67 | - if (is_array($permalink)) { |
|
68 | + if (is_array($permalink)) |
|
69 | + { |
|
68 | 70 | $this->permalink = $permalink[0]; |
69 | 71 | array_shift($permalink); |
70 | 72 | $this->redirects = $permalink; |
71 | - } else { |
|
73 | + } |
|
74 | + else |
|
75 | + { |
|
72 | 76 | $this->permalink = $permalink; |
73 | 77 | $this->redirects = []; |
74 | 78 | } |
@@ -166,15 +170,18 @@ discard block |
||
166 | 170 | { |
167 | 171 | $fxnCall = 'get' . ucfirst((string)$offset); |
168 | 172 | |
169 | - if (in_array($fxnCall, FrontMatterDocument::$whiteListedFunctions) && method_exists($this, $fxnCall)) { |
|
173 | + if (in_array($fxnCall, FrontMatterDocument::$whiteListedFunctions) && method_exists($this, $fxnCall)) |
|
174 | + { |
|
170 | 175 | return call_user_func_array([$this, $fxnCall], []); |
171 | 176 | } |
172 | 177 | |
173 | - if (isset($this->data[$offset])) { |
|
178 | + if (isset($this->data[$offset])) |
|
179 | + { |
|
174 | 180 | return $this->data[$offset]; |
175 | 181 | } |
176 | 182 | |
177 | - if (isset($this->frontMatter[$offset])) { |
|
183 | + if (isset($this->frontMatter[$offset])) |
|
184 | + { |
|
178 | 185 | return $this->frontMatter[$offset]; |
179 | 186 | } |
180 | 187 |
@@ -33,8 +33,10 @@ |
||
33 | 33 | */ |
34 | 34 | public function _getPermalinkWhere(array $where): ?string |
35 | 35 | { |
36 | - foreach ($this->permalinks as $expandedValue) { |
|
37 | - if ($expandedValue->getIterators() === $where) { |
|
36 | + foreach ($this->permalinks as $expandedValue) |
|
37 | + { |
|
38 | + if ($expandedValue->getIterators() === $where) |
|
39 | + { |
|
38 | 40 | return $expandedValue->getEvaluated(); |
39 | 41 | } |
40 | 42 | } |
@@ -78,7 +78,8 @@ |
||
78 | 78 | */ |
79 | 79 | protected function parseTemplateLanguage($bodyContent): string |
80 | 80 | { |
81 | - if ($this->templateEngine !== null) { |
|
81 | + if ($this->templateEngine !== null) |
|
82 | + { |
|
82 | 83 | $this->importDependencies = $this->templateEngine->getTemplateImportDependencies($bodyContent); |
83 | 84 | $this->dataDependencies = [ |
84 | 85 | 'collections' => $this->templateEngine->getAssortmentDependencies('collections', $bodyContent), |
@@ -55,7 +55,8 @@ discard block |
||
55 | 55 | |
56 | 56 | $instance->evaluateFrontMatter([], $complexVariables); |
57 | 57 | |
58 | - if ($instance->hasExpandedFrontMatter()) { |
|
58 | + if ($instance->hasExpandedFrontMatter()) |
|
59 | + { |
|
59 | 60 | return new RepeaterPageView($filePath); |
60 | 61 | } |
61 | 62 | |
@@ -74,7 +75,8 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public static function createVirtual($frontMatter, $body): StaticPageView |
76 | 77 | { |
77 | - if (vfsStreamWrapper::getRoot() == null) { |
|
78 | + if (vfsStreamWrapper::getRoot() == null) |
|
79 | + { |
|
78 | 80 | vfsStream::setup(); |
79 | 81 | } |
80 | 82 | |
@@ -108,12 +110,16 @@ discard block |
||
108 | 110 | |
109 | 111 | $contentItemBody = fs::getInternalResource('redirect.html.twig'); |
110 | 112 | |
111 | - try { |
|
112 | - if (!empty($redirectTemplate)) { |
|
113 | + try |
|
114 | + { |
|
115 | + if (!empty($redirectTemplate)) |
|
116 | + { |
|
113 | 117 | $redirectView = new File($redirectTemplate); |
114 | 118 | $contentItemBody = $redirectView->getContents(); |
115 | 119 | } |
116 | - } catch (Exception $e) { |
|
120 | + } |
|
121 | + catch (Exception $e) |
|
122 | + { |
|
117 | 123 | trigger_error($e->getMessage(), E_USER_WARNING); |
118 | 124 | } |
119 | 125 |
@@ -34,10 +34,12 @@ discard block |
||
34 | 34 | { |
35 | 35 | $fm = $this->getFrontMatter(); |
36 | 36 | |
37 | - if (isset($fm['redirect_from'])) { |
|
37 | + if (isset($fm['redirect_from'])) |
|
38 | + { |
|
38 | 39 | $redirects = $fm['redirect_from']; |
39 | 40 | |
40 | - if (!is_array($redirects)) { |
|
41 | + if (!is_array($redirects)) |
|
42 | + { |
|
41 | 43 | $redirects = [$redirects]; |
42 | 44 | } |
43 | 45 | |
@@ -54,10 +56,12 @@ discard block |
||
54 | 56 | */ |
55 | 57 | public function getContent(): string |
56 | 58 | { |
57 | - if (!$this->bodyContentEvaluated) { |
|
59 | + if (!$this->bodyContentEvaluated) |
|
60 | + { |
|
58 | 61 | $this->bodyContent = $this->parseTemplateLanguage($this->bodyContent); |
59 | 62 | |
60 | - if ($this->markupEngine) { |
|
63 | + if ($this->markupEngine) |
|
64 | + { |
|
61 | 65 | $this->bodyContent = $this->markupEngine->parse($this->bodyContent, $this); |
62 | 66 | } |
63 | 67 |
@@ -62,13 +62,15 @@ |
||
62 | 62 | */ |
63 | 63 | public function getContents(): string |
64 | 64 | { |
65 | - if (!$this->exists()) { |
|
65 | + if (!$this->exists()) |
|
66 | + { |
|
66 | 67 | throw $this->buildNotFoundException(); |
67 | 68 | } |
68 | 69 | |
69 | 70 | $content = file_get_contents($this->getAbsolutePath()); |
70 | 71 | |
71 | - if ($content === false) { |
|
72 | + if ($content === false) |
|
73 | + { |
|
72 | 74 | $error = error_get_last(); |
73 | 75 | |
74 | 76 | throw new RuntimeException($error['message']); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * Get the current File object. |
124 | 124 | */ |
125 | - public function current(): File|Folder |
|
125 | + public function current(): File | Folder |
|
126 | 126 | { |
127 | 127 | /** @var SplFileInfo $current */ |
128 | 128 | $current = parent::current(); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | /** |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function getChildren(): FileExplorer|RecursiveFilterIterator|null |
|
141 | + public function getChildren(): FileExplorer | RecursiveFilterIterator | null |
|
142 | 142 | { |
143 | 143 | $explorer = new self( |
144 | 144 | $this->getInnerIterator()->getChildren(), |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @deprecated use `FileExplorer::createFromDefinition()` instead |
200 | 200 | */ |
201 | - public static function create(string|Folder $folder, array $includes = [], array $excludes = [], ?int $flags = null): FileExplorer |
|
201 | + public static function create(string | Folder $folder, array $includes = [], array $excludes = [], ?int $flags = null): FileExplorer |
|
202 | 202 | { |
203 | 203 | $folder = fs::realpath($folder); |
204 | 204 | $iterator = new RecursiveDirectoryIterator((string)$folder, RecursiveDirectoryIterator::SKIP_DOTS); |
@@ -103,12 +103,15 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function accept(): bool |
105 | 105 | { |
106 | - if (!empty($this->matchers)) { |
|
107 | - foreach ($this->matchers as $matcher) { |
|
106 | + if (!empty($this->matchers)) |
|
107 | + { |
|
108 | + foreach ($this->matchers as $matcher) |
|
109 | + { |
|
108 | 110 | $result = call_user_func($matcher, $this->current()); |
109 | 111 | |
110 | 112 | // If any custom matchers return false, let's exit immediately |
111 | - if ($result === false) { |
|
113 | + if ($result === false) |
|
114 | + { |
|
112 | 115 | return false; |
113 | 116 | } |
114 | 117 | } |
@@ -128,7 +131,8 @@ discard block |
||
128 | 131 | $current = parent::current(); |
129 | 132 | $path = new FilesystemPath($current->getPathname()); |
130 | 133 | |
131 | - if ($current->isDir()) { |
|
134 | + if ($current->isDir()) |
|
135 | + { |
|
132 | 136 | return new Folder($path); |
133 | 137 | } |
134 | 138 | |
@@ -147,7 +151,8 @@ discard block |
||
147 | 151 | $this->flags |
148 | 152 | ); |
149 | 153 | |
150 | - foreach ($this->matchers as $matcher) { |
|
154 | + foreach ($this->matchers as $matcher) |
|
155 | + { |
|
151 | 156 | $explorer->addMatcher($matcher); |
152 | 157 | } |
153 | 158 | |
@@ -167,18 +172,22 @@ discard block |
||
167 | 172 | */ |
168 | 173 | public function matchesPattern(string $filePath): bool |
169 | 174 | { |
170 | - if (self::strpos_array($filePath, $this->includes)) { |
|
175 | + if (self::strpos_array($filePath, $this->includes)) |
|
176 | + { |
|
171 | 177 | return true; |
172 | 178 | } |
173 | - if (($this->flags & self::INCLUDE_ONLY_FILES) && !$this->current()->isDir()) { |
|
179 | + if (($this->flags & self::INCLUDE_ONLY_FILES) && !$this->current()->isDir()) |
|
180 | + { |
|
174 | 181 | return false; |
175 | 182 | } |
176 | - if (($this->flags & self::IGNORE_DIRECTORIES) && $this->current()->isDir()) { |
|
183 | + if (($this->flags & self::IGNORE_DIRECTORIES) && $this->current()->isDir()) |
|
184 | + { |
|
177 | 185 | return false; |
178 | 186 | } |
179 | 187 | |
180 | 188 | if (!($this->flags & self::ALLOW_DOT_FILES) |
181 | - && preg_match('#(^|\\\\|\/)\..+(\\\\|\/|$)#', $filePath) === 1) { |
|
189 | + && preg_match('#(^|\\\\|\/)\..+(\\\\|\/|$)#', $filePath) === 1) |
|
190 | + { |
|
182 | 191 | return false; |
183 | 192 | } |
184 | 193 | |
@@ -218,12 +227,16 @@ discard block |
||
218 | 227 | */ |
219 | 228 | private static function strpos_array(string $haystack, array $needle): bool |
220 | 229 | { |
221 | - foreach ($needle as $query) { |
|
222 | - if ($query[0] === '/' && $query[strlen($query) - 1] === '/' && preg_match($query, $haystack) === 1) { |
|
230 | + foreach ($needle as $query) |
|
231 | + { |
|
232 | + if ($query[0] === '/' && $query[strlen($query) - 1] === '/' && preg_match($query, $haystack) === 1) |
|
233 | + { |
|
223 | 234 | return true; |
224 | 235 | } |
225 | 236 | |
226 | - if (str_contains($haystack, $query)) { // stop on first true result |
|
237 | + if (str_contains($haystack, $query)) |
|
238 | + { |
|
239 | +// stop on first true result |
|
227 | 240 | return true; |
228 | 241 | } |
229 | 242 | } |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | $this->isWindows = $dirSep === '\\'; |
40 | 40 | $this->isVFS = fs::isVFS($filePath); |
41 | 41 | |
42 | - if ($this->isWindows) { |
|
42 | + if ($this->isWindows) |
|
43 | + { |
|
43 | 44 | $filePath = $this->unixifyPath($filePath); |
44 | 45 | } |
45 | 46 | |
@@ -58,7 +59,8 @@ discard block |
||
58 | 59 | */ |
59 | 60 | public function appendToPath($append): self |
60 | 61 | { |
61 | - if ($this->isFile(false)) { |
|
62 | + if ($this->isFile(false)) |
|
63 | + { |
|
62 | 64 | throw new InvalidArgumentException("Appending to a file's path is not possible"); |
63 | 65 | } |
64 | 66 | |
@@ -86,7 +88,8 @@ discard block |
||
86 | 88 | */ |
87 | 89 | public function getAbsolutePath(): string |
88 | 90 | { |
89 | - if (!$this->isVFS && $this->isWindows) { |
|
91 | + if (!$this->isVFS && $this->isWindows) |
|
92 | + { |
|
90 | 93 | return str_replace('/', '\\', $this->absolutePath); |
91 | 94 | } |
92 | 95 | |
@@ -112,7 +115,8 @@ discard block |
||
112 | 115 | { |
113 | 116 | $absPath = $this->absolutePath; |
114 | 117 | |
115 | - if ($checkExistence) { |
|
118 | + if ($checkExistence) |
|
119 | + { |
|
116 | 120 | return file_exists($absPath) && is_dir($absPath); |
117 | 121 | } |
118 | 122 | |
@@ -130,7 +134,8 @@ discard block |
||
130 | 134 | { |
131 | 135 | $absPath = $this->absolutePath; |
132 | 136 | |
133 | - if ($checkExistence) { |
|
137 | + if ($checkExistence) |
|
138 | + { |
|
134 | 139 | return file_exists($absPath) && is_file($absPath); |
135 | 140 | } |
136 | 141 | |
@@ -147,8 +152,10 @@ discard block |
||
147 | 152 | { |
148 | 153 | $paths = []; |
149 | 154 | |
150 | - foreach (func_get_args() as $arg) { |
|
151 | - if ($arg !== '') { |
|
155 | + foreach (func_get_args() as $arg) |
|
156 | + { |
|
157 | + if ($arg !== '') |
|
158 | + { |
|
152 | 159 | $paths[] = $arg; |
153 | 160 | } |
154 | 161 | } |