-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in ability to save output report to a file. Particularly useful w…
…ith json output
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace FancyGuy\Composer\SecurityCheck\Output; | ||
|
||
use FancyGuy\Composer\SecurityCheck\Exception\RuntimeException; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Output\StreamOutput; | ||
|
||
class FileOutput extends StreamOutput | ||
{ | ||
/** | ||
* @param string $filePath Full path to the file to append to | ||
* @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) | ||
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing) | ||
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) | ||
* | ||
* @see Symfony\Component\Console\Output\StreamOutput::__construct | ||
*/ | ||
public function __construct(string $filePath, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) | ||
{ | ||
if (false === ($writeStream = fopen($filePath, 'a', false))) { | ||
throw new RuntimeException(sprintf('Could not open write stream to: %s', $filePath)); | ||
} | ||
parent::__construct($writeStream, $verbosity, $decorated, $formatter); | ||
} | ||
|
||
/** | ||
* @throws RuntimeException Unable to close output file stream handle | ||
*/ | ||
public function __destruct() | ||
{ | ||
if (!fclose($this->getStream())) { | ||
throw new RuntimeException('Unable to write stream handle'); | ||
} | ||
} | ||
} |