class FileOutput
Same name and namespace in other branches
- main core/tests/PHPStan/ErrorFormatter/FileOutput.php \Drupal\PHPStan\ErrorFormatter\FileOutput
Output implementation that writes to a file.
@phpstan-ignore phpstanApi.interface
Hierarchy
- class \Drupal\PHPStan\ErrorFormatter\FileOutput implements \PHPStan\Command\Output
Expanded class hierarchy of FileOutput
File
-
core/
tests/ PHPStan/ ErrorFormatter/ FileOutput.php, line 15
Namespace
Drupal\PHPStan\ErrorFormatterView source
final class FileOutput implements Output {
/**
* The file handle.
*
* @var resource
*/
private $handle;
/**
* Constructs a FileOutput.
*
* @param string $filePath
* The path to the output file.
* @param \PHPStan\Command\OutputStyle $outputStyle
* The output style.
*/
public function __construct(string $filePath, private OutputStyle $outputStyle) {
$directory = dirname($filePath);
if ($directory && $directory !== 'php:' && !is_dir($directory)) {
mkdir($directory, 0777, TRUE);
}
$handle = fopen($filePath, 'w');
if ($handle === FALSE) {
throw new \RuntimeException(sprintf('Unable to open file for writing: %s', $filePath));
}
$this->handle = $handle;
}
/**
* Ensures the file is closed on destruction.
*/
public function __destruct() {
fclose($this->handle);
}
/**
* {@inheritdoc}
*/
public function writeFormatted(string $message) : void {
fwrite($this->handle, $message);
}
/**
* {@inheritdoc}
*/
public function writeLineFormatted(string $message) : void {
fwrite($this->handle, $message . "\n");
}
/**
* {@inheritdoc}
*/
public function writeRaw(string $message) : void {
fwrite($this->handle, $message);
}
/**
* {@inheritdoc}
*/
public function getStyle() : OutputStyle {
return $this->outputStyle;
}
/**
* {@inheritdoc}
*/
public function isVerbose() : bool {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function isVeryVerbose() : bool {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function isDebug() : bool {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function isDecorated() : bool {
return FALSE;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| FileOutput::$handle | private | property | The file handle. |
| FileOutput::getStyle | public | function | |
| FileOutput::isDebug | public | function | |
| FileOutput::isDecorated | public | function | |
| FileOutput::isVerbose | public | function | |
| FileOutput::isVeryVerbose | public | function | |
| FileOutput::writeFormatted | public | function | |
| FileOutput::writeLineFormatted | public | function | |
| FileOutput::writeRaw | public | function | |
| FileOutput::__construct | public | function | Constructs a FileOutput. |
| FileOutput::__destruct | public | function | Ensures the file is closed on destruction. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.