Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
file_info
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 get
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 __get
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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\storage;
15
16use phpbb\storage\exception\storage_exception;
17use phpbb\storage\adapter\adapter_interface;
18
19class file_info
20{
21    /**
22     * @var adapter_interface
23     */
24    protected $adapter;
25
26    /**
27     * Path of the file
28     *
29     * @var string
30     */
31    protected $path;
32
33    /**
34     * Stores the properties of $path file, so dont have to be consulted  multiple times.
35     * For example, when you need the width of an image, using getimagesize() you get
36     * both dimensions, so you store both here, and when you get the height, you dont have
37     * to call getimagesize() again
38     *
39     * @var array
40     */
41    protected $properties;
42
43    /**
44     * Constructor
45     *
46     * @param adapter_interface $adapter
47     * @param string $path
48     */
49    public function __construct(adapter_interface $adapter, $path)
50    {
51        $this->adapter = $adapter;
52        $this->path = $path;
53        $this->properties = [];
54    }
55
56    /**
57     * Load propertys lazily
58     *
59     * @param string    $name        The property name.
60     *
61     * @return string    Returns the property value
62     */
63    public function get($name)
64    {
65        if (!isset($this->properties[$name]))
66        {
67            if (!method_exists($this->adapter, 'file_' . $name))
68            {
69                throw new storage_exception('STORAGE_METHOD_NOT_IMPLEMENTED');
70            }
71
72            $this->properties = array_merge($this->properties, call_user_func([$this->adapter, 'file_' . $name], $this->path));
73        }
74
75        return $this->properties[$name];
76    }
77
78    /**
79     * Alias of \phpbb\storage\file_info->get()
80     */
81    public function __get($name)
82    {
83        return $this->get($name);
84    }
85}