[resortByTime 对数组按照时间重新排序]
@DateTime 2018-10-09
@param    [type]     &$files [description]
@return   [type]             [description]
518668
private function resortByTime(&$files)
    {
        $length = count($files); // 文件数量
        for($i=1; $i<$length; $i++) {
            for($j=0; $j<$length - $i; $j++){
                if ( (int)strtotime($files[$j]['date']) <  (int)strtotime($files[$j+1]['date'])) {
                    $temp = $files[$j+1];
                    $files[$j+1] = $files[$j];
                    $files[$j] = $temp;
                }
            }
        }
    }
1138045
public function addServersFromFiles($files = [])
    {

        // Since we expect an array let us turn a string (i.e. single file) into an array
        if (!is_array($files)) {
            $files = [$files];
        }

        // Iterate over the file(s) and add them
        foreach ($files as $file) {
            // Check to make sure the file exists and we can read it
            if (!file_exists($file) || !is_readable($file)) {
                continue;
            }

            // See if this file is JSON
            if (($servers = json_decode(file_get_contents($file), true)) === null
                && json_last_error() !== JSON_ERROR_NONE
            ) {
                // Type not supported
                continue;
            }

            // Add this list of servers
            $this->addServers($servers);
        }

        return $this;
    }
1337045
protected function filterFiles($files)
    {
        foreach ($files as $key => $file) {
            if ($file instanceof UploadedFile) {
                continue;
            }

            if (is_array($file)) {
                if (! isset($file['name'])) {
                    $files[$key] = $this->filterFiles($files[$key]);
                } elseif (isset($files[$key]['error']) && $files[$key]['error'] !== 0) {
                    unset($files[$key]);
                }

                continue;
            }

            unset($files[$key]);
        }

        return $files;
    }
1041069
public function createUploadedFilesFromArray(array $files)
    {
        $uploadedFiles = [];

        if (isset($files['tmp_name']) && ! is_array($files['tmp_name'])) {
            $uploadedFiles[] = $this->createUploadedFile(
                $files['tmp_name'],
                $files['size'],
                $files['error'],
                $files['name'],
                $files['type']
            );
        } elseif (isset($files['tmp_name']) && is_array($files['tmp_name'])) {
            foreach ($files['tmp_name'] as $key => $file) {
                $uploadedFiles[] = $this->createUploadedFile(
                    $file,
                    $files['size'][$key],
                    $files['error'][$key],
                    $files['name'][$key],
                    $files['type'][$key]
                );
            }
        } else {
            foreach ($files as $key => $value) {
                $uploadedFiles[$key] = $this->createUploadedFilesFromArray($value);
            }
        }

        return $uploadedFiles;
    }
1185019
public function watch($files)
    {
        $files = (array) $files;

        foreach ($files as $file) {
            $path = realpath($file);
            $this->_watched[$path] = $path;
        }
        $this->refreshWatched();
    }
1064779
private function removeFiles($files)
    {
        // Grab the duration
        $duration = $this->option('duration');
        
        // Grab the minimum acceptable timestamp
        $timestamp = time() - $duration;

        // Cycle through the list checking their creation dates
        foreach($files as $file)
        {
            // Compare the file modification times
            if(filemtime($file) < $timestamp)
            {
                // It passes the acceptable, so remove it
                unlink($file);

                // Check if the directory containing this file is empty
                if(count(scandir(dirname($file))) == 2)
                {
                    // It was empty, so just remove it
                    rmdir(dirname($file));
                }
            }
        }
    }
362379
protected function cleanup(array $files = array())
    {
        if (empty($files)) {
            return $this;
        }
        foreach ($files as $file) {
            if (!file_exists($file->name)) {
                continue;
            }
            unlink($file->name);
        }
        return $this;
    }
865878
public function setFile($file = null)
    {
        if (is_null($file)) {
            $this->file = ['name' => date('Ymd-His'), 'part' => 1];
        } else {
            if (!array_key_exists("name", $file) && !array_key_exists("part", $file)) {
                $this->file = $file['1'];
            } else {
                $this->file = $file;
            }
        }
        return $this;
    }
484220
public static function getFirstExistingFileArray($files = [])
    {
        foreach ($files as $file) {
            if (file_exists(\Yii::getAlias($file))) {
                return $file;
            }
        }

        return null;
    }
149879
public function bind($files)
	{
		try
		{
			$files = str_replace(array(" ", "\t", "\n"), "", $files);
			$id = md5($files);
			$files = explode(",", trim($files, ","));

			if ($this->debug)
				return $this->generateDebugLink($files);

			if ($this->documentRootDir)
				$dr = $this->documentRootDir;
			else
				$dr = $_SERVER["DOCUMENT_ROOT"];

			$outDir = "{$dr}{$this->outdir}";

			if (!is_dir($outDir))
				throw new \Exception("Asset directory doesn't exist {$outDir}");

			if (!$files)
				throw new \Exception ("Parameter 'files' is not defined");

			if (count($files) == 0)
				throw new \Exception ( "You have to set a file at least");


			$outputFile = "{$outDir}/{$id}.js";
			$metaFile = "{$outDir}/{$id}.meta";

			$now = time();
			$hash = null;
			$storedHash = null;

			if (!is_file($metaFile) || $this->ttl == 0)
			{
				list($mtimes, $fileList) = $this->generateInfo($files);

				$this->writeMeta($metaFile, $mtimes, $now);
				$this->compileAssets($fileList, $outputFile);
				return $this->generateLink($this->outdir, $id, $mtimes);
			}
			else
			{
				$meta = file_get_contents($metaFile);

				list($storedHash, $age) = explode(":", $meta);
				if ((intval($age) + $this->ttl) < $now)
				{
					list($mtimes, $fileList) = $this->generateInfo($files);
					$this->writeMeta($metaFile, $mtimes, $now);

					if ($mtimes !== $storedHash)
					{
						$this->compileAssets($fileList, $outputFile);
						return $this->generateLink($this->outdir, $id, $mtimes);
					}
				}
				return $this->generateLink($this->outdir, $id, $storedHash);
			}
		}
		catch (\Exception $e)
		{
			return "Assets error: " . $e->getMessage();
		}
	}
953179
public function set(array $files)
    {
        if (!empty($files)) {
            foreach ($files as $_file) {
                if (is_array($_file) && isset($_file['file'])) {
                    $this->add(
                        $_file['file'],
                        isset($_file['media']) ? $_file['media'] : '',
                        isset($_file['condition']) ? $_file['condition'] : null
                    );
                } elseif (is_string($_file)) {
                    $this->add($_file);
                }
            }
        }
        return $this;
    }
734121
public function setFiles($files = array())
    {
        if (count($files) === 0) {
            $this->_files = $_FILES;
        } else {
            $this->_files = $files;
        }

        foreach($this->_files as $file => $content) {
            if (!isset($content['error'])) {
                unset($this->_files[$file]);
            }
        }

        return $this;
    }
1367304
public function setFilemtime($file, $filemtime)
    {
        $this->readMetadataFile();

        $this->metadata[$file]['mt'] = $filemtime;

        return $this;
    }
208985
function setFiles($files)
    {
        $this->files = \Poirot\Http\Psr\normalizeFiles($files);
        return $this;
    }
33810
public function decodeFiles(array $files)
    {
        // combine into one document.
        //
        $suiteDocument = new Document('phpbench');
        $rootEl = $suiteDocument->createRoot('phpbench');

        foreach ($files as $file) {
            $fileDom = new Document();
            $fileDom->load($file);

            foreach ($fileDom->query('./suite') as $suiteEl) {
                $importedEl = $suiteDocument->importNode($suiteEl, true);
                $rootEl->appendChild($importedEl);
            }
        }

        return $this->decode($suiteDocument);
    }
690585
protected function convertUploadedFiles(array $files)
    {
        $fileObjects = [];
        
        foreach ($files as $fieldName => $file) {
            if ($file instanceof UploadedFileInterface) {
                $fileObjects[$fieldName] = $file;
            } elseif (!isset($file['tmp_name']) && !isset($file['error'])) {
                $fileObjects[$fieldName] = $this->convertUploadedFiles($file);
            } else {
                $fileObjects[$fieldName] = new UploadedFile($file);
            }
        }
        
        return $fileObjects;
    }
606318
public function setFiles(array $files)
    {
        foreach($files as $file) {
            if (!$file instanceof File) {
                throw new ObjectNotAFileException($file . ' is not a file');
            }
        }

        $this->files = $files;
        return $this;
    }