Exemple #1
0
 public function resolve(Request $request, Response $response)
 {
     $pathInfo = $request->uri('path');
     // Inex 1 because request URI starts with a slash
     if (strpos($pathInfo, $this->dstPath) !== 1) {
         return;
     } else {
         $pathInfo = substr($pathInfo, strlen($this->dstPath) + 1);
     }
     $pathInfo = pathinfo($pathInfo);
     // Only serves .css requests
     if ($pathInfo['extension'] != 'css') {
         return;
     }
     // also takes care of .min requests
     $pathInfo['filename'] = preg_replace('/\\.min$/', '', $pathInfo['filename']);
     $_srcPath = "/{$pathInfo['dirname']}/{$pathInfo['filename']}.scss";
     $dstPath = "./{$this->dstPath}/{$pathInfo['dirname']}/{$pathInfo['filename']}.css";
     foreach ($this->srcPath as $srcPath) {
         $srcPath = "./{$srcPath}{$_srcPath}";
         // compile when: target file not exists, or source is newer
         if (!file_exists($dstPath) || @filemtime($srcPath) > @filemtime($dstPath)) {
             $result = @trim((new Compiler())->compile(file_get_contents($srcPath)));
             // note; write empty file if target exists
             if ($result || file_exists($dstPath)) {
                 if (!@file_put_contents($dstPath, $result)) {
                     Log::warn('Permission denied, unable to compile SCSS.');
                 }
             }
             break;
         }
     }
 }
Exemple #2
0
 public function resolve(Request $request, Response $response)
 {
     $pathInfo = $request->uri('path');
     // Inex 1 because request URI starts with a slash
     if (strpos($pathInfo, $this->dstPath) !== 1) {
         return;
     } else {
         $pathInfo = substr($pathInfo, strlen($this->dstPath) + 1);
     }
     $pathInfo = pathinfo($pathInfo);
     // Only serves .min.css requests
     if (!preg_match('/\\.min\\.css$/', $pathInfo['basename'])) {
         return;
     }
     $pathInfo['filename'] = preg_replace('/\\.min$/', '', $pathInfo['filename']);
     $_srcPath = "/{$pathInfo['dirname']}/{$pathInfo['filename']}.css";
     $dstPath = "./{$this->dstPath}/{$pathInfo['dirname']}/{$pathInfo['filename']}.min.css";
     foreach ($this->srcPath as $srcPath) {
         $srcPath = "./{$srcPath}{$_srcPath}";
         // compile when: target file not exists, or source is newer
         if (file_exists($srcPath) && (!file_exists($dstPath) || @filemtime($srcPath) > @filemtime($dstPath))) {
             // empty results are ignored
             $result = trim(@CssMin::minify(file_get_contents($srcPath)));
             if ($result && !@file_put_contents($dstPath, $result)) {
                 Log::warn('Permission denied, unable to minify CSS.');
             }
             break;
         }
     }
 }