Write text to file

@param array $messages
@param string $file

@throws Exception
423654
protected function write($messages, $file)
    {
        $f = @fopen($file, 'a');
        if ($f === false)
        {
            throw new \Exception("Logfile $file is not writeable!");
        }

        foreach($messages as $msg)
        {
            fwrite($f, $msg);
        }

        fclose($f);
    }
598814
public static function write($file, array $content) {
        $jsonString = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

        if ($jsonString === false) {
            throw new Exception('Unable to convert array to JSON string', ExitApp::RUNTIME_ERROR);
        }

        $status = file_put_contents(
            $file,
            $jsonString . PHP_EOL
        );

        if ($status === false) {
            throw new Exception(sprintf(
                'Unable to write JSON-formatted content to file %s',
                $file
            ), ExitApp::RUNTIME_ERROR);
        }
    }
48968
private function writeAttributes( $file, $fields )
    {
        foreach ( $fields as $fieldName => $field )
        {
            fwrite( $file, "    /**\n" );
            fwrite( $file, "     * $fieldName\n" );
            fwrite( $file, "     *\n" );
            fwrite( $file, "     * @var {$this->translateType($field->type)}\n" );
            fwrite( $file, "     */\n" );
            fwrite( $file, "    private \$$fieldName;\n" );
        }
    }
201112
private function message( $message , $message_level )
	{
		if ( $message_level <= (int)$this->log_level )
		{
			if ( empty( $this->log_file_path ) )
			{
				error_log( $message );
			}
			else
			{
				if ( @file_put_contents( $this->log_file_path , $message . "\n" , FILE_APPEND ) === false )
				{
					$message = sprintf( "Unable to write to log file %s" , $this->log_file_path );

					error_log( self::getMessagePrefix( __CLASS__ , 'message' , 'fatal' ) . $message );

					throw new Exception( $message );
				}
			}

			return true;
		}

		return false;
	}
904673
private function writeMessage(string $level, string $message, string $tag, string $file, int $line, array $target_loggers)
    {
        if ( !$this->logger_config->isLogEnabled() ){
            return;
        }

        // determine log level filter
        $log_level_filter = 'E';
        foreach($this->logger_config->getLogLevelFilters() as $path => $lv)
        {
            if ($this->route_context === $path || strpos($this->route_context, $path) === 0){
                $log_level_filter = $lv;
            }
        }

        // do not output message when log level does not meet the filter level
        $cmp = self::compareLogLevel($level, $log_level_filter);
        if ( $cmp > 0 ){
            return;
        }

        // ignore different tags
        $log_tag_filters = $this->logger_config->getTagFilters();
        if ( is_array($log_tag_filters) && !empty($log_tag_filters) ){
            if ( !in_array( $tag, $log_tag_filters ) ){
                return;
            }
        }
    
        $msg = new LogMessage($level, $message, $tag, $file, $line);
    
        foreach( $target_loggers as $key )
        {
            if ( isset($this->loggers[$key]) && in_array($key,$target_loggers) )
            {
                $this->loggers[$key]->writeln($msg);
            }
        }
    }
914942
protected function writeToExceptionLogFile($message)
    {
        if (is_writable($this->exceptionLogFile) || is_writable(dirname($this->exceptionLogFile))) {
            $message = sprintf('[%s] %s' . PHP_EOL, (new \DateTime())->format(\DateTime::ISO8601), $message);
            @file_put_contents($this->exceptionLogFile, $message, FILE_APPEND);
        }
    }
1000445
public function writePoFile(string $file): void
    {
        $source = $this->dumpString();
        $testName = file_exists($file) ? $file : dirname($file);
        $status = is_writable($testName);
        if ($status === true) {
            $status = file_put_contents($file, $source);
        }
        if (false === $status) {
            throw new FileNotWritableException($file);
        }
    }
271757
private function execute(array  $files, $options, $errorMessage)
    {
        $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE);
        $this->output->write($outputMessage->getMessage());

        $errors = [];
        foreach ($files as $file) {
            $errors[] = $this->phpMdToolProcessor->process($file, $options);
        }

        $errors = array_filter($errors);

        if (!empty($errors)) {
            $outputText = $outputMessage->setError(implode('', $errors));
            $this->output->writeln($outputMessage->getFailMessage());
            $this->output->writeln($outputText);
            $this->output->writeln(BadJobLogoResponse::paint($errorMessage));
            throw new PhpMdViolationsException();
        }

        $this->output->writeln($outputMessage->getSuccessfulMessage());
    }
327339
public function overwrite($file, $content)
    {
        $written = file_put_contents($file, $content);

        // If $content is not empty
        // but nothing was written to $file
        // throw an exception.
        if ($content and ! $written)
        {
            throw new RuntimeException(
                "Unable to write to {$file}."
            );
        }
    }
817898
public function write($message)
    {
        if (!$this->logFile) {
            throw new \Parable\Log\Exception("No log file set. \Log\Writer\File requires a valid target file.");
        }
        $this->writeToFile($message);
        return $this;
    }
1256796
public static <MSG extends Message> void writeStream(Iterable<MSG> messages, File toFile, boolean append) {
    OutputStream out = null;
    try {
      out = new BufferedOutputStream(new FileOutputStream(toFile, append));
      writeStream(messages, out);
    } catch (Exception e) {
      throw ContextException.of("Unable to write messages", e).addContext("file", toFile);
    } finally {
      IOUtils.closeQuietly(out);
    }
  }
83507
public static void write(File file, String text) throws IOException {
        Writer writer = null;
        try {
            writer = new FileWriter(file);
            writer.write(text);
            writer.flush();

            Writer temp = writer;
            writer = null;
            temp.close();
        } finally {
            closeWithWarning(writer);
        }
    }
783710
public function sendMessage($level, $message)
    {
        if (is_resource($this->connect)) {
            fwrite($this->connect, '['.date('H:i:s d.m.Y').'] '.ucfirst($level).": {$message}\n");
        } else {
            throw new Exception('Error write log in file.');
        }
    }
881550
public function log($messages)
    {
        if (!is_array($messages)) {
            $messages = [$messages];
        }
        foreach ($messages as $message) {
            file_put_contents($this->logFile, date('d.m.Y H:i:s') . ' - ' . $message . PHP_EOL, FILE_APPEND | LOCK_EX);
        }
    }
1241857
public function write($configuration)
    {
        $ht = $this->getHTaccessFilename();
        $fs = $this->getFilesystem();
        if (@$fs->put($ht, $configuration) === false) {
            throw new Exception("Failed to write to file $ht");
        }
    }
689505
public function write($messages, $options = 0)
    {
        $this->log($messages);
        $this->output->write($messages, false, $options);
    }
590519
private function _writeLog($msg) {
        $log = "-------------------------------------\n";
        $log .= date('Y-m-d H:i:s') . ":\n";
        $log .= $msg."\n";
        $log .= "-------------------------------------\n";
        file_put_contents($this->_output, $log, FILE_APPEND | LOCK_EX);
    }