@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | $configuration = $event->getConfiguration()->getConfiguration(); |
42 | 42 | |
43 | 43 | /** @var AssetEngineInterface $engine */ |
44 | - foreach ($this->assetEngineManager->getEngines() as $engine) { |
|
44 | + foreach ($this->assetEngineManager->getEngines() as $engine) |
|
45 | + { |
|
45 | 46 | $defaults = __::get($configuration, $engine->getConfigurationNamespace(), []); |
46 | 47 | $options = array_merge($engine->getDefaultConfiguration(), $defaults); |
47 | 48 | |
@@ -55,17 +56,20 @@ discard block |
||
55 | 56 | * @var string $folder |
56 | 57 | * @var AssetEngineInterface $engine |
57 | 58 | */ |
58 | - foreach ($this->assetEngineManager->getFoldersToWatch() as $folder => $engine) { |
|
59 | + foreach ($this->assetEngineManager->getFoldersToWatch() as $folder => $engine) |
|
60 | + { |
|
59 | 61 | $assetFolder = fs::absolutePath($folder); |
60 | 62 | |
61 | - if (!fs::exists($assetFolder)) { |
|
63 | + if (!fs::exists($assetFolder)) |
|
64 | + { |
|
62 | 65 | continue; |
63 | 66 | } |
64 | 67 | |
65 | 68 | $engine->setPageManager($event->getPageManager()); |
66 | 69 | $extensions = []; |
67 | 70 | |
68 | - foreach ($engine->getExtensions() as $extension) { |
|
71 | + foreach ($engine->getExtensions() as $extension) |
|
72 | + { |
|
69 | 73 | $extensions[] = "/.{$extension}.twig$/"; |
70 | 74 | } |
71 | 75 | |
@@ -75,15 +79,19 @@ discard block |
||
75 | 79 | $definition->flags = FileExplorer::INCLUDE_ONLY_FILES | FileExplorer::IGNORE_DIRECTORIES; |
76 | 80 | $explorer = FileExplorer::createFromDefinition($definition); |
77 | 81 | |
78 | - foreach ($explorer as $file) { |
|
82 | + foreach ($explorer as $file) |
|
83 | + { |
|
79 | 84 | $assetPageView = new StaticPageView($file); |
80 | 85 | |
81 | - try { |
|
86 | + try |
|
87 | + { |
|
82 | 88 | $event->getPageManager()->trackNewPageView($assetPageView); |
83 | 89 | $this->assetPageViews[$assetPageView->getRelativeFilePath()] = [ |
84 | 90 | 'engine' => $engine, |
85 | 91 | ]; |
86 | - } catch (Exception $e) { |
|
92 | + } |
|
93 | + catch (Exception $e) |
|
94 | + { |
|
87 | 95 | $this->logger->error('An exception occurred while creating a Static PageView for an AssetEngine'); |
88 | 96 | $this->logger->error(' {message}', [ |
89 | 97 | 'message' => $e->getMessage(), |
@@ -98,12 +106,14 @@ discard block |
||
98 | 106 | $pageView = $event->getPageView(); |
99 | 107 | $filePath = $pageView->getRelativeFilePath(); |
100 | 108 | |
101 | - if (isset($this->assetPageViews[$filePath])) { |
|
109 | + if (isset($this->assetPageViews[$filePath])) |
|
110 | + { |
|
102 | 111 | /** @var AssetEngineInterface $engine */ |
103 | 112 | $engine = $this->assetPageViews[$filePath]['engine']; |
104 | 113 | $cacheDir = $this->buildCacheFolder($engine); |
105 | 114 | |
106 | - if (Service::hasRunTimeFlag(RuntimeStatus::USING_CACHE)) { |
|
115 | + if (Service::hasRunTimeFlag(RuntimeStatus::USING_CACHE)) |
|
116 | + { |
|
107 | 117 | $engine->loadCache($cacheDir); |
108 | 118 | } |
109 | 119 |
@@ -25,12 +25,12 @@ |
||
25 | 25 | |
26 | 26 | private $pageView; |
27 | 27 | |
28 | - public function __construct(BasePageView &$pageView) |
|
28 | + public function __construct(BasePageView & $pageView) |
|
29 | 29 | { |
30 | 30 | $this->pageView = &$pageView; |
31 | 31 | } |
32 | 32 | |
33 | - public function &getPageView(): BasePageView|DynamicPageView|RepeaterPageView|StaticPageView |
|
33 | + public function &getPageView(): BasePageView | DynamicPageView | RepeaterPageView | StaticPageView |
|
34 | 34 | { |
35 | 35 | return $this->pageView; |
36 | 36 | } |
@@ -25,7 +25,8 @@ |
||
25 | 25 | */ |
26 | 26 | public function setCompiledOutput($compiledOutput): void |
27 | 27 | { |
28 | - if (!StrUtils::canBeCastedToString($compiledOutput)) { |
|
28 | + if (!StrUtils::canBeCastedToString($compiledOutput)) |
|
29 | + { |
|
29 | 30 | @trigger_error('CompileProcessPostRenderPageView :: Value cannot be set to something that cannot be cast into a string.', E_USER_WARNING); |
30 | 31 | |
31 | 32 | return; |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * |
23 | 23 | * @return false|self returns false when template is not extending anything |
24 | 24 | */ |
25 | - public function getParentTemplate(): false|self; |
|
25 | + public function getParentTemplate(): false | self; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Render the template with the given context. |
@@ -22,11 +22,13 @@ |
||
22 | 22 | $this->dir = fs::getFolderPath(Service::getOption('currentTemplate')); |
23 | 23 | $this->path = fs::appendPath($this->dir, $location); |
24 | 24 | |
25 | - if (is_file($this->path)) { |
|
25 | + if (is_file($this->path)) |
|
26 | + { |
|
26 | 27 | $this->path = realpath($this->path); |
27 | 28 | } |
28 | 29 | |
29 | - if (!str_starts_with((string)$this->path, (string)Service::getWorkingDirectory())) { |
|
30 | + if (!str_starts_with((string)$this->path, (string)Service::getWorkingDirectory())) |
|
31 | + { |
|
30 | 32 | throw new FileNotFoundException(sprintf( |
31 | 33 | "The '%s' file could not be found or is outside the website working directory", |
32 | 34 | $location |
@@ -32,13 +32,15 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function filter($html, $beforeHeading = false, $anchorAttrs = [], $anchorBody = '', $anchorClass = '', $anchorTitle = '', $hMin = 1, $hMax = 6): string |
34 | 34 | { |
35 | - if (!function_exists('simplexml_load_string')) { |
|
35 | + if (!function_exists('simplexml_load_string')) |
|
36 | + { |
|
36 | 37 | trigger_error('XML support is not available with the current PHP installation.', E_USER_WARNING); |
37 | 38 | |
38 | 39 | return $html; |
39 | 40 | } |
40 | 41 | |
41 | - if ($anchorClass) { |
|
42 | + if ($anchorClass) |
|
43 | + { |
|
42 | 44 | $anchorAttrs['class'] = $anchorClass; |
43 | 45 | } |
44 | 46 | |
@@ -47,16 +49,19 @@ discard block |
||
47 | 49 | $headings = HtmlUtils::htmlXPath($dom, $html, '//h1|//h2|//h3|//h4|//h5|//h6'); |
48 | 50 | |
49 | 51 | /** @var DOMElement $heading */ |
50 | - foreach ($headings as $heading) { |
|
52 | + foreach ($headings as $heading) |
|
53 | + { |
|
51 | 54 | $headingID = $heading->attributes->getNamedItem('id'); |
52 | 55 | |
53 | - if ($headingID === null) { |
|
56 | + if ($headingID === null) |
|
57 | + { |
|
54 | 58 | continue; |
55 | 59 | } |
56 | 60 | |
57 | 61 | sscanf($heading->tagName, 'h%u', $currLvl); |
58 | 62 | |
59 | - if (!($hMin <= $currLvl && $currLvl <= $hMax)) { |
|
63 | + if (!($hMin <= $currLvl && $currLvl <= $hMax)) |
|
64 | + { |
|
60 | 65 | continue; |
61 | 66 | } |
62 | 67 | |
@@ -67,35 +72,45 @@ discard block |
||
67 | 72 | '{heading}' => $heading->textContent, |
68 | 73 | ]); |
69 | 74 | |
70 | - if (str_starts_with($body, '<')) { |
|
75 | + if (str_starts_with($body, '<')) |
|
76 | + { |
|
71 | 77 | $domAnchorBody = new DOMDocument(); |
72 | 78 | $loaded = @$domAnchorBody->loadHTML($body, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); |
73 | 79 | |
74 | - if ($loaded) { |
|
80 | + if ($loaded) |
|
81 | + { |
|
75 | 82 | /** @var DOMElement $childNode */ |
76 | - foreach ($domAnchorBody->childNodes as $childNode) { |
|
83 | + foreach ($domAnchorBody->childNodes as $childNode) |
|
84 | + { |
|
77 | 85 | $node = $anchor->ownerDocument->importNode($childNode->cloneNode(true), true); |
78 | 86 | $anchor->appendChild($node); |
79 | 87 | } |
80 | 88 | } |
81 | - } else { |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
82 | 92 | $anchor->nodeValue = $body; |
83 | 93 | } |
84 | 94 | |
85 | - if ($anchorTitle) { |
|
95 | + if ($anchorTitle) |
|
96 | + { |
|
86 | 97 | $anchorAttrs['title'] = strtr($anchorTitle, [ |
87 | 98 | '{heading}' => $heading->textContent, |
88 | 99 | ]); |
89 | 100 | } |
90 | 101 | |
91 | - foreach ($anchorAttrs as $attrName => $attrValue) { |
|
102 | + foreach ($anchorAttrs as $attrName => $attrValue) |
|
103 | + { |
|
92 | 104 | $anchor->setAttribute($attrName, $attrValue); |
93 | 105 | } |
94 | 106 | |
95 | - if ($beforeHeading) { |
|
107 | + if ($beforeHeading) |
|
108 | + { |
|
96 | 109 | $heading->insertBefore($dom->createTextNode(' '), $heading->childNodes[0]); |
97 | 110 | $heading->insertBefore($anchor, $heading->childNodes[0]); |
98 | - } else { |
|
111 | + } |
|
112 | + else |
|
113 | + { |
|
99 | 114 | $heading->appendChild($dom->createTextNode(' ')); |
100 | 115 | $heading->appendChild($anchor); |
101 | 116 | } |
@@ -14,24 +14,29 @@ |
||
14 | 14 | { |
15 | 15 | public function __invoke($array, $key, $order = 'ASC', $case_insensitive = false) |
16 | 16 | { |
17 | - if (!is_array($array)) { |
|
17 | + if (!is_array($array)) |
|
18 | + { |
|
18 | 19 | return $array; |
19 | 20 | } |
20 | 21 | |
21 | - usort($array, function ($a, $b) use ($key, $order, $case_insensitive) { |
|
22 | + usort($array, function ($a, $b) use ($key, $order, $case_insensitive) |
|
23 | + { |
|
22 | 24 | $aValue = __::get($a, $key); |
23 | 25 | $bValue = __::get($b, $key); |
24 | 26 | |
25 | - if ($case_insensitive) { |
|
27 | + if ($case_insensitive) |
|
28 | + { |
|
26 | 29 | $aValue = strtolower($aValue); |
27 | 30 | $bValue = strtolower($bValue); |
28 | 31 | } |
29 | 32 | |
30 | - if ($aValue == $bValue) { |
|
33 | + if ($aValue == $bValue) |
|
34 | + { |
|
31 | 35 | return 0; |
32 | 36 | } |
33 | 37 | |
34 | - if (strtolower((string)$order) === 'desc') { |
|
38 | + if (strtolower((string)$order) === 'desc') |
|
39 | + { |
|
35 | 40 | return ($aValue < $bValue) ? 1 : -1; |
36 | 41 | } |
37 | 42 |
@@ -16,19 +16,23 @@ |
||
16 | 16 | { |
17 | 17 | $results = []; |
18 | 18 | |
19 | - foreach ($array as $item) { |
|
19 | + foreach ($array as $item) |
|
20 | + { |
|
20 | 21 | $results[] = __::get($item, $key); |
21 | 22 | } |
22 | 23 | |
23 | - if ($flatten) { |
|
24 | + if ($flatten) |
|
25 | + { |
|
24 | 26 | $results = __::flatten($results); |
25 | 27 | |
26 | - if ($distinct) { |
|
28 | + if ($distinct) |
|
29 | + { |
|
27 | 30 | $results = array_values(array_unique($results)); |
28 | 31 | } |
29 | 32 | } |
30 | 33 | |
31 | - if ($ignore_null) { |
|
34 | + if ($ignore_null) |
|
35 | + { |
|
32 | 36 | $results = array_values(array_filter($results)); |
33 | 37 | } |
34 | 38 |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | { |
16 | 16 | public function __invoke($value, $paragraphCount = 1) |
17 | 17 | { |
18 | - if (!extension_loaded('dom')) { |
|
18 | + if (!extension_loaded('dom')) |
|
19 | + { |
|
19 | 20 | @trigger_error('The DOM Extension is not loaded and is necessary for the "summary" Twig filter.', E_WARNING); |
20 | 21 | |
21 | 22 | return $value; |
@@ -26,7 +27,8 @@ discard block |
||
26 | 27 | |
27 | 28 | $summary = ''; |
28 | 29 | |
29 | - foreach ($paragraphs as $paragraph) { |
|
30 | + foreach ($paragraphs as $paragraph) |
|
31 | + { |
|
30 | 32 | $summary .= $dom->saveHTML($paragraph); |
31 | 33 | } |
32 | 34 |