Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Output / Printer / Factory / FilesystemOutputFactory.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Output\Printer\Factory;
12
13 use Behat\Testwork\Output\Exception\BadOutputPathException;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Output\StreamOutput;
16
17 /**
18  * Creates an output stream for the filesystem.
19  *
20  * @author Wouter J <wouter@wouterj.nl>
21  */
22 class FilesystemOutputFactory extends OutputFactory
23 {
24     private $fileName;
25
26     public function setFileName($fileName)
27     {
28         $this->fileName = $fileName;
29     }
30
31     /**
32      * Configure output stream parameters.
33      *
34      * @param OutputInterface $output
35      */
36     protected function configureOutputStream(OutputInterface $output)
37     {
38         $verbosity = $this->getOutputVerbosity() ? OutputInterface::VERBOSITY_VERBOSE : OutputInterface::VERBOSITY_NORMAL;
39         $output->setVerbosity($verbosity);
40     }
41
42     /**
43      * {@inheritDoc}
44      */
45     public function createOutput($stream = null)
46     {
47         if (is_file($this->getOutputPath())) {
48             throw new BadOutputPathException(
49                 'Directory expected for the `output_path` option, but a filename was given.',
50                 $this->getOutputPath()
51             );
52         } elseif (!is_dir($this->getOutputPath())) {
53             mkdir($this->getOutputPath(), 0777, true);
54         }
55
56         if (null === $this->fileName) {
57             throw new \LogicException('Unable to create file, no file name specified');
58         }
59
60         $filePath = $this->getOutputPath().'/'.$this->fileName;
61
62         $stream = new StreamOutput(
63             fopen($filePath, 'w'),
64             StreamOutput::VERBOSITY_NORMAL,
65             false // a file is never decorated
66         );
67         $this->configureOutputStream($stream);
68
69         return $stream;
70     }
71 }