返回批量读取文件的标签，支持 css/js/html，支持min机制
@param string $filetype
@param array  $filelist
@param string $relative_dir
@param bool $min
@return string
487525
static private function fileElement($filetype, $filelist, $relative_dir = '', $min = true)
    {
        if ($relative_dir) $relative_dir = rtrim($relative_dir, '/');
        $filearr = explode(',', $filelist);
        $filelist = array();
        $out = '';
        if (strpos($relative_dir, 'http') === 0) {  // 'https://path'
            $basePath = '';
            $baseUrl  = '';
        } elseif (strpos($relative_dir, '/') === 0) {   // '/path' 以/开头
            $basePath = Config::getWebRootPath() . $relative_dir  . '/';
            $baseUrl  = $relative_dir . '/';
        } else {    // 'dir/path' 不是以/开头
            $name = Ioc::web()->getCurrentModule()->getName();
            $basePath = Config::getWebRootPath() . '/' . $name . $relative_dir  . '/';
            $baseUrl  = $name . '/' . $relative_dir . '/';
            $baseUrl = str_replace('//', '/', $baseUrl);
        }
        
        foreach ($filearr as $file) {
            $file = trim($file);
            $absfile = $basePath . "$file"; // 文件绝对路径
            $file = $baseUrl . "$file";     // 相对app的url，
            
            if (file_exists($absfile)) {
                $filelist[] = $file;
            } else {
                Ioc::logger()->error('file is not exists: ' . $absfile);
            }
        }
        
        if (!empty($filelist)) {
            // 如果开启合并，使用minify机制加载
            if ($min) {
                $f = implode(',', $filelist);
                $src = Config::getRootUrl() . '/minify/?f='.$f;
                if ($filetype == 'css') {
                    $out = '<link type="text/css" href="' . $src . '" rel="stylesheet"  />' . "\r\n";
                } elseif ($filetype == 'js') {
                    $out = '<script type="text/javascript" src="' . $src . '"></script>' . "\r\n";
                } else {
                    $out = '';
                }
            } elseif ($filetype == 'css' || $filetype == 'js') {
                $method = $filetype == 'js' ? 'script' : $filetype;
                
                foreach ($filelist as $file) {
                    $out .= self::$method($css) . "\r\n";
                }
            }
        }
        return $out;
    }
416173
public static function langParser($filePath, $relativePath = '')
	{
		$lang = [];
		$parsed = self::arrayParser($relativePath . $filePath);

		foreach ($parsed as $parse)
		{
			$lang = array_merge($lang, $parse);
		}

		return $lang;
	}
639660
private void listDirectory(File directory,
                               RelativeDirectory subdirectory,
                               Set<JavaFileObject.Kind> fileKinds,
                               boolean recurse,
                               ListBuffer<JavaFileObject> resultList) {
        File d = subdirectory.getFile(directory);
        if (!caseMapCheck(d, subdirectory))
            return;

        File[] files = d.listFiles();
        if (files == null)
            return;

        if (sortFiles != null)
            Arrays.sort(files, sortFiles);

        for (File f: files) {
            String fname = f.getName();
            if (f.isDirectory()) {
                if (recurse && SourceVersion.isIdentifier(fname)) {
                    listDirectory(directory,
                                  new RelativeDirectory(subdirectory, fname),
                                  fileKinds,
                                  recurse,
                                  resultList);
                }
            } else {
                if (isValidFile(fname, fileKinds)) {
                    JavaFileObject fe =
                        new RegularFileObject(this, fname, new File(d, fname));
                    resultList.append(fe);
                }
            }
        }
    }
24309
protected function addFileModificationCallbacks(&$fileList)
	{
		$fileList['index.php']['callback']=array($this,'generateIndex');
		$fileList['index-test.php']['callback']=array($this,'generateIndex');
		$fileList['protected/tests/bootstrap.php']['callback']=array($this,'generateTestBoostrap');
		$fileList['protected/yiic.php']['callback']=array($this,'generateYiic');
	}
966738
public function lintFileList($file_list) {
    $this->say("Linting YAML files...");

    $files = explode("\n", $file_list);

    /** @var \Acquia\Blt\Robo\Filesets\FilesetManager $fileset_manager */
    $fileset_manager = $this->getContainer()->get('filesetManager');
    $fileset_ids = $this->getConfigValue('validate.yaml.filesets');
    $filesets = $fileset_manager->getFilesets($fileset_ids);

    $bin = $this->getConfigValue('composer.bin');
    $command = "'$bin/yaml-cli' lint '%s'";
    foreach ($filesets as $fileset_id => $fileset) {
      $filesets[$fileset_id] = $fileset_manager->filterFilesByFileset($files, $fileset);
    }

    $this->executeCommandAgainstFilesets($filesets, $command);
  }
1169082
function relativePath(file1, file2) {
  var file1Dirname = path.dirname(file1);
  var file2Dirname = path.dirname(file2);

  if (file1Dirname !== file2Dirname) {
    return path.relative(file1Dirname, file2Dirname);
  }
  return '';
}
608806
public static function calculate_relative_path($file, $returnDir = false)
    {
        // We find the document root of the webserver
        $doc_root = $_SERVER['DOCUMENT_ROOT'];

        // Remove the document root, from the FULL absolute path of the
        // file we're looking for
        $ret = "/" . str_replace($doc_root, "", $file, $ok);
        if (!$ok) {
            return false;
        }

        // If they want the path to the dir, only return the dir part
        if ($returnDir) {
            $ret = dirname($ret) . "/";
        }

        $ret = preg_replace("|//|", "/", $ret);

        return $ret;
    }
855358
public function getCssContent(string $fileName, bool $minify): string
    {
        $content = file_get_contents($fileName);

        if ($content === false) {
            throw new RuntimeException(sprintf('File could be read: %s', $fileName));
        }

        if ($minify === true) {
            $compressor = new CssMinifier();
            $content = $compressor->run($content);
        }

        return $content;
    }
1038629
public static function findByFileType( $parentId, $parentType, $fileType ) {

		$fileTable = CoreTables::getTableName( CoreTables::TABLE_FILE );

		return self::queryByParent( $parentId, $parentType )->andFilterWhere( [ 'like', "$fileTable.type", $fileType ] )->all();
	}
296005
public function getAssets($type = null, $relativeTo = self::RELATIVE_PATH)
    {
        $cssFiles = $this->cssFiles;
        $jsFiles = $this->jsFiles;

        if ($this->includeVendors !== false) {
            if ($this->includeVendors === true || in_array('css', $this->includeVendors)) {
                $cssFiles = array_merge($this->cssVendors, $cssFiles);
            }
            if ($this->includeVendors === true || in_array('js', $this->includeVendors)) {
                $jsFiles = array_merge($this->jsVendors, $jsFiles);
            }
        }

        if ($relativeTo) {
            $root = $this->getRelativeRoot($relativeTo, $this->basePath, $this->baseUrl);
            $cssFiles = $this->makeUriRelativeTo($cssFiles, $root);
            $jsFiles = $this->makeUriRelativeTo($jsFiles, $root);
        }

        $additionalAssets = $this->additionalAssets;
        // finds assets provided by collectors
        foreach ($this->debugBar->getCollectors() as $collector) {
            if (($collector instanceof AssetProvider) && !in_array($collector->getName(), $this->ignoredCollectors)) {
                $additionalAssets[] = $collector->getAssets();
            }
        }

        foreach ($additionalAssets as $assets) {
            $basePath = isset($assets['base_path']) ? $assets['base_path'] : null;
            $baseUrl = isset($assets['base_url']) ? $assets['base_url'] : null;
            $root = $this->getRelativeRoot($relativeTo,
                $this->makeUriRelativeTo($basePath, $this->basePath),
                $this->makeUriRelativeTo($baseUrl, $this->baseUrl));
            $cssFiles = array_merge($cssFiles, $this->makeUriRelativeTo((array) $assets['css'], $root));
            $jsFiles = array_merge($jsFiles, $this->makeUriRelativeTo((array) $assets['js'], $root));
        }

        return $this->filterAssetArray(array($cssFiles, $jsFiles), $type);
    }
791022
public function actionBrowse($type)
    {
        $files = null;
        $relative = null;
        // check if request type is defined
        if ($this->allowedExt[$type] === null || !Any::isArray($this->allowedExt[$type])) {
            throw new NativeException('Hack attempt');
        }
        // list files in directory
        $files = File::listFiles('/upload/' . $type, $this->allowedExt[$type]);

        // absolute path to relative URI
        foreach ($files as $file) {
            $newName = Str::sub($file, Str::length(root)+1);
            $relative[] = trim(Str::replace(DIRECTORY_SEPARATOR, '/', $newName), '/');
        }

        // generate response
        return App::$View->render('editor/browse', [
            'callbackName' => App::$Security->strip_tags(App::$Request->query->get('CKEditor')),
            'callbackId' => (int)App::$Request->query->get('CKEditorFuncNum'),
            'files' => $relative,
            'type' => $type
        ], __DIR__);
    }
1228503
public function compress($type, $files, $file) 
	{
		// files have been updated so update the minified file
		if($this->isUpdated($files))
		{
			$content = $this->getFileContents($files);
			switch($type){
				case 'css':
					$content = $this->minifyCSS($content);
				break;
				case 'js':
					$content = $this->minifyJS($content);
				break;
			}
			$this->saveFile($file, $content);
		}
		return str_replace($this->scriptPath,$this->coreUrl,$file);	
	}
746855
function getFileList($rdir, $showHidden = false)
    {
        $filelist = '';
        if ($handle = opendir($rdir))
        {
            while (false !== ($file = readdir($handle)))
            {
                if ($file == '.' or $file == '..')
                {
                    continue;
                }

                if ($file{0} == "." and !$showHidden)
                {
                    continue;
                }

                $stats = stat($rdir . "/" . $file);
                if (is_dir($rdir . "/" . $file)) $mode = "d"; else $mode = "-";
                $moded = sprintf("%o", ($stats['mode'] & 000777));
                $mode1 = substr($moded, 0, 1);
                $mode2 = substr($moded, 1, 1);
                $mode3 = substr($moded, 2, 1);
                switch ($mode1) {
                    case "0":
                        $mode .= "---";
                        break;
                    case "1":
                        $mode .= "--x";
                        break;
                    case "2":
                        $mode .= "-w-";
                        break;
                    case "3":
                        $mode .= "-wx";
                        break;
                    case "4":
                        $mode .= "r--";
                        break;
                    case "5":
                        $mode .= "r-x";
                        break;
                    case "6":
                        $mode .= "rw-";
                        break;
                    case "7":
                        $mode .= "rwx";
                        break;
                }
                switch ($mode2) {
                    case "0":
                        $mode .= "---";
                        break;
                    case "1":
                        $mode .= "--x";
                        break;
                    case "2":
                        $mode .= "-w-";
                        break;
                    case "3":
                        $mode .= "-wx";
                        break;
                    case "4":
                        $mode .= "r--";
                        break;
                    case "5":
                        $mode .= "r-x";
                        break;
                    case "6":
                        $mode .= "rw-";
                        break;
                    case "7":
                        $mode .= "rwx";
                        break;
                }
                switch ($mode3) {
                    case "0":
                        $mode .= "---";
                        break;
                    case "1":
                        $mode .= "--x";
                        break;
                    case "2":
                        $mode .= "-w-";
                        break;
                    case "3":
                        $mode .= "-wx";
                        break;
                    case "4":
                        $mode .= "r--";
                        break;
                    case "5":
                        $mode .= "r-x";
                        break;
                    case "6":
                        $mode .= "rw-";
                        break;
                    case "7":
                        $mode .= "rwx";
                        break;
                }
                $uidfill = "";
                for ($i = strlen($stats['uid']); $i < 5; $i++) $uidfill .= " ";
                $gidfill = "";
                for ($i = strlen($stats['gid']); $i < 5; $i++) $gidfill .= " ";
                $sizefill = "";
                for ($i = strlen($stats['size']); $i < 11; $i++) $sizefill .= " ";
                $nlinkfill = "";
                for ($i = strlen($stats['nlink']); $i < 5; $i++) $nlinkfill .= " ";
                $mtime = date("M d H:i", $stats['mtime']);
                $filelist .= $mode . $nlinkfill . $stats['nlink'] . " " . $stats['uid'] . $uidfill . $stats['gid'] . $gidfill . $sizefill . $stats['size'] . " " . $mtime . " " . $file . "\r\n";
            }
            closedir($handle);
        }
        return $filelist;
    }
171911
public function getReferencedFilesFromDiff(array $diff_files, bool $include_referencing_files = true)
    {
        $all_inherited_files_to_check = $diff_files;

        while ($diff_files) {
            $diff_file = array_shift($diff_files);

            $dependent_files = $this->file_reference_provider->getFilesInheritingFromFile($diff_file);

            $new_dependent_files = array_diff($dependent_files, $all_inherited_files_to_check);

            $all_inherited_files_to_check = array_merge($all_inherited_files_to_check, $new_dependent_files);
            $diff_files = array_merge($diff_files, $new_dependent_files);
        }

        $all_files_to_check = $all_inherited_files_to_check;

        if ($include_referencing_files) {
            foreach ($all_inherited_files_to_check as $file_name) {
                $dependent_files = $this->file_reference_provider->getFilesReferencingFile($file_name);
                $all_files_to_check = array_merge($dependent_files, $all_files_to_check);
            }
        }

        return array_combine($all_files_to_check, $all_files_to_check);
    }
1092635
public function readFileStream($containerName, $fileName, $relativePath)
    {
        return $this->fileUploadFacade->readFileStream($containerName, $fileName, $relativePath);
    }
722382
public function getFilesInDir($dir_path, array $file_extensions)
    {
        $file_paths = [];

        /** @var \RecursiveDirectoryIterator */
        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir_path));
        $iterator->rewind();

        while ($iterator->valid()) {
            if (!$iterator->isDot()) {
                $extension = $iterator->getExtension();
                if (in_array($extension, $file_extensions, true)) {
                    $file_paths[] = (string)$iterator->getRealPath();
                }
            }

            $iterator->next();
        }

        return $file_paths;
    }
984106
public static function getUrlPathFromFilePath($filePath, $relativeToRootUrl = false) {
		$dir = $filePath;
		$rootPath = ROOT_PATH;
		
		if (strpos($dir, ROOT_PATH) === 0) {
			$dirUrl = ROOT_URL.substr(ROOT_PATH, strlen(__DIR__)+1);
		} else {
			// The directory URL is below the ROOT_URL. Let's try to find it (not 100% success rate)
			$rootPaths = explode(DIRECTORY_SEPARATOR, trim($rootPath, DIRECTORY_SEPARATOR));
			$thisDirs = explode(DIRECTORY_SEPARATOR, trim($dir, DIRECTORY_SEPARATOR));
		
			for ($i=0; $i<count($rootPaths); $i++) {
				if ($rootPaths[$i] != $thisDirs[$i]) {
					break;
				}
			}
		
			$nbSkip = count($rootPaths) - $i;
			$urls = explode('/', trim(ROOT_URL, '/'));
		
			if ($nbSkip > count($urls)) {
				throw new Exception('The directory "'.$dir.'" is almost certainly out of reach from the web.');
			}
		
			$dirUrls = array();
			for ($j=0; $j < count($urls)- $nbSkip; $j++) {
				$dirUrls[] = $urls[$j];
			}
			for ($k = $i; $k<count($thisDirs); $k++) {
				$dirUrls[] = $thisDirs[$k];
			}
			$dirUrl = '/'.implode('/', $dirUrls);
			
			if ($relativeToRootUrl) {
				$dirUrl = ltrim(str_repeat('/..', count($urls)).$dirUrl, '/');
			}
		}
		return $dirUrl;
	}