public function wrap($fileInfo)
{
if (is_array($fileInfo)) {
$result = [];
$paths = [];
foreach ($fileInfo as $file) {
if ($file instanceof File) {
return $fileInfo;
//it's already a `File` array, return it.
}
$paths[] = $file->getPath();
}
$files = FileQuery::create()->orderById(Criteria::ASC)->filterByPath($paths)->groupByPath()->find()->toKeyIndex('path');
foreach ($fileInfo as $file) {
if (isset($files[$file->getPath()])) {
$this->checkFileValues($file, $files[$file->getPath()]);
$result[] = $files[$file->getPath()];
} else {
$result[] = $this->createFromPathInfo($file);
}
}
return $result;
} else {
if ($fileInfo instanceof File) {
return $fileInfo;
//it's already a `File`, return it.
}
$path = $fileInfo->getPath();
$fileObj = FileQuery::create()->orderById()->filterByPath($path)->groupByPath()->findOne();
if (!$fileObj) {
$fileObj = $this->createFromPathInfo($fileInfo);
} else {
$this->checkFileValues($fileInfo, $fileObj);
}
return $fileObj;
}
}