示例#1
0
 protected function parseFile($file)
 {
     $tokens = token_get_all(file_get_contents($file));
     //  var_dump($tokens);die();
     $count = count($tokens) - 1;
     for ($i = 0; $i < $count; $i++) {
         $token = $tokens[$i];
         if ($token[0] == 307) {
             $method = $token[1];
             if ($method === 'getCss') {
                 $type = 'css';
             } elseif ($method === 'getJs') {
                 $type = 'js';
             } else {
                 $type = null;
             }
             if ($type !== null) {
                 $arg = $this->getArgument($tokens, $i);
                 $sourcePath = AssetResolver::resolveSourcePath($arg, \eBuildy\Helper\ResolverHelper::getModulePathFromView($file));
                 if ($sourcePath === null) {
                     // var_dump(array('file' => $file, 'type' => $type, 'source' => $arg));
                 } else {
                     $this->assets[$sourcePath] = $type;
                 }
             }
         }
     }
 }
示例#2
0
 public function compile($type, $source, $options = array(), $force = false)
 {
     if ($this->isGroup($source)) {
         $grouping = true;
         $targetFileName = $source;
     } else {
         $grouping = false;
         $targetFileName = md5($this->templatingService->getContext() . $source);
     }
     $targetUri = ($type === 'js' ? $this->jsPath : $this->cssPath) . AssetResolver::resolveNameWithVersion($targetFileName, $type, $this->version, $this->versionFormat);
     $doCompilation = false;
     if ($this->enableCompilation) {
         if ($grouping) {
             $sourcePath = $this->getGroupAssetPath($type, $this->groups[$type][$source]);
         } else {
             $sourcePath = $this->getAssetPath($source);
         }
         $targetFilePath = WEB_PATH . AssetResolver::resolveNameForCompilation($targetUri);
         if ($force || $this->forceCompilation) {
             $doCompilation = true;
         } elseif ($this->enableCompilation) {
             if (!file_exists($targetFilePath)) {
                 $doCompilation = true;
             } elseif ($grouping) {
                 foreach ($sourcePath as $source) {
                     $m = filemtime($targetFilePath);
                     if (filemtime($source) > $m) {
                         $doCompilation = true;
                         break;
                     }
                 }
             } elseif (filemtime($sourcePath) > filemtime($targetFilePath)) {
                 $doCompilation = true;
             }
         }
         if ($doCompilation) {
             if ($type === 'js') {
                 $compiler = new Compiler\JSCompiler($options);
             } elseif ($type === 'css') {
                 $compiler = new Compiler\CSSCompiler($options);
             }
             if ($grouping) {
                 $compiler->compileGroup($sourcePath, $targetFilePath);
             } else {
                 $compiler->compile($sourcePath, $targetFilePath);
             }
         }
     }
     return $targetUri;
 }