Prepares a fake record from the files table

@param array $fileinfo explicit file data
@return array
183200
protected function make_file_record(array $fileinfo) {

        $defaultrecord = array(
            'contenthash'   => file_storage::hash_from_string(''),
            'contextid'     => $this->contextid,
            'component'     => $this->component,
            'filearea'      => $this->filearea,
            'itemid'        => $this->itemid,
            'filepath'      => null,
            'filename'      => null,
            'filesize'      => 0,
            'userid'        => $this->userid,
            'mimetype'      => null,
            'status'        => 0,
            'timecreated'   => $now = time(),
            'timemodified'  => $now,
            'source'        => null,
            'author'        => null,
            'license'       => null,
            'sortorder'     => 0,
        );

        if (!array_key_exists('id', $fileinfo)) {
            $defaultrecord['id'] = $this->converter->get_nextid();
        }

        // override the default values with the explicit data provided and return
        return array_merge($defaultrecord, $fileinfo);
    }
557216
protected function normalizeFileInfo(IFileInfo $file)
    {
        $normalized = [
            'type' => $file->isDirectory() ? 'dir' : 'file',
            'path' => ltrim($this->getFilePath($file), $this->pathSeparator),
            'timestamp' => $file->getMTime()
        ];

        if (!$file->isDirectory()) {
            $normalized['size'] = $file->getSize();
        }

        return $normalized;
    }
123405
protected function mapFileInfo(SplFileInfo $file)
    {
        $normalized = [
            'type' => $file->getType(),
            'path' => $this->getFilePath($file),
        ];

        $normalized['timestamp'] = $file->getMTime();

        if ($normalized['type'] === 'file') {
            $normalized['size'] = $file->getSize();
        }

        return $normalized;
    }
1134542
protected function getCachedFileInfo()
    {
        $cached = $this->getCachedInfo();

        if ($cached !== null && array_key_exists($this->filePath, $cached)) {
            return $cached[$this->filePath];
        }

        return null;
    }
717582
protected static function getFlattenFileData(array $files = [])
    {
        $return = [];

        foreach (array_keys($files['tmp_name']) as $key) {
            $file = [
                'tmp_name' => $files['tmp_name'][$key],
                'size' => $files['size'][$key],
                'error' => $files['error'][$key],
                'name' => $files['name'][$key],
                'type' => $files['type'][$key],
            ];

            $return[$key] = self::createUploadedFile($file);
        }

        return $return;
    }
143827
public function deleteFile(FileInfo $fileInfo)
    {
        try {
            $fm = new Filesystem();
            $file = $fileInfo->getFilepath(true);
            $fm->remove($file);
        } catch (\Exception $e) {
            $this->getFileManager()->throwError("Cannot delete file or directory", 500, $e);
        }
    }
359719
public function generate(FileInfoInterface $fileInfo, MediaProviderInterface $mediaProvider)
    {
        $ext = pathinfo($fileInfo->getName(), PATHINFO_EXTENSION);
        return md5(uniqid()).'.'.$ext;
    }
1187178
protected function extractDataFromFileInfo(FileInfo $info)
    {
        $data = [];

        if ($info instanceof UploadedFile) {
            $data['original_name']      = $info->getClientOriginalName();
            $data['original_extension'] = $info->getClientOriginalExtension();
        }

        return $data;
    }
30345
public static function file_info($path, $area = null)
	{
		$info = array(
			'original' => $path,
			'realpath' => '',
			'dirname' => '',
			'basename' => '',
			'filename' => '',
			'extension' => '',
			'mimetype' => '',
			'charset' => '',
			'size' => 0,
			'permissions' => '',
			'time_created' => '',
			'time_modified' => '',
		);

		if ( ! $info['realpath'] = static::instance($area)->get_path($path) or ! is_file($info['realpath']))
		{
			throw new \InvalidPathException('Filename given is not a valid file.');
		}

		$info = array_merge($info, pathinfo($info['realpath']));

		if ( ! $fileinfo = new \finfo(FILEINFO_MIME, \Config::get('file.magic_file', null)))
		{
			throw new \InvalidArgumentException('Can not retrieve information about this file.');
		}

		$fileinfo = explode(';', $fileinfo->file($info['realpath']));

		$info['mimetype'] = isset($fileinfo[0]) ? $fileinfo[0] : 'application/octet-stream';

		if (isset($fileinfo[1]))
		{
			$fileinfo = explode('=', $fileinfo[1]);
			$info['charset'] = isset($fileinfo[1]) ? $fileinfo[1] : '';
		}

		$info['size'] = static::get_size($info['realpath'], $area);
		$info['permissions'] = static::get_permissions($info['realpath'], $area);
		$info['time_created'] = static::get_time($info['realpath'], $type = 'created', $area);
		$info['time_modified'] = static::get_time($info['realpath'], $type = 'modified', $area);

		return $info;
	}
53847
private function createFile(array $fileInfo = []) {
    $file = new \Nuki\Models\Data\File($fileInfo['tmp_name'], $fileInfo['size']);
    
    $file->setExtension(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
    $file->setName(pathinfo($fileInfo['name'], PATHINFO_BASENAME));
    
    return $file;
  }
273948
public function prepareExportFileVariables() : array {
		$result = [
			'success' => false,
			'error' => [],
			'data' => []
		];
		// details
		$details = [];
		if (!empty($this->collection['details'])) {
			$this->disassembleCollectionObject($this->collection['details'], $details);
		}
		// step 1: fields
		$result['data'][$this->collection['name']] = [];
		foreach ($this->fields as $k => $v) {
			if (!$this->skipExportField($k, $v)) continue;
			// if we have detail
			if (!empty($details[$k])) {
				$result['data'][$details[$k]['name']] = [];
				foreach ($details[$k]['pk'] as $k2 => $v2) {
					if ($k2 == 0 && strpos($v2, 'tenant_id') !== false) continue;
					$result['data'][$details[$k]['name']][0][$v2] = $v2;
				}
				continue;
			}
			// regular field
			$result['data'][$this->collection['name']][0][$k] = $k;
		}
		// step 2: detail fields
		foreach ($this->detail_fields as $k => $v) {
			$result['data'][$details[$k]['name']] = [];
			// add pk
			foreach ($details[$k]['pk'] as $k2 => $v2) {
				if ($k2 == 0 && strpos($v2, 'tenant_id') !== false) continue;
				$result['data'][$details[$k]['name']][0][$v2] = $v2;
			}
			// add fields
			foreach ($v['elements'] as $k2 => $v2) {
				if (!$this->skipExportField($k2, $v2)) continue;
				$result['data'][$details[$k]['name']][0][$k2] = $k2;
			}
		}
		$result['success'] = true;
		return $result;
	}
164824
public function getFileContent($filePath, $createIfNotExists = false)
    {
        if ($createIfNotExists && ! $this->disk->exists($filePath)) {
            if (! $this->disk->exists($directory = dirname($filePath))) {
                mkdir($directory, 0777, true);
            }

            file_put_contents($filePath, "<?php\n\nreturn [];");

            return [];
        }

        try {
            return (array) include $filePath;
        } catch (\ErrorException $e) {
            throw new FileNotFoundException('File not found: '.$filePath);
        }
    }
1334656
public function checkMimeType($fileInfo)
    {
        $mime = $fileInfo->getMimetype();
        if ($mime != 'directory' && !in_array($mime, $this->getFileManager()->getExtensionsAllowed())) {
            return 'Mime type "' . $mime . '" not allowed for file "' . $fileInfo->getFilename() . '"';
        }

        return true;
    }
988393
public function copy_to_storage($filerecord) {
        if (!$this->is_readable() or $this->is_directory()) {
            return false;
        }
        $filerecord = (array)$filerecord;

        $fs = get_file_storage();
        if ($existing = $fs->get_file($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'], $filerecord['itemid'], $filerecord['filepath'], $filerecord['filename'])) {
            $existing->delete();
        }
        $fs->create_file_from_storedfile($filerecord, $this->lf);

        return true;
    }
4328
public function provideName(FileInfo $srcFileInfo)
    {
        if (!$srcFileInfo->isFile()) {
            throw new \InvalidArgumentException(sprintf(
                'The source file does not exist on "%s" specified path.',
                $srcFileInfo->toString()
            ));
        }
        $hash = hash_file($this->algorithm, $srcFileInfo->toString());

        $dstFileInfo = $this->provideNameByHash($srcFileInfo, $hash);

        return $dstFileInfo;
    }
453812
public function prepare($files)
    {
        if (request()->has(static::FILE_DELETE_FLAG)) {
            return $this->destroy(request(static::FILE_DELETE_FLAG));
        }

        if (is_string($files) && request()->has(static::FILE_SORT_FLAG)) {
            return $this->sortFiles($files);
        }

        $targets = array_map([$this, 'prepareForeach'], $files);

        return array_merge($this->original(), $targets);
    }
809986
private function updateInformation(array $inputInformation, array $updateInformation)
    {
        foreach ($inputInformation as $name => $information) {
            $columnName = $information['colname'] . '__sort';
            $position   = \array_flip(\array_keys($updateInformation))[$name];

            $updateInformation = \array_merge(
                \array_slice($updateInformation, 0, ($position + 1)),
                [
                    $columnName => [
                        'colname' => $columnName,
                        'type'    => 'filesort'
                    ]
                ],
                \array_slice($updateInformation, ($position ? $position - 1 : $position + 1))
            );
        }

        return $updateInformation;
    }