class FileProcessOutputCallback

Logs process output to a file.

@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.

Hierarchy

Expanded class hierarchy of FileProcessOutputCallback

3 files declare their use of FileProcessOutputCallback
LoggingBeginnerTest.php in core/modules/package_manager/tests/src/Unit/LoggingBeginnerTest.php
LoggingCommitterTest.php in core/modules/package_manager/tests/src/Unit/LoggingCommitterTest.php
LoggingStagerTest.php in core/modules/package_manager/tests/src/Unit/LoggingStagerTest.php

File

core/modules/package_manager/src/FileProcessOutputCallback.php, line 18

Namespace

Drupal\package_manager
View source
final class FileProcessOutputCallback implements OutputCallbackInterface {
    
    /**
     * The file to write to.
     *
     * @var resource
     */
    private readonly mixed $handle;
    public function __construct(string $path, ?OutputCallbackInterface $decorated = NULL) {
        $this->handle = fopen($path, 'a');
        if (empty($this->handle)) {
            throw new \RuntimeException("Could not open or create '{$path}' for writing.");
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function clearErrorOutput() : void {
        $this->decorated?->clearErrorOutput();
    }
    
    /**
     * {@inheritdoc}
     */
    public function clearOutput() : void {
        $this->decorated?->clearOutput();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getErrorOutput() : array {
        return $this->decorated?->getErrorOutput() ?? [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOutput() : array {
        return $this->decorated?->getOutput() ?? [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function __invoke(OutputTypeEnum $type, string $buffer) : void {
        fwrite($this->handle, $buffer);
        if ($this->decorated) {
            ($this->decorated)($type, $buffer);
        }
    }

}

Members


Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.