Passed
Pull Request — master (#51)
by Rustam
12:12
created

Parameters::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use Yiisoft\Arrays\ArrayHelper;
8
9
/**
10
 * Parameters provides a way to get application parameters defined in config/params.php
11
 *
12
 * In order to use in a handler or any other place supporting auto-wired injection:
13
 *
14
 * ```php
15
 *
16
 * $params = [
17
 *      'admin' => [
18
 *          'email' => '[email protected]'
19
 *      ]
20
 * ];
21
 * ```
22
 *
23
 * ```php
24
 * public function actionIndex(Parameters $parameters)
25
 * {
26
 *     $adminEmail = $parameters->get('admin.email', '[email protected]'); // return [email protected] or [email protected] if search key not exists in parameters
27
 * }
28
 * ```
29
 */
30
class Parameters
31
{
32
    private array $parameters;
33
34
    public function __construct(array $data)
35
    {
36
        $this->parameters = $data;
37
    }
38
39
    public function get(string $key, $default = null)
40
    {
41
        return ArrayHelper::getValue($this->parameters, $key, $default);
42
    }
43
}
44