Adds or updates a generic file if neccessary.
@param string $file_name Original name of header.
@param string $content
@param string $subdir
179199
public function AddGenericFile($file_name, &$content, $subdir="")
    {
        if($subdir)
        {
            $subdir = trim($subdir, "\\/") . "/";
            
            if(!file_exists($this->output_path . $subdir))
                \Peg\Lib\Utilities\FileSystem::MakeDir(
                    $this->output_path . $subdir, 
                    0755, 
                    true
                );
        }
        
        $output_file = $this->output_path 
            . $subdir
            . $file_name
        ;
        
        \Peg\Lib\Utilities\FileSystem::WriteFileIfDifferent(
            $output_file, 
            $content
        );
    }
1141216
public function put($file, $content)
    {
        $file = $this->path($file);

        $dirname = dirname($file);

        $this->makeDirectory($dirname);

        return file_put_contents($file, $content);
    }
816556
public function writeFile(
        string $content,
        string $filename,
        string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING,
        ?ErrorCorrectionLevel $ecLevel = null
    ) : void {
        file_put_contents($filename, $this->writeString($content, $encoding, $ecLevel));
    }
1058215
public function putContents($file_name, $data, $mode = FTP_ASCII)
    {
        if (!is_resource($this->resource)) {
            throw new FtpException("Not connected to FTP server. Call connect() or ssl_connect() first.");
        }
        $temp = tmpfile();
        fwrite($temp, $data);
        fseek($temp, 0);
        return $this->fput($file_name, $temp, $mode);
    }
211037
public function addFile($file, $name = 'attachment', $mime = Mime::TXT) {
        $this->_fileTransfert = 'multipart/mixed';
        $this->_hasAttachment = true;

        if (file_exists($file)) {
            $data = file_get_contents($file);

            if ($name == self::ATTACHMENT) {
                $name = $name . uniqid();
            }

            if (isset($this->_attachments[$name])) {
                $name = $name . uniqid();
            }

            $this->_attachments[$name] = [chunk_split(base64_encode($data), $mime)];
        }
    }
586039
public function loadFile($filename, $subDir = null)
    {
        if (is_file($filename)) {
            if (strpos($filename, 'font') !== false) {
                $this->fonts->append($filename);
            } else {
                $type = pathinfo($filename, PATHINFO_EXTENSION);

                switch ($type) {
                    case 'css':
                        $this->styles->append($filename);
                        break;

                    case 'js':
                        $this->javascripts->append($filename);
                        break;
                }
            }
        } elseif (isset($subDir)) {
            $type = pathinfo($filename, PATHINFO_EXTENSION);

            if (empty($type)) {
                $type = substr($subDir, 0, -1);
            }

            switch ($type) {
                case 'css':
                    if (input()->env('DEBUG_STAGE') === 'PRODUCTION') {
                        if (false !== ($filePath = $this->getFilePath($filename . '.min.css', $subDir))) {
                            $this->styles->append($filePath);
                        }
                    } else {
                        if (false !== ($filePath = $this->getFilePath($filename . '.css', $subDir))) {
                            $this->styles->append($filePath);
                        }
                    }
                    break;

                case 'fonts':
                    if (input()->env('DEBUG_STAGE') === 'PRODUCTION') {
                        if (false !== ($filePath = $this->getFilePath($filename . '.min.css', $subDir))) {
                            $this->fonts->append($filePath);
                        }
                    } else {
                        if (false !== ($filePath = $this->getFilePath($filename . '.css', $subDir))) {
                            $this->fonts->append($filePath);
                        }
                    }
                    break;

                case 'js':
                    if (input()->env('DEBUG_STAGE') === 'PRODUCTION') {
                        if (false !== ($filePath = $this->getFilePath($filename . '.min.js', $subDir))) {
                            $this->styles->append($filePath);
                        }
                    } else {
                        if (false !== ($filePath = $this->getFilePath($filename . '.js', $subDir))) {
                            $this->styles->append($filePath);
                        }
                    }
                    break;
            }
        } else {
            $type = pathinfo($filename, PATHINFO_EXTENSION);

            if (empty($type)) {
                if (input()->env('DEBUG_STAGE') === 'PRODUCTION') {
                    // Search Style or Font
                    if (false !== ($filePath = $this->getFilePath($filename . '.min.css'))) {
                        $this->styles->append($filePath);
                    } elseif (false !== ($filePath = $this->getFilePath($filename . '.min.css'))) {
                        $this->fonts->append($filePath);
                    }

                    // Search Javascript
                    if (false !== ($filePath = $this->getFilePath($filename . '.min.js'))) {
                        $this->javascripts->append($filePath);
                    }
                } else {
                    // Search Style or Font
                    if (false !== ($filePath = $this->getFilePath($filename . '.css'))) {
                        $this->styles->append($filePath);
                    } elseif (false !== ($filePath = $this->getFilePath($filename . '.css'))) {
                        $this->fonts->append($filePath);
                    }

                    // Search Javascript
                    if (false !== ($filePath = $this->getFilePath($filename . '.js'))) {
                        $this->javascripts->append($filePath);
                    }
                }
            } else {
                switch ($type) {
                    case 'css':
                        if (false !== ($filePath = $this->getFilePath($filename))) {
                            $this->styles->append($filePath);
                        }
                        break;

                    case 'js':
                        if (false !== ($filePath = $this->getFilePath($filename))) {
                            $this->javascripts->append($filePath);
                        }
                        break;
                }
            }
        }
    }
623027
public function put($local_file = null, $remote_file = null, $mode = FTP_ASCII)
    {
        if (\ftp_put($this->_stream, $remote_file, $local_file, $mode)) {
            return true;
        }

        $this->error = 'Failed to upload file "'.$local_file.'"';

        return false;
    }
250441
protected function write($content, $file)
    {
        if (file_exists($file)) { // Do not create a new file
            return file_put_contents($file, $content) !== false;
        }

        return false;
    }
394953
def add_file(name, content)
      full_path = File.join(@path, name)
      file      = MirrorFile.new(full_path)

      file.write(content)

      file
    end
344098
private static function isAction($type, $sub_type) {
    if ( ($type === 'content' && in_array($sub_type, array('create', 'create upload', 'update', 'update upload', 'upgrade', 'delete'))) ||
         ($type === 'library' && in_array($sub_type, array('create', 'update'))) ) {
      return TRUE; // Log actions
    }
    return FALSE;
  }
386718
protected function writeFile(string $filename, string $content): void
    {
        try {
            $f = \fopen($filename, 'w');
            \fwrite($f, $content, \mb_strlen($content));
            \fclose($f);
        } catch (\Throwable $e) {
            throw new WriterException($e->getMessage(), $e->getCode(), $e);
        }
    }
281653
protected void writeFile(String subdir, String filename, String content) throws IOException {
        Path dir = root;
        if (subdir != null) {
            dir = dir.resolve(subdir);

            // If the dir does not exist, we need to create it
            if (Files.notExists(dir)) {
                Files.createDirectory(dir);
            }
        }
        Files.write(dir.resolve(filename), content.getBytes(StandardCharsets.UTF_8));
    }
205873
public function AddHeader($header_name, &$content, $subdir="includes")
    {
        if($subdir)
        {
            $subdir = trim($subdir, "\\/") . "/";
            
            if(!file_exists($this->output_path . $subdir))
                \Peg\Lib\Utilities\FileSystem::MakeDir(
                    $this->output_path . $subdir, 
                    0755, 
                    true
                );
        }
        
        $header = $this->output_path 
            . $subdir
            . $this->GetHeaderNamePHP($header_name)
        ;
        
        \Peg\Lib\Utilities\FileSystem::WriteFileIfDifferent($header, $content);
    }
453745
public function loadStatementsFromCache($file_path, $file_modified_time, $file_content_hash)
    {
        $root_cache_directory = Config::getInstance()->getCacheDirectory();

        if (!$root_cache_directory) {
            return;
        }

        $file_cache_key = $this->getParserCacheKey(
            $file_path
        );

        $parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;

        $file_content_hashes = $this->new_file_content_hashes + $this->getExistingFileContentHashes();

        $cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;

        if (isset($file_content_hashes[$file_cache_key])
            && $file_content_hash === $file_content_hashes[$file_cache_key]
            && is_readable($cache_location)
            && filemtime($cache_location) > $file_modified_time
        ) {
            if ($this->use_igbinary) {
                /** @var array<int, \PhpParser\Node\Stmt> */
                $stmts = igbinary_unserialize((string)file_get_contents($cache_location));
            } else {
                /** @var array<int, \PhpParser\Node\Stmt> */
                $stmts = unserialize((string)file_get_contents($cache_location));
            }

            return $stmts;
        }
    }
492468
public void addFile(String filename) {
        synchronized (files) {
            if (!files.contains(filename)) {
                files.add(filename);
            }
        }
    }
635796
private function writeStubs(string $target_path, string $source_file): void
    {
        @mkdir(dirname($target_path), 0775, true);
        
        
        $this->updatePlaceholders([
            "/*<FILENAME>*/" => preg_replace("#\.php$#", "", basename($target_path)),
        ]);
        $content = $this->replacePlaceholdersInText(file_get_contents($source_file));
        
        
        //var_dump($content);
        file_put_contents($target_path, $content);
    }
1107694
private function addFromString($filename, $content)
    {
        $this->repository->addFromString($this->getInternalPath().$filename, $content);
    }