@param string $content   Empty string by default
@param bool   $overwrite Overwrite by default

@return string
513564
protected function writeContent($content = '', $overwrite = true)
    {
        $this->filesystem->write($this->key, $content, $overwrite);

        return $content;
    }
996898
public function write($content)
    {

        $bytes =  $this->stream()->write($content);
        $this->didWrite = true;
        return $bytes;
    }
1205005
protected function _replaceCdata($content) {
		foreach ($this->_cdata as $n => $data) {
			$data = '<![CDATA[' . $data . ']]>';
			$content = str_replace('###CDATA-' . $n . '###', $data, $content);
		}
		return $content;
	}
717569
function OverWrite($file_in, $search, $replacement, $dest = Destination::DOWNLOAD, $file_out = "mpdf")
	{
		$pdf = file_get_contents($file_in);

		if (!is_array($search)) {
			$x = $search;
			$search = [$x];
		}
		if (!is_array($replacement)) {
			$x = $replacement;
			$replacement = [$x]; // mPDF 5.7.4
		}

		if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
			foreach ($search as $k => $val) {
				$search[$k] = $this->writer->utf8ToUtf16BigEndian($search[$k], false);
				$search[$k] = $this->writer->escape($search[$k]);
				$replacement[$k] = $this->writer->utf8ToUtf16BigEndian($replacement[$k], false);
				$replacement[$k] = $this->writer->escape($replacement[$k]);
			}
		} else {
			foreach ($replacement as $k => $val) {
				$replacement[$k] = mb_convert_encoding($replacement[$k], $this->mb_enc, 'utf-8');
				$replacement[$k] = $this->writer->escape($replacement[$k]);
			}
		}

		// Get xref into array
		$xref = [];
		preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s", $pdf, $m);
		$xref_objid = $m[1];
		preg_match_all('/(\d{10}) (\d{5}) (f|n)/', $m[2], $x);
		for ($i = 0; $i < count($x[0]); $i++) {
			$xref[] = [intval($x[1][$i]), $x[2][$i], $x[3][$i]];
		}

		$changes = [];
		preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s", $pdf, $m);
		preg_match_all("/(\d+) 0 R /s", $m[1], $o);
		$objlist = $o[1];

		foreach ($objlist as $obj) {
			if ($this->compress) {
				preg_match("/" . ($obj + 1) . " 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s", $pdf, $m);
			} else {
				preg_match("/" . ($obj + 1) . " 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s", $pdf, $m);
			}

			$s = $m[2];
			if (!$s) {
				continue;
			}

			$oldlen = $m[1];

			if ($this->encrypted) {
				$s = $this->protection->rc4($this->protection->objectKey($obj + 1), $s);
			}

			if ($this->compress) {
				$s = gzuncompress($s);
			}

			foreach ($search as $k => $val) {
				$s = str_replace($search[$k], $replacement[$k], $s);
			}

			if ($this->compress) {
				$s = gzcompress($s);
			}

			if ($this->encrypted) {
				$s = $this->protection->rc4($this->protection->objectKey($obj + 1), $s);
			}

			$newlen = strlen($s);

			$changes[($xref[$obj + 1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen));

			if ($this->compress) {
				$newstr = ($obj + 1) . " 0 obj\n<</Filter /FlateDecode /Length " . $newlen . ">>\nstream\n" . $s . "\nendstream\n";
			} else {
				$newstr = ($obj + 1) . " 0 obj\n<</Length " . $newlen . ">>\nstream\n" . $s . "\nendstream\n";
			}

			$pdf = str_replace($m[0], $newstr, $pdf);
		}

		// Update xref in PDF
		krsort($changes);
		$newxref = "xref\n0 " . $xref_objid . "\n";
		foreach ($xref as $v) {
			foreach ($changes as $ck => $cv) {
				if ($v[0] > $ck) {
					$v[0] += $cv;
				}
			}
			$newxref .= sprintf('%010d', $v[0]) . ' ' . $v[1] . ' ' . $v[2] . " \n";
		}
		$newxref .= "trailer";
		$pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s", $newxref, $pdf);

		// Update startxref in PDF
		preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
		$startxref = $m[1];
		$startxref += array_sum($changes);
		$pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s", "startxref\n" . $startxref . "\n%%EOF", $pdf);

		// OUTPUT
		switch ($dest) {
			case Destination::INLINE:
				if (isset($_SERVER['SERVER_NAME'])) {
					// We send to a browser
					header('Content-Type: application/pdf');
					header('Content-Length: ' . strlen($pdf));
					header('Content-disposition: inline; filename=' . $file_out);
				}

				echo $pdf;

				break;

			case Destination::FILE:
				if (!$file_out) {
					$file_out = 'mpdf.pdf';
				}

				$f = fopen($file_out, 'wb');

				if (!$f) {
					throw new \Mpdf\MpdfException('Unable to create output file: ' . $file_out);
				}

				fwrite($f, $pdf, strlen($pdf));

				fclose($f);

				break;

			case Destination::STRING_RETURN:
				return $pdf;

			case Destination::DOWNLOAD: // Download file
			default:
				if (isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
					header('Content-Type: application/force-download');
				} else {
					header('Content-Type: application/octet-stream');
				}

				header('Content-Length: ' . strlen($pdf));
				header('Content-disposition: attachment; filename=' . $file_out);

				echo $pdf;

				break;
		}
	}
1359930
protected function overwriteGitattributesFile($content)
    {
        $bytesWritten = file_put_contents(
            $this->analyser->getGitattributesFilePath(),
            $content
        );

        if ($bytesWritten) {
            $content = 'Overwrote it with the shown content:'
                . PHP_EOL . '<info>' . $content . '</info>';

            return PHP_EOL . PHP_EOL . $content;
        }

        $message = 'Overwrite of .gitattributes file failed.';
        throw new GitattributesCreationFailed($message);
    }
223188
public function name($value = false, $overwrite = false)
    {
        if ($value === false) {
            return $this->adapter->basename($this->path);
        }

        if (! is_string($value) || strlen($value) == 0) {
            throw new FilesystemException('Invalid name given to name() method');
        }

        $newPath = substr($this->path, 0, strrpos($this->path, DIRECTORY_SEPARATOR) + 1);
        $newPath .= $value;

        return $this->path($newPath, $overwrite);
    }
169030
public function fill($content)
    {
        if ($this->hasInstructions($content)) {
            $instructions = $this->getInstructions();
            foreach ($instructions as $instruction) {
                $content = $this->parseInstructions($content, $instruction);
            }
        }
        return $this->fillContent($content);
    }
106013
private static void safeOverwrite(Blob origBlob, InputStream content) {
        BlobStoreConnection connection = origBlob.getConnection();
        String origId = origBlob.getId().toString();

        // write new content to origId/new
        Blob newBlob = null;
        try {
            newBlob = connection.getBlob(new URI(origId + "/new"), null);
            copy(content, newBlob.openOutputStream(-1, false));
        } catch (Throwable th) {
            // any error or exception here is an unrecoverable fault
            throw new FaultException(th);
        }

        // At this point, we have origId (with old content) and origId/new

        // rename origId to origId/old
        Blob oldBlob = null;
        try {
            oldBlob = rename(origBlob, origId + "/old");
        } finally {
            if (oldBlob == null) {
                // rename failed; attempt recovery before throwing the fault
                try {
                    delete(newBlob);
                } catch (Throwable th) {
                    logger.error("Failed to delete " + newBlob.getId() + " while"
                              + " recovering from rename failure during safe"
                              + " overwrite", th);
                }
            }
        }

        // At this point, we have origId/old and origId/new

        // rename origId/new to origId
        boolean successful = false;
        try {
            rename(newBlob, origId);
            successful = true;
        } finally {
            if (!successful) {
                // rename failed; attempt recovery before throwing the fault
                try {
                    rename(oldBlob, origId);
                } catch (Throwable th) {
                    logger.error("Failed to rename " + oldBlob.getId() + " to "
                              + origId + " while recovering from rename"
                              + " failure during safe overwrite", th);
                }
                try {
                    newBlob.delete();
                } catch (Throwable th) {
                    logger.error("Failed to delete " + newBlob.getId()
                              + " while recovering from rename"
                              + " failure during safe overwrite", th);
                }
            }
        }

        // At this point, we have origId (with new content) and origId/old

        // remove origId/old; we don't need it anymore
        try {
            delete(oldBlob);
        } catch (Throwable th) {
            logger.error("Failed to delete " + oldBlob.getId()
                    + " while cleaning up after committed"
                    + " safe overwrite", th);
        }
    }
447551
protected function _defaultData($content)
    {
        $content = @unserialize($content);
        if (empty($content) || !is_a($content, \stdClass::class)) {
            $content = new \stdClass;
        }
        $content->file = empty($content->file) ? '' : $content->file;
        $content->title = empty($content->title) ? '' : $content->title;
        return $content;
    }
401504
public function assign(string $key, $value, bool $overwrite = false)
  {
    $file = $this->file;

    if (file_exists($file)) {
      $data = unserialize($this->decrypt(file_get_contents($file)));

      if (is_array($data)) {
        if (isset($data[$key])) {
          if ($overwrite == true) {
            $data[$key] = $value;
            $data = $this->encrypt(serialize($data));
            return file_put_contents($file, $data);
          }
          return false;
        } else {
          $data[$key] = $value;
          $data = $this->encrypt(serialize($data));
          return file_put_contents($file, $data);
        }
      }
    }

    $data = $this->encrypt(serialize([$key => $value]));

    file_put_contents($file, $data);

    return false;
  }
637109
static function copyDirectoryContents($dir, $target, $overwrite = true, $base = '')
	{
		$dir = rtrim($dir, "\\/ ").'/';
		$target = rtrim($target, "\\/ ").'/';
		$report = ['error'=>[],'copied'=>[]];

		if (!static::checkAndOrCreateDir($target, true, 0777)) {
			$report['error']['permission'] = $taget;
			return $report;
		}

		foreach (scandir($dir) as $file) {
			if ($file == '.' || $file == '..') {
				continue;
			}

			if (is_dir($dir.$file)) {
				if (!static::checkAndOrCreateDir($target.$file, true, 0777)) {
					$report['error']['permission'] = $taget.$file;
					return $report;
				} else {
					$copy = static::copyDirectoryContents($dir.$file, $target.$file, $overwrite, $base);
					$report = array_merge_recursive($report, $copy);
				}
			} elseif (is_file($dir.$file)) {
				if ($overwrite === false && file_exists($target.$file)) {
					$report['error']['overwrite'][] = str_replace($base.'/', '', $target.$file);
					continue;
				}
				if (!copy($dir.$file, $target.$file)) {
					$report['error']['permission'] = $target.$file;
					return $report;
				} else {
					$report['copied'][] = str_replace($base.'/', '', $target.$file);
				}
			}
		}
		return $report;
	}
242226
protected function addSection($section, $contents, $overwrite = false)
    {
        if ($overwrite || !isset($this->sections[$section])) {
            $this->sections[$section] = $contents;
        }

        return $this;
    }
18522
public function writeString(
        string $content,
        string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING,
        ?ErrorCorrectionLevel $ecLevel = null
    ) : string {
        if (strlen($content) === 0) {
            throw new InvalidArgumentException('Found empty contents');
        }

        if (null === $ecLevel) {
            $ecLevel = ErrorCorrectionLevel::L();
        }

        return $this->renderer->render(Encoder::encode($content, $ecLevel, $encoding));
    }
296752
public function load(string $configPath, $overwrite = false): void
    {
        if (!file_exists($configPath)) {
            return;
        }
        $config = include $configPath;
        if (!is_array($config) && !is_object($config)) {
            return;
        }
        if (is_object($config)) {
            $config = get_object_vars($config);
        }
        $this->loadArray($config, $overwrite);
    }
518977
public function addElement( $tag, $element, $overwrite = FALSE )
	{
		$this->add( array( $tag => $element ), $overwrite );
	}
938701
private function loadFromFile($filename, $overwrite = false)
    {
        try {
            $yamlDatas = Yaml::parse(file_get_contents($filename));

            if (is_array($yamlDatas)) {
                if (true === $this->debug) {
                    $this->debug_data[$filename] = $yamlDatas;
                }

                if (self::CONFIG_FILE.'.'.self::EXTENSION === basename($filename) ||
                    self::CONFIG_FILE.'.'.$this->environment.'.'.self::EXTENSION === basename($filename)) {
                    foreach ($yamlDatas as $component => $config) {
                        if (!is_array($config)) {
                            $this->container->get('logger')->error('Bad configuration, array expected, given : '.$config);
                        }
                        $this->setSection($component, $config, $overwrite);
                    }
                } else {
                    $this->setSection(basename($filename, '.'.self::EXTENSION), $yamlDatas, $overwrite);
                }
            }
        } catch (ParseException $e) {
            throw new InvalidConfigException($e->getMessage(), null, $e, $e->getParsedFile(), $e->getParsedLine());
        }
    }
706842
public function load($overwrite = false, $cache = true)
	{
		$paths = $this->find_file($cache);
		$config = array();

		foreach ($paths as $path)
		{
			$config = $overwrite ?
				array_merge($config, $this->load_file($path)) :
				\Arr::merge($config, $this->load_file($path));
		}

		return $config;
	}