Jarves\Filesystem\WebFilesystem::wrap PHP Метод

wrap() публичный Метод

This maintains the file references. Jarves does not store the actual path in references but an ID. This ID is related to the path. If a file path is changed we need only to change one place (system_file table) instead of all references.
public wrap ( Jarves\File\FileInfoInterface | Jarves\File\FileInfoInterface[] $fileInfo ) : Jarves\File\FileInfoInterface | Jarves\File\FileInfoInterface[] | File
$fileInfo Jarves\File\FileInfoInterface | Jarves\File\FileInfoInterface[]
Результат Jarves\File\FileInfoInterface | Jarves\File\FileInfoInterface[] | Jarves\Model\File
    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;
        }
    }