method getContent documentation in bbn\Cdn\Compiler

Returns the content of a file or a group of files,

after having compiled it if needed, and minified if test is false.

function($file, $test = false) { if (is_array($file)) { $ext = Str::fileExt($file[0]); $minified = false; $c = ''; foreach ($file as $f) { $has_content = false; if (!is_file($this->fpath . $f)) { throw new \Exception(X::_("Impossible to find the file") . ' ' . $this->fpath . $f); return false; } foreach (self::$_min_suffixes as $s) { if (strpos($f, $s . '.')) { $minified = true; if ($test && file_exists($this->fpath . str_replace($s . '.', '.', $f))) { $c .= PHP_EOL . file_get_contents($this->fpath . str_replace($s . '.', '.', $f)); $has_content = true; } break; } } if (!$has_content) { $c .= PHP_EOL . file_get_contents($this->fpath . $f); } if (!empty($c)) { $c = trim($c); } } $file = $file[0]; } else { $ext = Str::fileExt($file); $minified = false; if (!is_file($this->fpath . $file)) { throw new \Exception(X::_("Impossible to find the file") . ' ' . $this->fpath . $file); return false; } foreach (self::$_min_suffixes as $s) { if (strpos($file, $s . '.')) { $minified = true; if ($test && file_exists($this->fpath . str_replace($s . '.', '.', $file))) { $c = file_get_contents($this->fpath . str_replace($s . '.', '.', $file)); } break; } } if (!isset($c)) { $c = file_get_contents($this->fpath . $file); } if (\is_string($c)) { $c = trim($c); } } if ($c) { switch ($ext) { case 'js': if (!$test && !$minified) { $c = $this->minify($c, 'js'); } break; case 'css': if (!$test && !$minified) { $c = $this->minify($c, 'css'); } break; case 'less': $less = new Less(); $less->setImportDir([X::dirname($this->fpath . $file)]); try { $c = $less->compile($c); } catch (\Exception $e) { X::log("Error during LESS compilation with file $file :" . $e->getMessage(), 'cdn_err'); $this->setError("Error during LESS compilation with file $file :" . $e->getMessage()); throw $e; } if ($c && !$test) { try { $c = $this->minify($c, 'css'); } catch (\Exception $e) { $this->setError("Error during LESS compilation with file $file :" . $e->getMessage()); throw $e; } } break; case 'scss': try { $scss = new \ScssPhp\ScssPhp\Compiler(); $scss->setImportPaths([X::dirname($this->fpath . $file)]); if (is_file(X::dirname($this->fpath . $file) . '/_def.scss')) { $c = file_get_contents((X::dirname($this->fpath . $file) . '/_def.scss')) . $c; } $c = $scss->compile($c); if ($c && !$test) { $c = $this->minify($c, 'css'); } } catch (\Exception $e) { $this->setError("Error during SCSS compilation with file $file :" . $e->getMessage()); die($e->getMessage()); } break; case 'sass': $sass = new \SassParser( [ 'cache' => false, 'syntax' => 'sass' ] ); try { $c = $sass->toCss($c, false); if ($c && !$test) { $c = $this->minify($c, 'css'); } } catch (\Exception $e) { $this->setError("Error during SASS compilation with file $file :" . $e->getMessage()); die($e->getMessage()); } break; } if (!$this->check()) { die("File $file \n{$this->getError()}"); } return $c; } return false; }

Returns the content of a file or a group of files, BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.