1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of Underscore.php |
6
|
|
|
* |
7
|
|
|
* (c) Maxime Fabre <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Underscore; |
14
|
|
|
|
15
|
|
|
use Underscore\Methods\ArraysMethods; |
16
|
|
|
use Underscore\Traits\Repository; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The base class and wrapper around all other classes. |
20
|
|
|
*/ |
21
|
|
|
class Underscore extends Repository |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The current config. |
25
|
|
|
*/ |
26
|
|
|
protected static array $options = []; |
27
|
|
|
|
28
|
|
|
//////////////////////////////////////////////////////////////////// |
29
|
|
|
//////////////////////////// INTERFACE ///////////////////////////// |
30
|
|
|
//////////////////////////////////////////////////////////////////// |
31
|
|
|
/** |
32
|
|
|
* Dispatch to the correct Repository class. |
33
|
|
|
* |
34
|
|
|
* @param mixed $subject The subject |
35
|
|
|
*/ |
36
|
|
|
public static function from($subject) : Repository |
37
|
|
|
{ |
38
|
|
|
$class = Dispatch::toClass($subject); |
39
|
|
|
|
40
|
3 |
|
return $class::from($subject); |
41
|
|
|
} |
42
|
3 |
|
|
43
|
|
|
//////////////////////////////////////////////////////////////////// |
44
|
3 |
|
///////////////////////////// HELPERS ////////////////////////////// |
45
|
|
|
//////////////////////////////////////////////////////////////////// |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get an option from the config file. |
49
|
|
|
* |
50
|
|
|
* @param string $option The key of the option |
51
|
|
|
* |
52
|
|
|
* @return mixed Its value |
53
|
|
|
*/ |
54
|
|
|
public static function option(string $option) : mixed |
55
|
|
|
{ |
56
|
|
|
// Get config file |
57
|
|
|
if (!static::$options) { |
|
|
|
|
58
|
34 |
|
static::$options = include __DIR__.'/../config/underscore.php'; |
59
|
|
|
} |
60
|
|
|
|
61
|
34 |
|
return ArraysMethods::get(static::$options, $option); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.