HEX
Server: LiteSpeed
System: Linux server44.twelveinks.com 5.14.0-570.12.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 13 06:11:55 EDT 2025 x86_64
User: moda (1338)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /python/moda/public_html/tech/old/vendor/league/climate/src/Util/Writer/File.php
<?php

namespace League\CLImate\Util\Writer;

use League\CLImate\Exceptions\RuntimeException;

class File implements WriterInterface
{
    /** @var resource|string */
    protected $resource;

    /** @var boolean $close_locally */
    protected $close_locally = false;

    /** @var boolean $use_locking */
    protected $use_locking = false;

    /** @var boolean $gzip_file */
    protected $gzip_file = false;

    /**
     * @param string|resource $resource
     * @param bool $use_locking
     * @param bool $gzip_file
     */
    public function __construct($resource, $use_locking = false, $gzip_file = false)
    {
        $this->resource    = $resource;
        $this->use_locking = $use_locking;
        $this->gzip_file   = $gzip_file;
    }

    public function lock()
    {
        $this->use_locking = true;

        return $this;
    }

    public function gzipped()
    {
        $this->gzip_file = true;

        return $this;
    }

    /**
     * Write the content to the stream
     *
     * @param  string $content
     */
    public function write($content)
    {
        $resource = $this->getResource();

        if ($this->use_locking) {
            flock($resource, LOCK_EX);
        }

        gzwrite($resource, $content);

        if ($this->use_locking) {
            flock($resource, LOCK_UN);
        }
    }

    protected function getResource()
    {
        if (is_resource($this->resource)) {
            return $this->resource;
        }

        $this->close_locally = true;

        if (!is_writable($this->resource)) {
            throw new RuntimeException("The resource [{$this->resource}] is not writable");
        }

        if (!($this->resource = $this->openResource())) {
            throw new RuntimeException("The resource could not be opened");
        }

        return $this->resource;
    }

    protected function openResource()
    {
        if ($this->gzip_file) {
            return gzopen($this->resource, 'a');
        }

        return fopen($this->resource, 'a');
    }

    public function _destruct()
    {
        if ($this->close_locally) {
            gzclose($this->getResource());
        }
    }
}