示例#1
0
 /**
  * Generate compiled file(s) and render link(s)
  */
 public function render()
 {
     $hasArgs = func_num_args() > 0;
     if ($hasArgs) {
         $backup = $this->compiler->getFileCollection();
         $newFiles = new FileCollection($backup->getRoot());
         $newFiles->addFiles(func_get_args());
         $this->compiler->setFileCollection($newFiles);
     }
     // remote files
     foreach ($this->compiler->getFileCollection()->getRemoteFiles() as $file) {
         echo $this->getElement($file), PHP_EOL;
     }
     foreach ($this->compiler->generate() as $file) {
         echo $this->getElement($this->tempPath . '/' . $file->file . '?' . $file->lastModified), PHP_EOL;
     }
     if ($hasArgs) {
         $this->compiler->setFileCollection($backup);
     }
 }
 /**
  * @param string $code
  * @param WebLoader\Compiler $loader
  * @param string $file
  * @return string
  */
 public function __invoke($code, WebLoader\Compiler $loader, $file)
 {
     $ree = '~\\/~';
     $root = $loader->getFileCollection()->getRoot();
     $rootSegments = preg_split($ree, $root);
     $pathInfo = pathinfo($file);
     $pathInfoSegments = preg_split($ree, $pathInfo['dirname']);
     $fileRelativePath = array_diff($pathInfoSegments, $rootSegments);
     $fileRelativePath[] = $pathInfo['basename'];
     $fileRelativePath = join(DIRECTORY_SEPARATOR, $fileRelativePath);
     $this->lilo->appendLoadPath($root);
     $this->lilo->scan($fileRelativePath);
     $fileDeps = $this->lilo->getFileChain($fileRelativePath);
     $code = array_reduce($fileDeps, function ($memo, $dep) {
         return $memo . $dep['content'];
     }, '');
     return $code;
 }