@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function __construct(Container $cacheContainer) |
34 | 34 | { |
35 | 35 | $this->cacheContainer = $cacheContainer; |
36 | - $this->cachePrefix = $this->cacheContainer->cachePrefix . '.' . $this->cacheContainer->classPrefix . '.'; |
|
36 | + $this->cachePrefix = $this->cacheContainer->cachePrefix.'.'.$this->cacheContainer->classPrefix.'.'; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | if (!$this->isAvailableCacheLibrary()) { |
45 | 45 | return false; |
46 | 46 | } |
47 | - $key = $this->cachePrefix . $key; |
|
47 | + $key = $this->cachePrefix.$key; |
|
48 | 48 | $writer = null; |
49 | 49 | $isAppend = !$overwrite; |
50 | 50 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | ]); |
56 | 56 | |
57 | 57 | try { |
58 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
58 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
59 | 59 | $writer = $this->cacheContainer->ioContainer->fileWriter->getWriter($file, $isAppend); |
60 | 60 | $writer->write($value); |
61 | - $this->logger->info("Execute cache save: " . $key); |
|
61 | + $this->logger->info("Execute cache save: ".$key); |
|
62 | 62 | return true; |
63 | 63 | } catch (IOException $e) { |
64 | 64 | $this->logger->warn($e->getMessage()); |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | if (!$this->isAvailableCacheLibrary()) { |
83 | 83 | return null; |
84 | 84 | } |
85 | - $key = $this->cachePrefix . $key; |
|
85 | + $key = $this->cachePrefix.$key; |
|
86 | 86 | $value = null; |
87 | 87 | $reader = null; |
88 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
88 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
89 | 89 | |
90 | 90 | if ($file->isReadable()) { |
91 | 91 | try { |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | $data = $this->decode($reader->read()); |
94 | 94 | if ($data['ttl'] > 0) { |
95 | 95 | if (time() > $data['time'] + $data['ttl']) { |
96 | - $this->logger->info("Expired cache: " . $key); |
|
96 | + $this->logger->info("Expired cache: ".$key); |
|
97 | 97 | $file->delete(); |
98 | 98 | } |
99 | 99 | } else { |
100 | 100 | $value = $data['data']; |
101 | - $this->logger->info("Execute cache read: " . $key); |
|
101 | + $this->logger->info("Execute cache read: ".$key); |
|
102 | 102 | } |
103 | 103 | } catch (IOException $e) { |
104 | 104 | $this->logger->warn($e->getMessage()); |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | if (!$this->isAvailableCacheLibrary()) { |
125 | 125 | return false; |
126 | 126 | } |
127 | - $key = $this->cachePrefix . $key; |
|
127 | + $key = $this->cachePrefix.$key; |
|
128 | 128 | $result = false; |
129 | 129 | |
130 | - $file = new File($this->cacheContainer->cacheDir . '/' . $key . '.cache'); |
|
130 | + $file = new File($this->cacheContainer->cacheDir.'/'.$key.'.cache'); |
|
131 | 131 | if ($file->isWritable()) { |
132 | 132 | $result = $file->delete(); |
133 | - $this->logger->info("Execute cache cleared: " . $key); |
|
133 | + $this->logger->info("Execute cache cleared: ".$key); |
|
134 | 134 | } else { |
135 | - $this->logger->warn("Failed to clear cache: " . $key); |
|
135 | + $this->logger->warn("Failed to clear cache: ".$key); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return $result; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | $file = new File($filepath); |
158 | 158 | if ($file->isWritable()) { |
159 | 159 | if ($file->delete()) { |
160 | - $this->logger->info("Execute cache cleared: " . $this->cachePrefix . "*"); |
|
160 | + $this->logger->info("Execute cache cleared: ".$this->cachePrefix."*"); |
|
161 | 161 | } else { |
162 | - $this->logger->warn("Failed to clear cache: " . $this->cachePrefix . "*"); |
|
162 | + $this->logger->warn("Failed to clear cache: ".$this->cachePrefix."*"); |
|
163 | 163 | $result = false; |
164 | 164 | } |
165 | 165 | } else { |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | } else { |
175 | - $this->logger->warn("Can't read directory:" . $dir->getFilePath()); |
|
175 | + $this->logger->warn("Can't read directory:".$dir->getFilePath()); |
|
176 | 176 | $result = false; |
177 | 177 | } |
178 | 178 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function __construct(Container $container) |
59 | 59 | { |
60 | 60 | $this->container = $container; |
61 | - $this->session = $container->session; |
|
61 | + $this->session = $container->session; |
|
62 | 62 | $this->timestamp = 0; |
63 | 63 | $this->logger = $container->logger; |
64 | 64 | } |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | $params = ["model" => $params["model"], "helper" => $params["helper"]]; |
73 | 73 | $dirname = $this->camel2snake($this->container->router->pageName); |
74 | 74 | |
75 | - $templateFile = new File($this->container->applicationInfo->applicationRoot . "/app/views/" . $dirname . "/" . $this->container->filename); |
|
76 | - $sharedFile = new File($this->container->applicationInfo->applicationRoot . "/app/views/" . $this->container->applicationInfo->sharedDir . "/" . $this->container->filename); |
|
75 | + $templateFile = new File($this->container->applicationInfo->applicationRoot."/app/views/".$dirname."/".$this->container->filename); |
|
76 | + $sharedFile = new File($this->container->applicationInfo->applicationRoot."/app/views/".$this->container->applicationInfo->sharedDir."/".$this->container->filename); |
|
77 | 77 | |
78 | 78 | $file = $templateFile->exists() ? $templateFile : ($sharedFile->exists() ? $sharedFile : null); |
79 | 79 | if ($file === null) { |
80 | - $errorMessage = "Invalid template file path: " . $templateFile->getFilePath() . " or " . $sharedFile->getFilePath(); |
|
80 | + $errorMessage = "Invalid template file path: ".$templateFile->getFilePath()." or ".$sharedFile->getFilePath(); |
|
81 | 81 | throw new ResourceNotFoundException($errorMessage); |
82 | 82 | } |
83 | 83 | |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | $this->replaceTemplateMark($content, $mimeType); |
94 | 94 | |
95 | 95 | // テンプレートファイルをコンパイルし一時ファイルを作成 |
96 | - $tmpFile = new File($this->getTemporaryDirectory() . "/" . $this->getRandomstring(30)); |
|
96 | + $tmpFile = new File($this->getTemporaryDirectory()."/".$this->getRandomstring(30)); |
|
97 | 97 | $writer = new FileWriter($tmpFile); |
98 | 98 | $writer->write($content); |
99 | 99 | $writer->close(); |
100 | - $this->logger->debug("Write temporary template file: " . $tmpFile->getFilePath()); |
|
101 | - $this->logger->debug("Compiled template file size: " . $tmpFile->size()); |
|
100 | + $this->logger->debug("Write temporary template file: ".$tmpFile->getFilePath()); |
|
101 | + $this->logger->debug("Compiled template file size: ".$tmpFile->size()); |
|
102 | 102 | |
103 | 103 | $params["__params__"] = $params; |
104 | 104 | $params["__mimeType__"] = $mimeType; |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | // CSRFチェックが実行される前に非同期でリクエストがあった場合を考慮して |
129 | 129 | // CSRFトークンは削除しない |
130 | 130 | if (preg_match('/<form.*?>.*?<\/form>/is', $content)) { |
131 | - $csrfToken = sha1($this->session->id() . microtime()); |
|
131 | + $csrfToken = sha1($this->session->id().microtime()); |
|
132 | 132 | $this->session->set($this->getCsrfTokenKey(), $csrfToken); |
133 | 133 | $this->addToken($content, $csrfToken); |
134 | 134 | } |
135 | 135 | |
136 | 136 | // テンプレートファイルをコンパイルし一時ファイルを作成 |
137 | - $tmpFile = new File($this->getTemporaryDirectory() . "/" . $this->getRandomstring(30)); |
|
137 | + $tmpFile = new File($this->getTemporaryDirectory()."/".$this->getRandomstring(30)); |
|
138 | 138 | $writer = new FileWriter($tmpFile); |
139 | 139 | $writer->write($content); |
140 | 140 | $writer->close(); |
141 | - $this->logger->debug("Write temporary template file: " . $tmpFile->getFilePath()); |
|
142 | - $this->logger->debug("Compiled template file size: " . $tmpFile->size()); |
|
141 | + $this->logger->debug("Write temporary template file: ".$tmpFile->getFilePath()); |
|
142 | + $this->logger->debug("Compiled template file size: ".$tmpFile->size()); |
|
143 | 143 | |
144 | 144 | $params["__params__"] = $params; |
145 | 145 | $params["__mimeType__"] = $mimeType; |
@@ -179,20 +179,20 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function cache($filename, $data, $expire) |
181 | 181 | { |
182 | - $cacheDir = $this->container->applicationInfo->applicationRoot . "/app/views/" . $this->container->applicationInfo->cacheDir; |
|
182 | + $cacheDir = $this->container->applicationInfo->applicationRoot."/app/views/".$this->container->applicationInfo->cacheDir; |
|
183 | 183 | $factory = new CacheDriverFactory(); |
184 | 184 | $config = new Container(false); |
185 | 185 | $config->cacheDir = $cacheDir; |
186 | 186 | $config->classPrefix = "view_cache"; |
187 | 187 | $cache = $factory->create("WebStream\Cache\Driver\TemporaryFile", $config); |
188 | 188 | $cache->inject('logger', $this->logger); |
189 | - var_dump($cacheDir . "/" . $filename . ".cache"); |
|
190 | - $file = new File($cacheDir . "/" . $filename . ".cache"); |
|
189 | + var_dump($cacheDir."/".$filename.".cache"); |
|
190 | + $file = new File($cacheDir."/".$filename.".cache"); |
|
191 | 191 | if (!$file->exists() || $this->timestamp > $file->lastModified()) { |
192 | 192 | if ($cache->add($filename, $data, $expire)) { |
193 | - $this->logger->debug("Write template cache file: " . $file->getFilePath()); |
|
193 | + $this->logger->debug("Write template cache file: ".$file->getFilePath()); |
|
194 | 194 | } else { |
195 | - throw new IOException("File write failure: " . $file->getFilePath()); |
|
195 | + throw new IOException("File write failure: ".$file->getFilePath()); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -219,29 +219,29 @@ discard block |
||
219 | 219 | { |
220 | 220 | $originContentHash = md5($content); |
221 | 221 | |
222 | - $content = preg_replace_callback('/(%.{\$' . $this->getHelperVariableName() . '\->async\(.+?\)})/', function ($matches) { |
|
222 | + $content = preg_replace_callback('/(%.{\$'.$this->getHelperVariableName().'\->async\(.+?\)})/', function($matches) { |
|
223 | 223 | $asyncId = $this->getAsyncDomId(); |
224 | - $context = preg_replace_callback('/\$' . $this->getHelperVariableName() . '->async\((.+?)\)/', function ($matches2) use ($asyncId) { |
|
225 | - return '$' . $this->getHelperVariableName() . '->async(' . $matches2[1] . ',\'' . $asyncId . '\')'; |
|
224 | + $context = preg_replace_callback('/\$'.$this->getHelperVariableName().'->async\((.+?)\)/', function($matches2) use ($asyncId) { |
|
225 | + return '$'.$this->getHelperVariableName().'->async('.$matches2[1].',\''.$asyncId.'\')'; |
|
226 | 226 | }, $matches[1]); |
227 | 227 | |
228 | 228 | return "<div id='$asyncId'>$context</div>"; |
229 | 229 | }, $content); |
230 | 230 | |
231 | - $content = preg_replace('/' . self::TEMPLATE_MARK_PHP . '\{(.*?)\}/', '<?php echo $1; ?>', $content); |
|
232 | - $content = preg_replace_callback('/' . self::TEMPLATE_MARK_TEMPLATE . '\{(.*?)\}/', function ($matches) { |
|
231 | + $content = preg_replace('/'.self::TEMPLATE_MARK_PHP.'\{(.*?)\}/', '<?php echo $1; ?>', $content); |
|
232 | + $content = preg_replace_callback('/'.self::TEMPLATE_MARK_TEMPLATE.'\{(.*?)\}/', function($matches) { |
|
233 | 233 | if (substr($matches[1], 0, 1) === '$') { |
234 | - return self::TEMPLATE_MARK_TEMPLATE . '{<?php echo ' . $matches[1] . ';?>}'; |
|
234 | + return self::TEMPLATE_MARK_TEMPLATE.'{<?php echo '.$matches[1].';?>}'; |
|
235 | 235 | } else { |
236 | - return '<?php $this->draw(\'' . $matches[1] . '\', $__params__, $__mimeType__); ?>'; |
|
236 | + return '<?php $this->draw(\''.$matches[1].'\', $__params__, $__mimeType__); ?>'; |
|
237 | 237 | } |
238 | 238 | }, $content); |
239 | 239 | |
240 | 240 | if ($mimeType === "xml") { |
241 | - $content = preg_replace('/' . self::TEMPLATE_MARK_XML . '\{(.*?)\}/', '<?php echo safetyOutXML($1); ?>', $content); |
|
241 | + $content = preg_replace('/'.self::TEMPLATE_MARK_XML.'\{(.*?)\}/', '<?php echo safetyOutXML($1); ?>', $content); |
|
242 | 242 | } elseif ($mimeType === "html") { |
243 | - $content = preg_replace('/' . self::TEMPLATE_MARK_HTML . '\{(.*?)\}/', '<?php echo safetyOut($1); ?>', $content); |
|
244 | - $content = preg_replace('/' . self::TEMPLATE_MARK_JAVASCRIPT . '\{(.*?)\}/', '<?php echo safetyOutJavaScript($1); ?>', $content); |
|
243 | + $content = preg_replace('/'.self::TEMPLATE_MARK_HTML.'\{(.*?)\}/', '<?php echo safetyOut($1); ?>', $content); |
|
244 | + $content = preg_replace('/'.self::TEMPLATE_MARK_JAVASCRIPT.'\{(.*?)\}/', '<?php echo safetyOutJavaScript($1); ?>', $content); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | $replacedContentHash = md5($content); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | |
182 | 182 | // テンプレートキャッシュチェック |
183 | 183 | $pageName = $this->container->coreDelegator->getPageName(); |
184 | - $cacheFile = $applicationInfo->cachePrefix . $this->camel2snake($pageName) . "-" . $this->camel2snake($method); |
|
184 | + $cacheFile = $applicationInfo->cachePrefix.$this->camel2snake($pageName)."-".$this->camel2snake($method); |
|
185 | 185 | |
186 | 186 | $factory = new CacheDriverFactory(); |
187 | 187 | $config = new Container(false); |
188 | - $config->cacheDir = $applicationInfo->applicationRoot . "/app/views/" . $applicationInfo->cacheDir; |
|
188 | + $config->cacheDir = $applicationInfo->applicationRoot."/app/views/".$applicationInfo->cacheDir; |
|
189 | 189 | $config->classPrefix = "view_cache"; |
190 | 190 | $cache = $factory->create("WebStream\Cache\Driver\TemporaryFile", $config); |
191 | 191 | $cache->inject('logger', $this->logger); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | ]); |
255 | 255 | |
256 | 256 | if ($template->cacheTime !== null) { |
257 | - $cacheFile = $applicationInfo->cachePrefix . $this->camel2snake($pageName) . "-" . $this->camel2snake($method); |
|
257 | + $cacheFile = $applicationInfo->cachePrefix.$this->camel2snake($pageName)."-".$this->camel2snake($method); |
|
258 | 258 | $view->templateCache($cacheFile, ob_get_contents(), $template->cacheTime); |
259 | 259 | } |
260 | 260 |