예제 #1
0
파일: dom.php 프로젝트: boltphp/core
 public function __construct($html = false, $charset = 'UTF-8')
 {
     $this->_doc = new DOMDocument('1.0', $charset);
     $this->_doc->validateOnParse = true;
     $this->_doc->preserveWhiteSpace = false;
     $this->_doc->resolveExternals = false;
     $this->_doc->formatOutput = b::env() === 'dev';
     if ($html) {
         $this->_doc->loadHTML($html);
     }
     $this->_guid = b::guid('domref');
 }
예제 #2
0
파일: assetsTest.php 프로젝트: boltphp/core
 public function test_devModeFilter()
 {
     if (!class_exists('lessc')) {
         $this->markTestSkipped('LessPHP is not installed');
     }
     b::env('dev');
     // we need out less filter
     $this->a->filter('less', 'Lessphp');
     $this->a->filter('*', 'CssMin', false);
     $file = b::path($this->dir, 'less/file.less');
     $exp = "footer {\n  background: green;\n}\n" . "body header {\n  background: red;\n}";
     $this->assertEquals($exp, $this->a->processFile($file));
     b::env('prod');
     $exp = "footer{background:green}" . "body header{background:red}";
     $this->assertEquals($exp, $this->a->processFile($file));
 }
예제 #3
0
파일: assets.php 프로젝트: boltphp/core
 public function processFile($path, $config = [])
 {
     $rel = b::param('rel', false, $config);
     $url = b::param('url', false, $config);
     $useGlobalFilters = b::param('useGlobalFilters', true, $config);
     // get the file
     $file = $this->getFile($path);
     $root = pathinfo($path)['dirname'];
     $ext = pathinfo($path)['extension'];
     // get it's tree
     $content = $file->getContent();
     if (empty($content)) {
         return $content;
     }
     $inc = [];
     // parse the string
     $found = $this->parseString($content, $root);
     if (b::param('filterOnly', false, $config) === 'true') {
         $found = ['filter' => $found['filter']];
     }
     $tree = $this->getCombinedTree($found, $ext);
     $reduce = function ($items, $reduce) {
         $resp = [];
         foreach ($items as $key => $files) {
             $resp[] = $key;
             $resp += $reduce($files, $reduce);
         }
         return $resp;
     };
     // loop through each file and append
     foreach (array_unique($reduce($tree, $reduce)) as $f) {
         if ($f === $path) {
             continue;
         }
         $inc[] = $this->processFile($f);
     }
     $source = false;
     $sourcePath = false;
     $targetPath = false;
     if ($url) {
         $parts = parse_url($url);
         $source = "{$parts['scheme']}://{$parts['host']}";
         $targetPath = trim($parts['path'], '/');
         $sourcePath = $targetPath . '/' . trim($rel, '/');
     }
     $inc[] = $content;
     $a = new StringAsset(implode("\n", $inc), [], $source, $sourcePath);
     if ($targetPath) {
         $a->setTargetPath($targetPath);
     }
     // use filters
     if ($useGlobalFilters !== false) {
         if (array_key_exists($ext, $this->_filters)) {
             foreach ($this->_filters[$ext] as $filter) {
                 if ($filter[1] === false and b::env() === 'dev') {
                     continue;
                 }
                 $a->ensureFilter(new $filter[0]());
             }
         }
         foreach ($this->_filters['*'] as $filter) {
             if ($filter[1] === false and b::env() === 'dev') {
                 continue;
             }
             $a->ensureFilter(new $filter[0]());
         }
     }
     $a->ensureFilter(new CssRewriteFilter());
     return trim($a->dump());
 }