|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of sensorario/resources repository |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Simone Gentili <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sensorario\Resources; |
|
13
|
|
|
|
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
use Sensorario\Resources\Validators\ResourcesValidator; |
|
16
|
|
|
|
|
17
|
|
|
class Resource |
|
18
|
|
|
extends MagicResource |
|
|
|
|
|
|
19
|
|
|
implements Interfaces\ResourceInterface |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
protected static $allowed = []; |
|
22
|
|
|
|
|
23
|
|
|
protected static $allowedValues = []; |
|
24
|
|
|
|
|
25
|
|
|
protected static $mandatory = []; |
|
26
|
|
|
|
|
27
|
|
|
protected static $defaults = []; |
|
28
|
|
|
|
|
29
|
|
|
protected static $rules = []; |
|
30
|
|
|
|
|
31
|
|
|
public static function mandatory() |
|
32
|
|
|
{ |
|
33
|
|
|
return static::$mandatory; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function allowed() |
|
37
|
|
|
{ |
|
38
|
|
|
return static::$allowed; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function allowedValues() |
|
42
|
|
|
{ |
|
43
|
|
|
return static::$allowedValues; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function rules() |
|
47
|
|
|
{ |
|
48
|
|
|
return static::$rules; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function defaults() |
|
52
|
|
|
{ |
|
53
|
|
|
return static::$defaults; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function applyConfiguration( |
|
57
|
|
|
$resourceName, |
|
58
|
|
|
Container $config |
|
59
|
|
|
) { |
|
60
|
|
|
static::$allowed = $config->allowed($resourceName); |
|
61
|
|
|
static::$mandatory = $config->mandatory($resourceName); |
|
62
|
|
|
static::$defaults = $config->defaults($resourceName); |
|
63
|
|
|
static::$rules = $config->rules($resourceName); |
|
64
|
|
|
static::$allowedValues = $config->allowedValues($resourceName); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function fromConfiguration( |
|
68
|
|
|
$resourceName, |
|
69
|
|
|
Container $container |
|
70
|
|
|
) { |
|
71
|
|
|
$resource = new self( |
|
72
|
|
|
[], |
|
73
|
|
|
new ResourcesValidator(), |
|
74
|
|
|
$validationRequired = false |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$resource->applyConfiguration( |
|
78
|
|
|
$resourceName, |
|
79
|
|
|
$container |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
return $resource; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|