Builds a UnitOfWork instance from the given \SplFileInfo

@param \SplFileInfo $fileInfo The fileInfo to build from

@throws \InvalidArgumentException

@return UnitOfWork The instantiated migration
428377
public static function buildFromSplFileInfo(\SplFileInfo $fileInfo)
    {
        $uniqueId = $fileInfo->getBasename();
        $file = $fileInfo->openFile();
        $query = '';

        while (!$file->eof()) {
            $query .= $file->fgets();
        }

        return new UnitOfWork(new Uid($uniqueId), new Workload($query), new \DateTime());
    }
919043
public static function createFromFile($filename, $force_extension = null)
    {
        self::$instance = new Collector;

        self::$instance->buffer = null;

        $extension = ($force_extension!=null)
            ? $force_extension
            : pathinfo($filename, PATHINFO_EXTENSION);

        foreach(self::$instance->readers as $slug => $base) {

            if (Str::lower($extension) == $slug) {

                $class_name = 'PhpOffice\\PhpSpreadsheet\\Reader\\'.$base;
                $reader = new $class_name();
                self::$instance->buffer = $reader->load($filename);
                break;
            }
        }

        if (self::$instance->buffer == null) {
            throw new \InvalidArgumentException(
                "Unsupported file type for reading. Use " . implode(',', self::$instance->readers));
        }

        self::$instance->debug_info = ['created_with' => __METHOD__];

        return self::$instance;
    }
875912
final public function createFile($filePath = null)
    {
        if (isset($filePath)) {
            $this->filePath = $filePath;
        }

        if (pathinfo($this->filePath, PATHINFO_EXTENSION) === '') {
            $this->filePath .= $this->fileExtension;
        }

        return $this;
    }
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;
    }
1201338
public function add(SplFileInfo $splFileInfo)
    {
        $fileSystem = new Filesystem();

        if (!$fileSystem->exists($splFileInfo->getRealPath())) {
            throw new Exception('Trying to add '.$splFileInfo->getRealPath().' missing file to the index');
        }

        // if the file is already present in the index, and its mtime has been modified, we add it to the change set
        if ($this->has($splFileInfo->getRealPath())
            && $splFileInfo->getMTime() !== $this->index[$splFileInfo->getRealPath()]) {
            $this->changes[$splFileInfo->getRealPath()] = $splFileInfo;
        }
        // add new or existing file to the index
        $this->index[$splFileInfo->getRealPath()] = $splFileInfo->getMTime();
    }
952220
public function validate(\Upload\FileInfoInterface $fileInfo)
    {
        $fileSize = $fileInfo->getSize();

        if ($fileSize < $this->minSize) {
            throw new \Upload\Exception(sprintf('File size is too small. Must be greater than or equal to: %s', $this->minSize), $fileInfo);
        }

        if ($fileSize > $this->maxSize) {
            throw new \Upload\Exception(sprintf('File size is too large. Must be less than: %s', $this->maxSize), $fileInfo);
        }
    }
824436
public function init(\SplFileInfo $file, $extension = null)
    {
        $config = Grav::instance()['config'];

        // some extension logic
        if (empty($extension)) {
            $this->extension('.' . $file->getExtension());
        } else {
            $this->extension($extension);
        }

        // extract page language from page extension
        $language = trim(basename($this->extension(), 'md'), '.') ?: null;
        $this->language($language);

        $this->hide_home_route = $config->get('system.home.hide_in_urls', false);
        $this->home_route = $this->adjustRouteCase($config->get('system.home.alias'));
        $this->filePath($file->getPathname());
        $this->modified($file->getMTime());
        $this->id($this->modified() . md5($this->filePath()));
        $this->routable(true);
        $this->header();
        $this->date();
        $this->metadata();
        $this->url();
        $this->visible();
        $this->modularTwig(strpos($this->slug(), '_') === 0);
        $this->setPublishState();
        $this->published();
        $this->urlExtension();


        return $this;
    }
100936
public function transform(SplFileInfo $file)
    {
        try {
            $taxonomyFile = $this->fileToTaxonomyFile->transform($file);
            $taxonomy = $this->buildTaxonomy($taxonomyFile);

            return $taxonomy;
        } catch (\Exception $e) {
            throw new TransformationFailure($e->getMessage(), 0, $e, $file->getRealPath());
        }
    }
299048
protected function addPluginFromFile(\SplFileInfo $fileInfo)
    {
        $class = $this->getFullClassFromFile($fileInfo);

        if (!is_null($class)) {
            $newPlugin         = new \stdClass();
            $newPlugin->class  = $class;
            $newPlugin->source = "core";
            $parts             = explode('\\', $newPlugin->class);
            $newPlugin->name   = end($parts);

            $this->pluginInfo[] = $newPlugin;
        }
    }
210055
protected function getConfigurationNesting(SplFileInfo $file, $configPath)
    {
        $directory = $file->getPath();

        if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) {
            $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
        }

        return $tree;
    }
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);
    }
101676
public function load(VersionInfo $versionInfo): self
    {
        $languages = [];
        foreach ($versionInfo->languageCodes as $languageCode) {
            $languages[] = $this->languageService->loadLanguage($languageCode);
        }

        $this->data = array_map(
            function (Language $language) use ($versionInfo) {
                return $this->valueFactory->createLanguage($language, $versionInfo);
            },
            $languages
        );

        return $this;
    }
669665
public function transform(SplFileInfo $file)
    {
        try {
            $contentFile = $this->fileToContentFile->transform($file);
            $contentItem = $this->buildContentItem($contentFile);

            return $contentItem;
        } catch (\Exception $e) {
            throw new TransformationFailure($e->getMessage(), 0, $e, $file->getRealPath());
        }
    }
748121
public function upload(\Upload\FileInfoInterface $fileInfo)
    {
        $destinationFile = $this->directory . $fileInfo->getNameWithExtension();
        if ($this->overwrite === false && file_exists($destinationFile) === true) {
            throw new \Upload\Exception('File already exists', $fileInfo);
        }

        if ($this->moveUploadedFile($fileInfo->getPathname(), $destinationFile) === false) {
            throw new \Upload\Exception('File could not be moved to final destination.', $fileInfo);
        }
    }
133985
public function create(\SplFileInfo $file)
    {
        $extension = $file->getExtension();
        switch ($extension) {
            case 'css':
                return new StylesheetDocument();
            case 'js':
                return new JavascriptDocument();
            default:
                if (strstr($this->getMimeType($file), 'image')) {
                    return new ImageDocument();
                }

                return new FileDocument();
        }
    }
563666
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        if (! array_key_exists('prooph.link.fileconnector', $config)) throw new \InvalidArgumentException('Missing prooph.link.fileconnector root config key');
        if (! is_array($config['prooph.link.fileconnector'])) throw new \InvalidArgumentException("Config for prooph.link.fileconnector must be an array");
        if (! array_key_exists('file_types', $config['prooph.link.fileconnector'])) throw new \InvalidArgumentException('Missing file_types in prooph.link.fileconnector config');

        $fileTypeAdapters = new FileTypeAdapterManager(new Config($config['prooph.link.fileconnector']['file_types']));

        $fileTypeAdapters->setServiceLocator($serviceLocator);

        return $fileTypeAdapters;
    }
225977
protected function generateType(FileGenerator $file, TypeGenerator $generator, Type $type, SplFileInfo $fileInfo)
    {
        $code = $generator->generate($file, $type);
        $this->filesystem->putFileContents($fileInfo->getPathname(), $code);
    }