Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
57.14% covered (warning)
57.14%
4 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
temp
57.14% covered (warning)
57.14%
4 / 7
50.00% covered (danger)
50.00%
1 / 2
10.86
0.00% covered (danger)
0.00%
0 / 1
 __construct
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
10.50
 get_dir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\filesystem;
15
16class temp
17{
18    /**
19    * @var string    Temporary directory path
20    */
21    protected $temp_dir;
22
23    /**
24     * Constructor
25     */
26    public function __construct($filesystem, $cache_temp_dir)
27    {
28        $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
29
30        // Prevent trying to write to system temp dir in case of open_basedir
31        // restrictions being in effect
32        if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
33        {
34            $tmp_dir = $cache_temp_dir;
35
36            if (!is_dir($tmp_dir))
37            {
38                $filesystem->mkdir($tmp_dir, 0777);
39            }
40        }
41
42        $this->temp_dir = helper::realpath($tmp_dir);
43    }
44
45    /**
46     * Get a temporary directory to write files
47     *
48     * @return string    returns the directory
49     */
50    public function get_dir()
51    {
52        return $this->temp_dir;
53    }
54}