Create VAST document from file

@param string $filename

@return Document
546733
public function fromFile($filename)
    {
        $xml = $this->createDomDocument();
        $xml->load($filename);

        return new Document($xml);
    }
189585
public static function fromFile($fileName) {
        if (!file_exists($fileName))
            throw new SettingsException("file $fileName does not exist");
        return static::fromString(file_get_contents($fileName), dirname($fileName));
    }
1195414
protected function create(string $filename){
        $fileSystem = new Filesystem();
        $source = $this->config['source'] ?: 'Source';
        $file_path = ROOT . '/' . $source;
        // 创建文件路径
        $fileSystem->exists($file_path) || $fileSystem->mkdir($file_path);

        $html = '';
        $html .= "---" . PHP_EOL;
        $html .= "title: " . $filename . PHP_EOL;
        $html .= "type: " . 'type' . PHP_EOL;
        $html .= "date: " . date('Y-m-d H:i:s') . PHP_EOL;
        $html .= "tags: " . $filename . PHP_EOL;
        $html .= "---" . PHP_EOL . PHP_EOL;
        $html .= "Create at ".date('Y-m-d H:i:s').PHP_EOL;
        $html .= 'You should edit this page as markdown'.PHP_EOL;

        $file_name = $file_path . '/' . $filename . '.md';
        if ($fileSystem->exists([$file_name])) {
            throw new Exception('Create '.$filename.'.php failed, this file exited!!!');
        }
        
        $status = file_put_contents($file_name, $html, LOCK_EX);
        if ($status === false) {
            throw new Exception('Create '.$filename.' failed!');
        }
    }
761174
public function expandFileProperties($filename) {
    $expanded_contents = Expander::expandArrayProperties(file($filename), $this->export());
    file_put_contents($filename, implode("", $expanded_contents));
  }
890841
public function create_file_from_pathname($filerecord, $pathname) {
        global $DB;

        $filerecord = (array)$filerecord;  // Do not modify the submitted record, this cast unlinks objects.
        $filerecord = (object)$filerecord; // We support arrays too.

        // validate all parameters, we do not want any rubbish stored in database, right?
        if (!is_number($filerecord->contextid) or $filerecord->contextid < 1) {
            throw new file_exception('storedfileproblem', 'Invalid contextid');
        }

        $filerecord->component = clean_param($filerecord->component, PARAM_COMPONENT);
        if (empty($filerecord->component)) {
            throw new file_exception('storedfileproblem', 'Invalid component');
        }

        $filerecord->filearea = clean_param($filerecord->filearea, PARAM_AREA);
        if (empty($filerecord->filearea)) {
            throw new file_exception('storedfileproblem', 'Invalid filearea');
        }

        if (!is_number($filerecord->itemid) or $filerecord->itemid < 0) {
            throw new file_exception('storedfileproblem', 'Invalid itemid');
        }

        if (!empty($filerecord->sortorder)) {
            if (!is_number($filerecord->sortorder) or $filerecord->sortorder < 0) {
                $filerecord->sortorder = 0;
            }
        } else {
            $filerecord->sortorder = 0;
        }

        $filerecord->filepath = clean_param($filerecord->filepath, PARAM_PATH);
        if (strpos($filerecord->filepath, '/') !== 0 or strrpos($filerecord->filepath, '/') !== strlen($filerecord->filepath)-1) {
            // path must start and end with '/'
            throw new file_exception('storedfileproblem', 'Invalid file path');
        }

        $filerecord->filename = clean_param($filerecord->filename, PARAM_FILE);
        if ($filerecord->filename === '') {
            // filename must not be empty
            throw new file_exception('storedfileproblem', 'Invalid file name');
        }

        $now = time();
        if (isset($filerecord->timecreated)) {
            if (!is_number($filerecord->timecreated)) {
                throw new file_exception('storedfileproblem', 'Invalid file timecreated');
            }
            if ($filerecord->timecreated < 0) {
                //NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
                $filerecord->timecreated = 0;
            }
        } else {
            $filerecord->timecreated = $now;
        }

        if (isset($filerecord->timemodified)) {
            if (!is_number($filerecord->timemodified)) {
                throw new file_exception('storedfileproblem', 'Invalid file timemodified');
            }
            if ($filerecord->timemodified < 0) {
                //NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
                $filerecord->timemodified = 0;
            }
        } else {
            $filerecord->timemodified = $now;
        }

        $newrecord = new stdClass();

        $newrecord->contextid = $filerecord->contextid;
        $newrecord->component = $filerecord->component;
        $newrecord->filearea  = $filerecord->filearea;
        $newrecord->itemid    = $filerecord->itemid;
        $newrecord->filepath  = $filerecord->filepath;
        $newrecord->filename  = $filerecord->filename;

        $newrecord->timecreated  = $filerecord->timecreated;
        $newrecord->timemodified = $filerecord->timemodified;
        $newrecord->mimetype     = empty($filerecord->mimetype) ? $this->mimetype($pathname, $filerecord->filename) : $filerecord->mimetype;
        $newrecord->userid       = empty($filerecord->userid) ? null : $filerecord->userid;
        $newrecord->source       = empty($filerecord->source) ? null : $filerecord->source;
        $newrecord->author       = empty($filerecord->author) ? null : $filerecord->author;
        $newrecord->license      = empty($filerecord->license) ? null : $filerecord->license;
        $newrecord->status       = empty($filerecord->status) ? 0 : $filerecord->status;
        $newrecord->sortorder    = $filerecord->sortorder;

        list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_file_to_pool($pathname, null, $newrecord);

        $newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);

        try {
            $this->create_file($newrecord);
        } catch (dml_exception $e) {
            if ($newfile) {
                $this->filesystem->remove_file($newrecord->contenthash);
            }
            throw new stored_file_creation_exception($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid,
                                                    $newrecord->filepath, $newrecord->filename, $e->debuginfo);
        }

        $this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);

        return $this->get_file_instance($newrecord);
    }
716178
public function create($fileUri, $agendaId, $filename, $type = Document::DOCTYPE_PURCHASE, $fileSplit = false, $lacyLoad = false): Document
    {
        $file = new FileInfo($fileUri);
        $mimeType = $file->getMimeType();

        $documentFile = new DocumentFile();
        $documentFile->setType($type)
            ->setAgendaId($agendaId)
            ->setFileSplit($fileSplit)
            ->setFile(
                new UploadFile($file->getFilename(), $mimeType, file_get_contents($file->getPathname()))
            )
        ;

        return current($this->send([$documentFile], $lacyLoad));
    }
106383
public function getFileResource($fileName)
    {
        $resource = fopen('php://temp', 'r+');
        $entry = $this->sevenZip->getEntry($fileName);

        fwrite($resource, $entry->getContent());
        rewind($resource);
        return $resource;
    }
1148772
protected function createFullFilePath($fileName)
    {
        $tempPath = $this->documentConfig->getTempPath();

        if (!is_dir($tempPath)) {
            mkdir($tempPath, 777, true);
        }

        return sprintf('%s/%s', $tempPath, $fileName);
    }
990208
private function createDocument($file)
    {
        $d = new Document();
        $d->uniqueName = $this->getUniqueName();
        $d->originalName = $file->getClientOriginalName();
        $d->extension = strtolower($file->getClientOriginalExtension());
        $d->mimeType = $file->getClientMimeType();
        $d->filePath = sprintf('%s/%s.%s', $this->subfolder, $d->uniqueName, $d->extension);
        $d->storage_disk = Config::get('filesystems.default');
        $d->hash = md5_file($file->getRealPath());
        $d->realPath = $file->getRealPath();

        return $d;
    }
1318821
public function fromString($fileName)
    {
        $fileNameArray = $fileName ? explode('.', $fileName) : array();
        if(!$fileNameArray || count($fileNameArray) < 2){
            throw new Exception\InvalidArgumentException('File name not correct');
        }

        $fileExt = array_pop($fileNameArray);
        $fileNameMain = implode('.', $fileNameArray);
        $fileNameArray = explode(',', $fileNameMain);
        if(!$fileExt || !$fileNameArray || !$fileNameArray[0]){
            throw new Exception\InvalidArgumentException('File name not correct');
        }

        //remove empty elements
        $fileNameArray = array_filter($fileNameArray);
        $fileNameMain = array_shift($fileNameArray);
        $this->setExtension($fileExt);
        $this->setFilename($fileNameMain);

        $args = $fileNameArray;
        $argMapping = $this->argMapping;
        $params = array();
        foreach($args as $arg){
            if(!$arg){
                continue;
            }
            if(strlen($arg) < 3 || strpos($arg, '_') !== 1){
                continue;
            }
            $argKey = $arg{0};
            if(isset($argMapping[$argKey])){
                $arg = substr($arg, 2);
                if($arg !== ''){
                    $params[$argMapping[$argKey]] = $arg;
                }
            }
        }

        $this->fromArray($params);
        return $params;
    }
653761
public function fromFile($fileName)
	{
		// 清空数据
		$this->clear();
		$this->fileName = $fileName;
		$this->parseFileToData($fileName);
	}
146162
public static function make(string $fileName, array $values = null)
    {
        $valuestore = (new static())->setFileName($fileName);

        if (! is_null($values)) {
            $valuestore->put($values);
        }

        return $valuestore;
    }
486418
public static function fromFilename($filename)
    {
        $contents = file_get_contents($filename);
        $jsonData = json_decode($contents, true);
        $instance = new self($jsonData);
        return $instance;
    }
433803
public static function fromFile(string $filename): PhpTrait {
		$trait = new PhpTrait();
		$parser = new FileParser($filename);
		$parser->addVisitor(new TraitParserVisitor($trait));
		$parser->addVisitor(new MethodParserVisitor($trait));
		$parser->addVisitor(new ConstantParserVisitor($trait));
		$parser->addVisitor(new PropertyParserVisitor($trait));
		$parser->parse();

		return $trait;
	}
537292
public function createDocumentCollection($documentName)
    {
        $class = $this->dm->getClassMetadata($documentName);

        if ($class->isMappedSuperclass || $class->isEmbeddedDocument) {
            throw new \InvalidArgumentException('Cannot create document collection for mapped super classes or embedded documents.');
        }

        if ($class->isFile()) {
            $this->dm->getDocumentDatabase($documentName)->createCollection($class->getCollection() . '.files');
            $this->dm->getDocumentDatabase($documentName)->createCollection($class->getCollection() . '.chunks');

            return;
        }

        $this->dm->getDocumentDatabase($documentName)->createCollection(
            $class->getCollection(),
            $class->getCollectionCapped(),
            $class->getCollectionSize(),
            $class->getCollectionMax()
        );
    }
478500
public static function fromFile($filename)
	{
		$filename = realpath($filename);
		if ($filename === false)
			throw new ClientConfigurationException('Configuration file ' . $filename . ' does not exists');

		return static::fromArray(include $filename);
	}
887967
public function createPath($filename)
    {
        $dir = Config::get('js-localization.storage_path');
        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }

        return $dir . $filename;
    }