Save dom as string

@param string $filepath

@return string
334766
public function save($filepath = '')
    {
        $string = $this->innerHtml();
        if ($filepath !== '') {
            file_put_contents($filepath, $string, LOCK_EX);
        }

        return $string;
    }
659337
public function loadFile($filePath)
    {
        if ($filePath instanceof \SplFileInfo) {
            $filePath = $filePath->getRealPath();
        }

        if (is_file($filePath)) {
            return $this->loadString(file_get_contents($filePath));
        }

        return false;
    }
266572
public static function getFileName($filePath) {
        $lastIndex = strripos($filePath, DIRECTORY_SEPARATOR);
        $fileName = substr($filePath, $lastIndex + 1);
        return substr($fileName, 0, strripos($fileName, "."));
    }
487380
public function saveToFile($filePath,$format = 'csvforexcel')
    {
        $this->format(Format::get($format));
        $this->run();

        $this->data->saveToFile($filePath);

        return true;
    }
432612
public function writeFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        $sections = (empty($options)
            ? true
            : $options[ 'sections' ]);

        $content = null;

        if ($sections) {
            foreach ($this->getArrayCopy() as $section => $data) {
                if (is_array($data)) {
                    $content .= '[' . $section . ']' . PHP_EOL;

                    foreach ($data as $key => $value) {
                        if (is_array($value)) {
                            foreach ($value as $valueChild) {
                                $content .= $key . '[] = ' . (is_numeric($valueChild)
                                        ? $valueChild
                                        : '"' . $valueChild . '"') . PHP_EOL;
                            }
                        } elseif (strpos($key, ';') !== false) {
                            $content .= '; ' . trim(ucfirst($key), ';') . ' ' . $value . PHP_EOL;
                        } elseif (empty($value)) {
                            $content .= $key . ' = ' . PHP_EOL;
                        } else {
                            $content .= $key . ' = ' . (is_numeric($value)
                                    ? $value
                                    : '"' . $value . '"') . PHP_EOL;
                        }
                    }

                    $content .= PHP_EOL;
                } elseif (strpos($section, ';') !== false) {
                    $content .= '; ' . trim(ucfirst($section), ';') . ' ' . $data . PHP_EOL;
                } elseif (empty($data)) {
                    $content .= $section . ' = ' . PHP_EOL;
                } else {
                    $content .= $section . ' = ' . (is_numeric($data)
                            ? $data
                            : '"' . $data . '"') . PHP_EOL;
                }
            }
        } else {
            foreach ($this->getArrayCopy() as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $valueChild) {
                        $content .= $key . '[] = ' . (is_numeric($valueChild)
                                ? $valueChild
                                : '"' . $valueChild . '"') . PHP_EOL;
                    }
                } elseif (strpos($key, ';') !== false) {
                    $content .= '; ' . trim(ucfirst($key), ';') . ' ' . $value . PHP_EOL;
                } elseif (empty($value)) {
                    $content .= $key . ' = ' . PHP_EOL;
                } else {
                    $content .= $key . ' = ' . (is_numeric($value)
                            ? $value
                            : '"' . $value . '"') . PHP_EOL;
                }
            }
        }

        return (new File())->write($filePath, $content);
    }
320815
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $rarArchive = RarArchive::open($filePath);
        $rarEntries = $rarArchive->getEntries();

        /**
         * @var RarEntry $rarEntiry
         */
        foreach ($rarEntries as $rarEntry) {

            $rarEntry->extract($directory);
        }

        return $this->createFinderFromDirectory($directory);
    }
457358
public function getRootApplicationDirectoryPathByFilePath(string $filePath): string
    {
        if ($this->isApplicationRootDefined()) {
            return ${static::CONST_NAME_APPLICATION_ROOT_DIR};
        }

        $vendorPosition = strpos($filePath, 'vendor');

        if ($vendorPosition !== false) {
            return substr($filePath, 0, $vendorPosition);
        }

        $sourcePosition = strpos($filePath, 'src');

        return substr($filePath, 0, $sourcePosition);
    }
865786
protected function createWritableStream ($filePath)
    {
        if (is_resource($filePath)) {
            $stream = $filePath;
        } elseif (is_string($filePath)) {
            $stream = fopen($filePath, 'wb');
            if (! $stream) {
                throw new InvalidArgumentException("Can't open file `{$filePath}` for writing.");
            }
        } else {
            $stream = tmpfile();
        }

        return $stream;
    }
1205810
public static function getXmlContentFromFile ($filePath)
    {
        // Detect media type
        $finfo         = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $fileMediaType = finfo_file($finfo, $filePath);
        finfo_close($finfo);

        // Act upon detected media type
        switch ($fileMediaType) {
            case 'application/xml':
                $fileContent = file_get_contents($filePath);
                break;
            case 'application/x-gzip':
                $fileContent = self::gunzip($filePath);
                break;
            case 'application/zip':
                $fileContent = self::unzip($filePath);
                break;
            default:
                throw new Exception("Unsupported file media type: $fileMediaType");
        }

        return $fileContent;
    }
600253
public function embed(string $filePath): string
    {
        $id = $this->getAttachmentId($filePath);
        $this->embeddedAttachments[$id] = $filePath;

        return $id;
    }
114064
private static function parseFile($filePath = '')
    {
        $supportFileType = array();
        $supportFileType = array_merge($supportFileType, self::supportFilePHP());
        $supportFileType = array_merge($supportFileType, self::supportFileYAML());
        foreach ($supportFileType as $value) {
            $file = sprintf('%s.%s', $filePath, $value);
            if (is_file($file)) {
                if (in_array($value, self::supportFilePHP())) {
                    return require($file);
                }
                if (in_array($value, self::supportFileYAML())) {
                    return Yaml::parse(file_get_contents($file));
                }
            }
        }
        return null;
    }
39418
public function readFile($filePath)
    {
        try {
            $file = fopen($filePath, 'r');
            $content = fread($file, filesize($filePath));
            fclose($file);
            return $content;
        } catch (\Exception $e) {
            return '';
        }
    }
707948
public function saveToFile($filePath)
    {
        $handle = @fopen($filePath, 'w');
        if (false === $handle) {
            throw new Exception('Cannot open file "' . $filePath . '" for writing.');
        }

        $bytesWritten = @fwrite($handle, (string)$this);
        if (false === $bytesWritten) {
            fclose($handle);
            throw new Exception('Cannot write into file "' . $filePath . '".');
        }

        $closed = @fclose($handle);
        if (false === $closed) {
            throw new Exception('Cannot close file handle for "' . $filePath . '".');
        }
    }
338654
public function getFilePath($filePath)
    {
        $composerFiles = [];
        foreach ($this->alias as $name => $path) {
            $composerFiles[] = $path . '/' . $filePath;
        }

        return FileHelper::getFirstExistingFileArray($composerFiles);
    }
287865
public static function findDomainPath($string, $filePath)
    {
        $domains = Template::getDomains(TRUE);
        $filenamePath = null;
        if (!file_exists($filePath) && 0 < count($domains)) {
            foreach ($domains as $domain => $paths) {
                $domainFilename = str_replace($domain, $paths["public"], $string);
                if (file_exists($domainFilename)) {
                    $filenamePath = $domainFilename;
                    continue;
                }
            }
        }

        return $filenamePath;
    }
724460
public function save( $filePath ){
		$data	= array();
		foreach( $this->index() as $route ){
			$data[]	= array(
				'controller'	=> $route->getController(),
				'action'		=> $route->getAction(),
				'pattern'		=> $route->getPattern(),
				'method'		=> $route->getMethod(),
			);
		}
		return \FS_File_JSON_Writer::save( $filePath, $data, TRUE );
	}
486504
private function saveRemoteFile($fileUrl, $filePath)
    {
        if (! $file = @file_get_contents($fileUrl)) {
            self::$errors[] = [
                'message' => 'Error to download file: ' . $fileUrl
            ];

            return false;
        }

        if (! @file_put_contents($filePath, $file)) {
            self::$errors[] = [
                'message' => 'Failed to save file to: ' . $filePath
            ];

            return false;
        }

        return true;
    }