Completed
Push — feature/0.7.0 ( 044eb8...362342 )
by Ryuichi
03:34
created
WebStream/Template/Basic.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,15 +179,15 @@  discard block
 block discarded – undo
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
         $cache = new Cache($cacheDir);
184 184
         $cache->inject('logger', $this->logger);
185
-        $file = new File($cacheDir . "/" . $filename . ".cache");
185
+        $file = new File($cacheDir."/".$filename.".cache");
186 186
         if (!$file->exists() || $this->timestamp > $file->lastModified()) {
187 187
             if ($cache->save($filename, $data, $expire)) {
188
-                $this->logger->debug("Write template cache file: " . $file->getFilePath());
188
+                $this->logger->debug("Write template cache file: ".$file->getFilePath());
189 189
             } else {
190
-                throw new IOException("File write failure: " . $file->getFilePath());
190
+                throw new IOException("File write failure: ".$file->getFilePath());
191 191
             }
192 192
         }
193 193
     }
@@ -214,29 +214,29 @@  discard block
 block discarded – undo
214 214
     {
215 215
         $originContentHash = md5($content);
216 216
 
217
-        $content = preg_replace_callback('/(%.{\$' . $this->getHelperVariableName() . '\->async\(.+?\)})/', function ($matches) {
217
+        $content = preg_replace_callback('/(%.{\$'.$this->getHelperVariableName().'\->async\(.+?\)})/', function($matches) {
218 218
             $asyncId = $this->getAsyncDomId();
219
-            $context = preg_replace_callback('/\$' . $this->getHelperVariableName() . '->async\((.+?)\)/', function ($matches2) use ($asyncId) {
220
-                return '$' . $this->getHelperVariableName() . '->async(' . $matches2[1] . ',\'' . $asyncId . '\')';
219
+            $context = preg_replace_callback('/\$'.$this->getHelperVariableName().'->async\((.+?)\)/', function($matches2) use ($asyncId) {
220
+                return '$'.$this->getHelperVariableName().'->async('.$matches2[1].',\''.$asyncId.'\')';
221 221
             }, $matches[1]);
222 222
 
223 223
             return "<div id='$asyncId'>$context</div>";
224 224
         }, $content);
225 225
 
226
-        $content = preg_replace('/' . self::TEMPLATE_MARK_PHP . '\{(.*?)\}/', '<?php echo $1; ?>', $content);
227
-        $content = preg_replace_callback('/' . self::TEMPLATE_MARK_TEMPLATE . '\{(.*?)\}/', function ($matches) {
226
+        $content = preg_replace('/'.self::TEMPLATE_MARK_PHP.'\{(.*?)\}/', '<?php echo $1; ?>', $content);
227
+        $content = preg_replace_callback('/'.self::TEMPLATE_MARK_TEMPLATE.'\{(.*?)\}/', function($matches) {
228 228
             if (substr($matches[1], 0, 1) === '$') {
229
-                return self::TEMPLATE_MARK_TEMPLATE . '{<?php echo ' . $matches[1] . ';?>}';
229
+                return self::TEMPLATE_MARK_TEMPLATE.'{<?php echo '.$matches[1].';?>}';
230 230
             } else {
231
-                return '<?php $this->draw(\'' . $matches[1] . '\', $__params__, $__mimeType__); ?>';
231
+                return '<?php $this->draw(\''.$matches[1].'\', $__params__, $__mimeType__); ?>';
232 232
             }
233 233
         }, $content);
234 234
 
235 235
         if ($mimeType === "xml") {
236
-            $content = preg_replace('/' . self::TEMPLATE_MARK_XML . '\{(.*?)\}/', '<?php echo safetyOutXML($1); ?>', $content);
236
+            $content = preg_replace('/'.self::TEMPLATE_MARK_XML.'\{(.*?)\}/', '<?php echo safetyOutXML($1); ?>', $content);
237 237
         } elseif ($mimeType === "html") {
238
-            $content = preg_replace('/' . self::TEMPLATE_MARK_HTML . '\{(.*?)\}/', '<?php echo safetyOut($1); ?>', $content);
239
-            $content = preg_replace('/' . self::TEMPLATE_MARK_JAVASCRIPT . '\{(.*?)\}/', '<?php echo safetyOutJavaScript($1); ?>', $content);
238
+            $content = preg_replace('/'.self::TEMPLATE_MARK_HTML.'\{(.*?)\}/', '<?php echo safetyOut($1); ?>', $content);
239
+            $content = preg_replace('/'.self::TEMPLATE_MARK_JAVASCRIPT.'\{(.*?)\}/', '<?php echo safetyOutJavaScript($1); ?>', $content);
240 240
         }
241 241
 
242 242
         $replacedContentHash = md5($content);
Please login to merge, or discard this patch.