@@ -86,11 +86,11 @@ |
||
86 | 86 | /** @noinspection PhpIncludeInspection */ |
87 | 87 | include( $realPath ); |
88 | 88 | $rendered = ob_get_clean(); |
89 | - }elseif ($this->templateString) { |
|
89 | + } elseif ($this->templateString) { |
|
90 | 90 | ob_start(); |
91 | 91 | eval( "?>" . $this->templateString ); |
92 | 92 | $rendered = ob_get_clean(); |
93 | - }else { |
|
93 | + } else { |
|
94 | 94 | throw new \Exception( "Neither valid template path no valid template string passed to PhpTemplate." ); |
95 | 95 | } |
96 | 96 |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | $templatePath = null, |
52 | 52 | $templateString = null, |
53 | 53 | ResourceRepository $repo = null |
54 | - ){ |
|
55 | - parent::__construct( $component ); |
|
54 | + ) { |
|
55 | + parent::__construct($component); |
|
56 | 56 | $this->templatePath = $templatePath; |
57 | 57 | $this->templateString = $templateString; |
58 | 58 | // Optional Puli repo |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @return Response |
66 | 66 | * @throws \Exception |
67 | 67 | */ |
68 | - protected function doRender( ViewState $state, array $props = [ ] ) |
|
68 | + protected function doRender(ViewState $state, array $props = [ ]) |
|
69 | 69 | { |
70 | 70 | // Available variables in template file are: |
71 | 71 | // $state |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | /** @noinspection PhpUnusedLocalVariableInspection */ |
82 | 82 | $exec = $this->component->exec; |
83 | 83 | if ($this->templatePath) { |
84 | - $realPath = $this->getRealTemplatePath( $this->templatePath ); |
|
84 | + $realPath = $this->getRealTemplatePath($this->templatePath); |
|
85 | 85 | ob_start(); |
86 | 86 | /** @noinspection PhpIncludeInspection */ |
87 | - include( $realPath ); |
|
87 | + include($realPath); |
|
88 | 88 | $rendered = ob_get_clean(); |
89 | 89 | }elseif ($this->templateString) { |
90 | 90 | ob_start(); |
91 | - eval( "?>" . $this->templateString ); |
|
91 | + eval("?>".$this->templateString); |
|
92 | 92 | $rendered = ob_get_clean(); |
93 | 93 | }else { |
94 | - throw new \Exception( "Neither valid template path no valid template string passed to PhpTemplate." ); |
|
94 | + throw new \Exception("Neither valid template path no valid template string passed to PhpTemplate."); |
|
95 | 95 | } |
96 | 96 | |
97 | - return new Response( "text/html", $rendered ); |
|
97 | + return new Response("text/html", $rendered); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,18 +102,18 @@ discard block |
||
102 | 102 | * @return null|string |
103 | 103 | * @throws \Exception |
104 | 104 | */ |
105 | - private function getRealTemplatePath( $templatePath ) |
|
105 | + private function getRealTemplatePath($templatePath) |
|
106 | 106 | { |
107 | 107 | if ($this->repo instanceof ResourceRepository) { |
108 | - if ($this->repo->contains( $templatePath )) { |
|
109 | - return $this->repo->get( $templatePath ) |
|
108 | + if ($this->repo->contains($templatePath)) { |
|
109 | + return $this->repo->get($templatePath) |
|
110 | 110 | ->getFilesystemPath(); |
111 | 111 | } |
112 | 112 | } |
113 | - if (file_exists( $templatePath )) { |
|
113 | + if (file_exists($templatePath)) { |
|
114 | 114 | return $templatePath; |
115 | 115 | } |
116 | - throw new \Exception( "Template path not found in repository or on filesystem: {$templatePath}, in PhpTemplate" ); |
|
116 | + throw new \Exception("Template path not found in repository or on filesystem: {$templatePath}, in PhpTemplate"); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
@@ -40,16 +40,16 @@ |
||
40 | 40 | * @param string $content |
41 | 41 | * @param int|null $responseCode |
42 | 42 | */ |
43 | - public function __construct( $type, $content, $responseCode = null ) |
|
43 | + public function __construct($type, $content, $responseCode = null) |
|
44 | 44 | { |
45 | 45 | $this->type = $type; |
46 | 46 | $this->content = $content; |
47 | 47 | |
48 | 48 | // Response code defaults |
49 | 49 | if (null === $responseCode) { |
50 | - if( $type == "redirect" ){ |
|
50 | + if ($type == "redirect") { |
|
51 | 51 | $responseCode = 302; |
52 | - }else{ |
|
52 | + }else { |
|
53 | 53 | $responseCode = 200; |
54 | 54 | } |
55 | 55 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | if (null === $responseCode) { |
50 | 50 | if( $type == "redirect" ){ |
51 | 51 | $responseCode = 302; |
52 | - }else{ |
|
52 | + } else{ |
|
53 | 53 | $responseCode = 200; |
54 | 54 | } |
55 | 55 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Class AbstractTemplate |
26 | 26 | * @package PatternSeek\ComponentView |
27 | 27 | */ |
28 | -abstract class AbstractTemplate{ |
|
28 | +abstract class AbstractTemplate { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var AbstractViewComponent |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @param AbstractViewComponent $component |
37 | 37 | */ |
38 | - public function __construct( AbstractViewComponent $component ){ |
|
38 | + public function __construct(AbstractViewComponent $component) { |
|
39 | 39 | $this->component = $component; |
40 | 40 | } |
41 | 41 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param array $props |
46 | 46 | * @return Response |
47 | 47 | */ |
48 | - public function render( ViewState $state, array $props = [] ) |
|
48 | + public function render(ViewState $state, array $props = [ ]) |
|
49 | 49 | { |
50 | - return $this->doRender( $state, $props ); |
|
50 | + return $this->doRender($state, $props); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,6 +55,6 @@ discard block |
||
55 | 55 | * @param array $props |
56 | 56 | * @return Response |
57 | 57 | */ |
58 | - abstract protected function doRender( ViewState $state, array $props = [] ); |
|
58 | + abstract protected function doRender(ViewState $state, array $props = [ ]); |
|
59 | 59 | |
60 | 60 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | protected $component; |
20 | 20 | |
21 | - public function setComponent( AbstractViewComponent $component ) |
|
21 | + public function setComponent(AbstractViewComponent $component) |
|
22 | 22 | { |
23 | 23 | $this->component = $component; |
24 | 24 | } |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | * @param bool $onlyComponentOutput |
31 | 31 | * @return string A URL or URI |
32 | 32 | */ |
33 | - public function url( $execMethod, $args = [ ], $onlyComponentOutput = false ) // $onlyComponentOutput Not used in this implementation but necessary for subclasses |
|
33 | + public function url($execMethod, $args = [ ], $onlyComponentOutput = false) // $onlyComponentOutput Not used in this implementation but necessary for subclasses |
|
34 | 34 | { |
35 | 35 | // $onlyComponentOutput is not used in this implementation but may be by sub-classes |
36 | - $args[ 'exec' ] = $this->component->getExecPath( $execMethod ); |
|
37 | - $qs = http_build_query( $args ); |
|
36 | + $args[ 'exec' ] = $this->component->getExecPath($execMethod); |
|
37 | + $qs = http_build_query($args); |
|
38 | 38 | return "?{$qs}"; |
39 | 39 | } |
40 | 40 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | return <<<EOS |
70 | 70 | <form method="{$method}" action=""{$formID}{$onSubmit} enctype="{$encType}"> |
71 | - <input type="hidden" name="exec" value="{$this->component->getExecPath( $execMethod )}"> |
|
71 | + <input type="hidden" name="exec" value="{$this->component->getExecPath($execMethod)}"> |
|
72 | 72 | {$formBody} |
73 | 73 | </form> |
74 | 74 | EOS; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | public function callStatic($class, $function, $args = array()) |
85 | 85 | { |
86 | 86 | if (class_exists($class) && method_exists($class, $function)) { |
87 | - return call_user_func_array( array( $class, $function ), $args ); |
|
87 | + return call_user_func_array(array($class, $function), $args); |
|
88 | 88 | } |
89 | 89 | return null; |
90 | 90 | } |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | * @param array $anchorAttrs |
99 | 99 | * @return string |
100 | 100 | */ |
101 | - public function replaceElementUsingLink( $execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ] ) |
|
101 | + public function replaceElementUsingLink($execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ]) |
|
102 | 102 | { |
103 | - $url = $this->url( $execMethod, $args, true ); |
|
103 | + $url = $this->url($execMethod, $args, true); |
|
104 | 104 | $attrs = [ ]; |
105 | 105 | foreach ($anchorAttrs as $k => $v) { |
106 | 106 | $attrs[ ] = "{$k}='{$v}'"; |
107 | 107 | } |
108 | - $attrsStr = implode( ' ', $attrs ); |
|
108 | + $attrsStr = implode(' ', $attrs); |
|
109 | 109 | return <<<EOS |
110 | 110 | <script type="application/javascript"> |
111 | 111 | if( typeof(execLink) != "function" ){ |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | * @param string $encType |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function replaceElementUsingForm( $execMethod, $method, $formBody, $targetDiv, $formID, $encType = 'application/x-www-form-urlencoded' ) |
|
141 | + public function replaceElementUsingForm($execMethod, $method, $formBody, $targetDiv, $formID, $encType = 'application/x-www-form-urlencoded') |
|
142 | 142 | { |
143 | 143 | return <<<EOS |
144 | - {$this->wrapForm( $execMethod, $method, $formBody, true, $formID, |
|
145 | - "execForm( this, \"{$targetDiv}\" ); return false;", $encType )} |
|
144 | + {$this->wrapForm($execMethod, $method, $formBody, true, $formID, |
|
145 | + "execForm( this, \"{$targetDiv}\" ); return false;", $encType)} |
|
146 | 146 | <script type="application/javascript"> |
147 | 147 | if( typeof(execForm) != "function" ){ |
148 | 148 | var execForm = function( form, targetDiv ){ |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | $templatePath = null, |
58 | 58 | $templateString = null, |
59 | 59 | ResourceRepository $repo = null |
60 | - ){ |
|
61 | - parent::__construct( $component ); |
|
60 | + ) { |
|
61 | + parent::__construct($component); |
|
62 | 62 | $this->templatePath = $templatePath; |
63 | 63 | $this->templateString = $templateString; |
64 | 64 | // Optional Puli repo |
65 | 65 | $this->repo = $repo; |
66 | 66 | |
67 | - $this->initTwig( $this->getLoader() ); |
|
67 | + $this->initTwig($this->getLoader()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | * @param array $props |
73 | 73 | * @return Response |
74 | 74 | */ |
75 | - protected function doRender( ViewState $state, array $props = [] ): Response |
|
75 | + protected function doRender(ViewState $state, array $props = [ ]): Response |
|
76 | 76 | { |
77 | 77 | // If puli plugin is available then add it. |
78 | - if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
|
79 | - $this->twig->addExtension( new PuliExtension( $this->repo ) ); |
|
78 | + if (class_exists("Puli\\TwigExtension\\PuliExtension") && null !== $this->repo) { |
|
79 | + $this->twig->addExtension(new PuliExtension($this->repo)); |
|
80 | 80 | } |
81 | - if( $this->templateString ){ |
|
81 | + if ($this->templateString) { |
|
82 | 82 | $template = $this->twig->createTemplate($this->templateString); |
83 | 83 | } |
84 | 84 | |
85 | 85 | $rendered = $this->twig->render( |
86 | - $template??$this->templatePath, |
|
86 | + $template ?? $this->templatePath, |
|
87 | 87 | [ |
88 | 88 | 'state' => $state, |
89 | 89 | 'props' => $props, |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | 'parent' => $this->component->getParent(), |
92 | 92 | 'exec' => $this->component->exec |
93 | 93 | ] ); |
94 | - return new Response( "text/html", $rendered ); |
|
94 | + return new Response("text/html", $rendered); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return Twig_LoaderInterface |
99 | 99 | */ |
100 | - protected function getLoader(): ChainLoader|ArrayLoader|LoaderInterface |
|
100 | + protected function getLoader(): ChainLoader | ArrayLoader | LoaderInterface |
|
101 | 101 | { |
102 | 102 | |
103 | - if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
|
104 | - $loader = new ChainLoader( [ new PuliTemplateLoader( $this->repo ), new Twig_Loader_String() ] ); |
|
103 | + if (class_exists("Puli\\TwigExtension\\PuliExtension") && null !== $this->repo) { |
|
104 | + $loader = new ChainLoader([ new PuliTemplateLoader($this->repo), new Twig_Loader_String() ]); |
|
105 | 105 | }else { |
106 | 106 | $loader = new ArrayLoader(); |
107 | 107 | } |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * @param $loader |
113 | 113 | */ |
114 | - protected function initTwig( $loader ) |
|
114 | + protected function initTwig($loader) |
|
115 | 115 | { |
116 | 116 | $config = [ 'autoescape' => false ]; |
117 | - if (defined( "TWIG_CACHE_DIR" )) { |
|
117 | + if (defined("TWIG_CACHE_DIR")) { |
|
118 | 118 | $config[ 'cache' ] = TWIG_CACHE_DIR; |
119 | 119 | } |
120 | - $this->twig = new Environment( $loader, $config ); |
|
120 | + $this->twig = new Environment($loader, $config); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | } |
@@ -102,7 +102,7 @@ |
||
102 | 102 | |
103 | 103 | if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
104 | 104 | $loader = new ChainLoader( [ new PuliTemplateLoader( $this->repo ), new Twig_Loader_String() ] ); |
105 | - }else { |
|
105 | + } else { |
|
106 | 106 | $loader = new ArrayLoader(); |
107 | 107 | } |
108 | 108 | return $loader; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | AbstractViewComponent $parent = null, |
75 | 75 | ExecHelper $execHelper = null, |
76 | 76 | LoggerInterface $logger = null |
77 | - ){ |
|
77 | + ) { |
|
78 | 78 | // Null means we are root |
79 | 79 | $this->parent = $parent; |
80 | 80 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | if (null === $execHelper) { |
85 | 85 | $execHelper = new ExecHelper(); |
86 | 86 | } |
87 | - $this->setExec( $execHelper ); |
|
87 | + $this->setExec($execHelper); |
|
88 | 88 | |
89 | 89 | $this->handleDependencyInjection(); |
90 | 90 | |
91 | - $this->setLogger( $logger ); |
|
91 | + $this->setLogger($logger); |
|
92 | 92 | |
93 | 93 | // Set up the state container |
94 | 94 | $this->initState(); |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * @param string $level A constant from LogLevel |
100 | 100 | * @param array|atring $context |
101 | 101 | */ |
102 | - protected function log( string $message, string $level, array|string $context = [] ){ |
|
103 | - if( isset( $this->logger ) ){ |
|
104 | - $class = get_class( $this ); |
|
102 | + protected function log(string $message, string $level, array | string $context = [ ]) { |
|
103 | + if (isset($this->logger)) { |
|
104 | + $class = get_class($this); |
|
105 | 105 | $message = "[{$class}] {$message}"; |
106 | - if( ! is_array($context) ){ |
|
107 | - $context = [$context]; |
|
106 | + if (!is_array($context)) { |
|
107 | + $context = [ $context ]; |
|
108 | 108 | } |
109 | - $this->logger->log( $level, $message, $context ); |
|
109 | + $this->logger->log($level, $message, $context); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | { |
119 | 119 | $ser = serialize($this); |
120 | 120 | // We have to unserialise the serialised object here because it's stripped down to only the required properties by __sleep() |
121 | - $this->log( "Dehydrating", LogLevel::DEBUG, [unserialize($ser)] ); |
|
121 | + $this->log("Dehydrating", LogLevel::DEBUG, [ unserialize($ser) ]); |
|
122 | 122 | return $ser; |
123 | 123 | } |
124 | 124 | |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | * Use this to unserialise ViewComponents |
127 | 127 | * Note that we have implemented __sleep() so not all members are serialised. |
128 | 128 | */ |
129 | - public static function rehydrate( $serialised, ExecHelper $execHelper, LoggerInterface $logger = null ): AbstractViewComponent |
|
129 | + public static function rehydrate($serialised, ExecHelper $execHelper, LoggerInterface $logger = null): AbstractViewComponent |
|
130 | 130 | { |
131 | 131 | /** @var AbstractViewComponent $view */ |
132 | - $view = unserialize( $serialised ); |
|
133 | - if( null !== $logger ){ |
|
134 | - $logger->log( LogLevel::DEBUG, "Rehydrating", [$view] ); |
|
132 | + $view = unserialize($serialised); |
|
133 | + if (null !== $logger) { |
|
134 | + $logger->log(LogLevel::DEBUG, "Rehydrating", [ $view ]); |
|
135 | 135 | } |
136 | - $view->setExec( $execHelper ); |
|
136 | + $view->setExec($execHelper); |
|
137 | 137 | $view->handleDependencyInjection(); |
138 | - $view->setLogger( $logger ); |
|
138 | + $view->setLogger($logger); |
|
139 | 139 | return $view; |
140 | 140 | } |
141 | 141 | |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | * Implement JsonSerializable interface, for logging mainly |
157 | 157 | * @return mixed |
158 | 158 | */ |
159 | - #[Pure] public function jsonSerialize(): mixed |
|
159 | + #[Pure ] public function jsonSerialize(): mixed |
|
160 | 160 | { |
161 | - $ret = []; |
|
161 | + $ret = [ ]; |
|
162 | 162 | // Return the same fields as __sleep() specifies for serialize() |
163 | - foreach ( $this->__sleep() as $member ){ |
|
163 | + foreach ($this->__sleep() as $member) { |
|
164 | 164 | // Skip parent because recursion isn't supported |
165 | - if( $member == 'parent'){ |
|
165 | + if ($member == 'parent') { |
|
166 | 166 | continue; |
167 | 167 | } |
168 | - $ret[$member] = $this->$member; |
|
168 | + $ret[ $member ] = $this->$member; |
|
169 | 169 | } |
170 | 170 | return $ret; |
171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @throws Exception |
178 | 178 | * @return Response |
179 | 179 | */ |
180 | - public function render( $execMethodName = null, array $execArgs = null ): Response |
|
180 | + public function render($execMethodName = null, array $execArgs = null): Response |
|
181 | 181 | { |
182 | 182 | $this->state->validate(); |
183 | 183 | |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | // If we're called with an 'exec' then run it instead of rendering the whole tree. |
193 | 193 | // It may still render the whole tree or it may just render a portion or just return JSON |
194 | 194 | if ($execMethodName) { // Used to test for null but it could easily be an empty string |
195 | - $this->log( "Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true ), LogLevel::DEBUG ); |
|
196 | - $out = $this->execMethod( $execMethodName, $execArgs ); |
|
195 | + $this->log("Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true), LogLevel::DEBUG); |
|
196 | + $out = $this->execMethod($execMethodName, $execArgs); |
|
197 | 197 | }else { |
198 | - $this->log( "Rendering without exec", LogLevel::DEBUG ); |
|
199 | - $out = $this->template->render( $this->state, $this->props ); |
|
200 | - if (!( $out instanceof Response )) { |
|
201 | - throw new Exception( get_class( $this->template ) . " returned invalid response. Should have been an instance of PatternSeek\ComponentView\Response" ); |
|
198 | + $this->log("Rendering without exec", LogLevel::DEBUG); |
|
199 | + $out = $this->template->render($this->state, $this->props); |
|
200 | + if (!($out instanceof Response)) { |
|
201 | + throw new Exception(get_class($this->template)." returned invalid response. Should have been an instance of PatternSeek\ComponentView\Response"); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | return $out; |
@@ -212,34 +212,34 @@ discard block |
||
212 | 212 | * @throws Exception |
213 | 213 | * @return Response |
214 | 214 | */ |
215 | - protected function execMethod( $methodName, array $args = null ): Response |
|
215 | + protected function execMethod($methodName, array $args = null): Response |
|
216 | 216 | { |
217 | - if (!is_array( $methodName )) { |
|
218 | - $methodName = explode( '.', $methodName ); |
|
217 | + if (!is_array($methodName)) { |
|
218 | + $methodName = explode('.', $methodName); |
|
219 | 219 | } |
220 | - if (count( $methodName ) == 1) { |
|
221 | - $methodName = $methodName[ 0 ] . 'Handler'; |
|
222 | - $out = $this->$methodName( $args ); |
|
220 | + if (count($methodName) == 1) { |
|
221 | + $methodName = $methodName[ 0 ].'Handler'; |
|
222 | + $out = $this->$methodName($args); |
|
223 | 223 | }else { |
224 | - $childName = array_shift( $methodName ); |
|
224 | + $childName = array_shift($methodName); |
|
225 | 225 | $child = $this->childComponents[ $childName ]; |
226 | 226 | if ($child instanceof AbstractViewComponent) { |
227 | - $out = $child->execMethod( $methodName, $args ); |
|
227 | + $out = $child->execMethod($methodName, $args); |
|
228 | 228 | }else { |
229 | - throw new Exception( implode( ".", $methodName ) . " is not a valid method." ); |
|
229 | + throw new Exception(implode(".", $methodName)." is not a valid method."); |
|
230 | 230 | } |
231 | 231 | } |
232 | - if (!( $out instanceof Response )) { |
|
233 | - $nameStr = is_array( $methodName )?implode( ".", $methodName ):$methodName; |
|
234 | - throw new Exception( $nameStr . " returned invalid response. Should have been an instance of PatternSeek\ComponentView\Response" ); |
|
232 | + if (!($out instanceof Response)) { |
|
233 | + $nameStr = is_array($methodName) ?implode(".", $methodName) : $methodName; |
|
234 | + throw new Exception($nameStr." returned invalid response. Should have been an instance of PatternSeek\ComponentView\Response"); |
|
235 | 235 | } |
236 | 236 | return $out; |
237 | 237 | } |
238 | 238 | |
239 | - public function getExecPath( $execMethod ): string |
|
239 | + public function getExecPath($execMethod): string |
|
240 | 240 | { |
241 | 241 | $path = $this->getPath(); |
242 | - return ( $path === null?$execMethod:$path . '.' . $execMethod ); |
|
242 | + return ($path === null ? $execMethod : $path.'.'.$execMethod); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | public function getParent(): ?AbstractViewComponent |
@@ -248,12 +248,12 @@ discard block |
||
248 | 248 | } |
249 | 249 | |
250 | 250 | |
251 | - protected function setFlashMessage( $string ) |
|
251 | + protected function setFlashMessage($string) |
|
252 | 252 | { |
253 | 253 | $this->flashMessage = $string; |
254 | 254 | } |
255 | 255 | |
256 | - protected function setFlashError( string $string ) |
|
256 | + protected function setFlashError(string $string) |
|
257 | 257 | { |
258 | 258 | $this->flashError = $string; |
259 | 259 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | } |
298 | 298 | $pPath = $this->parent->getPath(); |
299 | 299 | if (null !== $pPath) { |
300 | - return $pPath . '.' . $this->handle; |
|
300 | + return $pPath.'.'.$this->handle; |
|
301 | 301 | }else { |
302 | 302 | return $this->handle; |
303 | 303 | } |
@@ -311,20 +311,20 @@ discard block |
||
311 | 311 | * @param array $props |
312 | 312 | * @throws Exception |
313 | 313 | */ |
314 | - protected function addOrUpdateChild( $handle, $type, array $props = [ ] ) |
|
314 | + protected function addOrUpdateChild($handle, $type, array $props = [ ]) |
|
315 | 315 | { |
316 | - $this->log( "Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG ); |
|
317 | - if (!isset( $this->childComponents[ $handle ] )) { |
|
318 | - if( ! class_exists( $type ) ){ |
|
319 | - throw new Exception( "Class '{$type}' for sub-component does not exist." ); |
|
316 | + $this->log("Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG); |
|
317 | + if (!isset($this->childComponents[ $handle ])) { |
|
318 | + if (!class_exists($type)) { |
|
319 | + throw new Exception("Class '{$type}' for sub-component does not exist."); |
|
320 | 320 | } |
321 | - $child = new $type( $handle, $this, $this->exec, $this->logger ); |
|
321 | + $child = new $type($handle, $this, $this->exec, $this->logger); |
|
322 | 322 | $this->childComponents[ $handle ] = $child; |
323 | 323 | }else { |
324 | 324 | // exec, di and logger are set recursively in rehydrate() |
325 | 325 | $child = $this->childComponents[ $handle ]; |
326 | 326 | } |
327 | - $child->updateProps( $props ); |
|
327 | + $child->updateProps($props); |
|
328 | 328 | $child->updateState(); |
329 | 329 | } |
330 | 330 | |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | * @return string |
336 | 336 | * @throws Exception |
337 | 337 | */ |
338 | - public function renderChild( $handle ): string |
|
338 | + public function renderChild($handle): string |
|
339 | 339 | { |
340 | 340 | if (!$this->childComponents[ $handle ]) { |
341 | 341 | $message = "Attempted to render nonexistent child component with handle '{$handle}'"; |
342 | - $this->log( $message, LogLevel::CRITICAL ); |
|
343 | - throw new Exception( $message ); |
|
342 | + $this->log($message, LogLevel::CRITICAL); |
|
343 | + throw new Exception($message); |
|
344 | 344 | } |
345 | 345 | return $this->childComponents[ $handle ]->render()->content; |
346 | 346 | } |
@@ -388,58 +388,58 @@ discard block |
||
388 | 388 | * @param array $inputs |
389 | 389 | * @throws Exception |
390 | 390 | */ |
391 | - protected function testInputs( array $inputSpec, array &$inputs ) |
|
391 | + protected function testInputs(array $inputSpec, array &$inputs) |
|
392 | 392 | { |
393 | 393 | |
394 | 394 | foreach ($inputSpec as $fieldName => $fieldSpec) { |
395 | 395 | // Required field |
396 | - if (( count( $fieldSpec ) < 2 )) { |
|
397 | - if (!isset( $inputs[ $fieldName ] )) { |
|
398 | - $calledFunc = debug_backtrace()[1]['function']; |
|
399 | - $callerFunc = debug_backtrace()[2]['function']; |
|
400 | - $callerClass = debug_backtrace()[2]['class']; |
|
396 | + if ((count($fieldSpec) < 2)) { |
|
397 | + if (!isset($inputs[ $fieldName ])) { |
|
398 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
399 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
400 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
401 | 401 | $parentText = ''; |
402 | - if( $this->parent !== null ){ |
|
402 | + if ($this->parent !== null) { |
|
403 | 403 | $parentText = " (parent component is ".get_class($this->parent).")"; |
404 | 404 | } |
405 | - throw new Exception( $fieldName . " is a required field for " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
405 | + throw new Exception($fieldName." is a required field for ".get_class($this)."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | // Set default is unset |
409 | - if (!isset( $inputs[ $fieldName ] )) { |
|
409 | + if (!isset($inputs[ $fieldName ])) { |
|
410 | 410 | $inputs[ $fieldName ] = $fieldSpec[ 1 ]; |
411 | 411 | } |
412 | 412 | // Check type |
413 | 413 | // Any type allowed, continue |
414 | - if (!isset( $fieldSpec[ 0 ] ) || $fieldSpec[ 0 ] === null) { |
|
414 | + if (!isset($fieldSpec[ 0 ]) || $fieldSpec[ 0 ] === null) { |
|
415 | 415 | continue; |
416 | 416 | } |
417 | 417 | $requiredType = $fieldSpec[ 0 ]; |
418 | 418 | $input = $inputs[ $fieldName ]; |
419 | 419 | // Specific type required |
420 | 420 | // Null is allowed |
421 | - if (!is_null( $input )) { |
|
422 | - $failed = match ( $requiredType ) { |
|
423 | - "string" => !is_string( $input ), |
|
424 | - "array" => !is_array( $input ), |
|
425 | - "object" => !is_object( $input ), |
|
426 | - "resource" => !is_resource( $input ), |
|
427 | - "callable" => !is_callable( $input ), |
|
428 | - "boolean", "bool" => !is_bool( $input ), |
|
429 | - "integer", "int" => !is_int( $input ), |
|
430 | - "double" => !is_double( $input ), |
|
431 | - "float" => !is_float( $input ), |
|
432 | - default => !( $input instanceof $requiredType ), |
|
421 | + if (!is_null($input)) { |
|
422 | + $failed = match ($requiredType) { |
|
423 | + "string" => !is_string($input), |
|
424 | + "array" => !is_array($input), |
|
425 | + "object" => !is_object($input), |
|
426 | + "resource" => !is_resource($input), |
|
427 | + "callable" => !is_callable($input), |
|
428 | + "boolean", "bool" => !is_bool($input), |
|
429 | + "integer", "int" => !is_int($input), |
|
430 | + "double" => !is_double($input), |
|
431 | + "float" => !is_float($input), |
|
432 | + default => !($input instanceof $requiredType), |
|
433 | 433 | }; |
434 | 434 | if ($failed) { |
435 | - $calledFunc = debug_backtrace()[1]['function']; |
|
436 | - $callerFunc = debug_backtrace()[2]['function']; |
|
437 | - $callerClass = debug_backtrace()[2]['class']; |
|
435 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
436 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
437 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
438 | 438 | $parentText = ''; |
439 | - if( $this->parent !== null ){ |
|
439 | + if ($this->parent !== null) { |
|
440 | 440 | $parentText = " (parent component is ".get_class($this->parent).")"; |
441 | 441 | } |
442 | - throw new Exception( $fieldName . " should be of type " . $requiredType . "in " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
442 | + throw new Exception($fieldName." should be of type ".$requiredType."in ".get_class($this)."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | /** |
449 | 449 | * Update the full component view tree. |
450 | 450 | */ |
451 | - public function updateView( array $props ) |
|
451 | + public function updateView(array $props) |
|
452 | 452 | { |
453 | - $this->updateProps( $props ); |
|
453 | + $this->updateProps($props); |
|
454 | 454 | $this->updateState(); |
455 | 455 | } |
456 | 456 | |
@@ -459,13 +459,13 @@ discard block |
||
459 | 459 | * |
460 | 460 | * @var array $props |
461 | 461 | */ |
462 | - protected function updateProps( array $props ) |
|
462 | + protected function updateProps(array $props) |
|
463 | 463 | { |
464 | - $this->log( "Storing new props: ", LogLevel::DEBUG, var_export( $props, true ) ); |
|
464 | + $this->log("Storing new props: ", LogLevel::DEBUG, var_export($props, true)); |
|
465 | 465 | $this->props = $props; |
466 | 466 | } |
467 | 467 | |
468 | - protected function forceResponse( Response $response ) |
|
468 | + protected function forceResponse(Response $response) |
|
469 | 469 | { |
470 | 470 | $this->forceResponse = $response; |
471 | 471 | } |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | /** |
474 | 474 | * @param ExecHelper $execHelper |
475 | 475 | */ |
476 | - private function setExec( ExecHelper $execHelper ) |
|
476 | + private function setExec(ExecHelper $execHelper) |
|
477 | 477 | { |
478 | 478 | $this->exec = clone $execHelper; |
479 | - $this->exec->setComponent( $this ); |
|
480 | - foreach( $this->childComponents as $child ){ |
|
481 | - $child->setExec( $execHelper ); |
|
479 | + $this->exec->setComponent($this); |
|
480 | + foreach ($this->childComponents as $child) { |
|
481 | + $child->setExec($execHelper); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
@@ -492,9 +492,9 @@ discard block |
||
492 | 492 | // it manually and you still get the advantage that the deps |
493 | 493 | // are specified in the optional injectDependencies() method's |
494 | 494 | // signature |
495 | - $this->log( "Dependency injection...", LogLevel::DEBUG ); |
|
496 | - DependencyInjector::instance()->injectIntoMethod( $this ); |
|
497 | - foreach( $this->childComponents as $child ){ |
|
495 | + $this->log("Dependency injection...", LogLevel::DEBUG); |
|
496 | + DependencyInjector::instance()->injectIntoMethod($this); |
|
497 | + foreach ($this->childComponents as $child) { |
|
498 | 498 | $child->handleDependencyInjection(); |
499 | 499 | } |
500 | 500 | } |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | /** |
503 | 503 | * @param LoggerInterface $logger |
504 | 504 | */ |
505 | - private function setLogger( LoggerInterface $logger = null ) |
|
505 | + private function setLogger(LoggerInterface $logger = null) |
|
506 | 506 | { |
507 | - if( null !== $logger ){ |
|
507 | + if (null !== $logger) { |
|
508 | 508 | $this->logger = $logger; |
509 | 509 | /** @var AbstractViewComponent $child */ |
510 | - foreach( $this->childComponents as $child ){ |
|
511 | - $child->setLogger( $logger ); |
|
510 | + foreach ($this->childComponents as $child) { |
|
511 | + $child->setLogger($logger); |
|
512 | 512 | } |
513 | 513 | } |
514 | 514 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | if ($execMethodName) { // Used to test for null but it could easily be an empty string |
195 | 195 | $this->log( "Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true ), LogLevel::DEBUG ); |
196 | 196 | $out = $this->execMethod( $execMethodName, $execArgs ); |
197 | - }else { |
|
197 | + } else { |
|
198 | 198 | $this->log( "Rendering without exec", LogLevel::DEBUG ); |
199 | 199 | $out = $this->template->render( $this->state, $this->props ); |
200 | 200 | if (!( $out instanceof Response )) { |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | if (count( $methodName ) == 1) { |
221 | 221 | $methodName = $methodName[ 0 ] . 'Handler'; |
222 | 222 | $out = $this->$methodName( $args ); |
223 | - }else { |
|
223 | + } else { |
|
224 | 224 | $childName = array_shift( $methodName ); |
225 | 225 | $child = $this->childComponents[ $childName ]; |
226 | 226 | if ($child instanceof AbstractViewComponent) { |
227 | 227 | $out = $child->execMethod( $methodName, $args ); |
228 | - }else { |
|
228 | + } else { |
|
229 | 229 | throw new Exception( implode( ".", $methodName ) . " is not a valid method." ); |
230 | 230 | } |
231 | 231 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $pPath = $this->parent->getPath(); |
299 | 299 | if (null !== $pPath) { |
300 | 300 | return $pPath . '.' . $this->handle; |
301 | - }else { |
|
301 | + } else { |
|
302 | 302 | return $this->handle; |
303 | 303 | } |
304 | 304 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | $child = new $type( $handle, $this, $this->exec, $this->logger ); |
322 | 322 | $this->childComponents[ $handle ] = $child; |
323 | - }else { |
|
323 | + } else { |
|
324 | 324 | // exec, di and logger are set recursively in rehydrate() |
325 | 325 | $child = $this->childComponents[ $handle ]; |
326 | 326 | } |