Completed
Push — master ( ca7ebd...ffd42a )
by Nikolas
03:40
created

WebApplication::restrictAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web;
3
4
use rtens\domin\ActionRegistry;
5
use rtens\domin\delivery\FieldRegistry;
6
use rtens\domin\delivery\RendererRegistry;
7
use rtens\domin\delivery\web\fields\ActionField;
8
use rtens\domin\delivery\web\fields\ColorField;
9
use rtens\domin\delivery\web\fields\DateIntervalField;
10
use rtens\domin\delivery\web\fields\RangeField;
11
use rtens\domin\delivery\web\fields\TextField;
12
use rtens\domin\delivery\web\renderers\charting\ChartRenderer;
13
use rtens\domin\delivery\web\renderers\charting\ScatterChartRenderer;
14
use rtens\domin\delivery\web\renderers\ColorRenderer;
15
use rtens\domin\delivery\web\renderers\dashboard\ActionPanelRenderer;
16
use rtens\domin\delivery\web\renderers\dashboard\DashboardItemRenderer;
17
use rtens\domin\delivery\web\renderers\DateIntervalRenderer;
18
use rtens\domin\delivery\web\renderers\DelayedOutputRenderer;
19
use rtens\domin\delivery\web\renderers\ElementRenderer;
20
use rtens\domin\delivery\web\renderers\MapRenderer;
21
use rtens\domin\delivery\web\renderers\tables\DataTableRenderer;
22
use rtens\domin\delivery\web\renderers\tables\TableRenderer;
23
use rtens\domin\delivery\web\renderers\TextRenderer;
24
use rtens\domin\execution\access\AccessControl;
25
use rtens\domin\parameters\IdentifiersProvider;
26
use rtens\domin\reflection\types\TypeFactory;
27
use rtens\domin\delivery\web\fields\ImageField;
28
use rtens\domin\delivery\web\fields\NumberField;
29
use rtens\domin\delivery\web\menu\Menu;
30
use rtens\domin\delivery\web\renderers\ListRenderer;
31
use rtens\domin\delivery\web\renderers\BooleanRenderer;
32
use rtens\domin\delivery\web\renderers\DateTimeRenderer;
33
use rtens\domin\delivery\web\renderers\FileRenderer;
34
use rtens\domin\delivery\web\renderers\HtmlRenderer;
35
use rtens\domin\delivery\web\renderers\IdentifierRenderer;
36
use rtens\domin\delivery\web\renderers\ImageRenderer;
37
use rtens\domin\delivery\web\renderers\link\LinkPrinter;
38
use rtens\domin\delivery\web\renderers\link\LinkRegistry;
39
use rtens\domin\delivery\web\renderers\ObjectRenderer;
40
use rtens\domin\delivery\web\renderers\PrimitiveRenderer;
41
use rtens\domin\delivery\web\fields\ArrayField;
42
use rtens\domin\delivery\web\fields\BooleanField;
43
use rtens\domin\delivery\web\fields\DateTimeField;
44
use rtens\domin\delivery\web\fields\EnumerationField;
45
use rtens\domin\delivery\web\fields\FileField;
46
use rtens\domin\delivery\web\fields\HtmlField;
47
use rtens\domin\delivery\web\fields\IdentifierField;
48
use rtens\domin\delivery\web\fields\MultiField;
49
use rtens\domin\delivery\web\fields\NullableField;
50
use rtens\domin\delivery\web\fields\ObjectField;
51
use rtens\domin\delivery\web\fields\StringField;
52
use watoki\factory\Factory;
53
54
class WebApplication {
55
56
    /** @var string */
57
    public $name = 'domin';
58
59
    /** @var Factory */
60
    public $factory;
61
62
    /** @var ActionRegistry */
63
    public $actions;
64
65
    /** @var RendererRegistry */
66
    public $renderers;
67
68
    /** @var LinkRegistry */
69
    public $links;
70
71
    /** @var TypeFactory */
72
    public $types;
73
74
    /** @var FieldRegistry */
75
    public $fields;
76
77
    /** @var IdentifiersProvider */
78
    public $identifiers;
79
80
    /** @var Menu */
81
    public $menu;
82
83
    /** @var MobileDetector */
84
    public $detector;
85
86
    /** @var WebCommentParser */
87
    public $parser;
88
89
    /** @var AccessControl */
90
    public $access;
91
92
    /** @var ActionGroups */
93
    public $groups;
94
95
    /** @var null|ExecutionToken */
96
    public $token;
97
98
    /**
99
     * @param Factory $factory <-
100
     * @param ActionRegistry $actions <-
101
     * @param FieldRegistry $fields <-
102
     * @param RendererRegistry $renderers <-
103
     * @param LinkRegistry $links <-
104
     * @param IdentifiersProvider $identifiers <-
105
     * @param TypeFactory $types <-
106
     * @param MobileDetector $detect <-
107
     * @param WebCommentParser $parser <-
108
     * @param AccessControl $access <-
109
     */
110
    public function __construct(Factory $factory, ActionRegistry $actions, FieldRegistry $fields,
111
                                RendererRegistry $renderers, LinkRegistry $links, IdentifiersProvider $identifiers,
112
                                TypeFactory $types, MobileDetector $detect, WebCommentParser $parser,
113
                                AccessControl $access) {
114
        $factory->setSingleton($this);
115
116
        $this->factory = $factory;
117
        $this->actions = $actions;
118
        $this->renderers = $renderers;
119
        $this->links = $links;
120
        $this->types = $types;
121
        $this->fields = $fields;
122
        $this->identifiers = $identifiers;
123
        $this->detector = $detect;
124
        $this->parser = $parser;
125
        $this->access = $access;
126
        $this->menu = new Menu($actions);
0 ignored issues
show
Unused Code introduced by
The call to Menu::__construct() has too many arguments starting with $actions.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
127
        $this->groups = new ActionGroups($actions);
128
    }
129
130
    /**
131
     * @param callable $callback Receives the WebApplication instance
132
     * @param null|Factory $factory
133
     * @return Factory
134
     */
135
    public static function init(callable $callback, Factory $factory = null) {
136
        $factory = $factory ?: new Factory();
137
138
        /** @var self $instance */
139
        $instance = $factory->getInstance(self::class);
140
        $callback($factory->setSingleton($instance));
141
        $instance->prepare();
142
143
        return $factory;
144
    }
145
146
    /**
147
     * @param string $name
148
     */
149
    public function setNameAndBrand($name) {
150
        $this->name = $name;
151
        $this->menu->setBrand($name);
152
    }
153
154
    public function prepare() {
155
        $this->registerRenderers();
156
        $this->registerFields();
157
    }
158
159
    private function registerRenderers() {
160
        $links = new LinkPrinter($this->links, $this->actions, $this->parser, $this->token);
161
162
        $this->renderers->add(new ElementRenderer());
163
        $this->renderers->add(new BooleanRenderer());
164
        $this->renderers->add(new ColorRenderer());
165
        $this->renderers->add(new PrimitiveRenderer());
166
        $this->renderers->add(new DateTimeRenderer());
167
        $this->renderers->add(new DateIntervalRenderer());
168
        $this->renderers->add(new TextRenderer());
169
        $this->renderers->add(new HtmlRenderer());
170
        $this->renderers->add(new IdentifierRenderer($links));
171
        $this->renderers->add(new FileRenderer());
172
        $this->renderers->add(new ImageRenderer());
173
        $this->renderers->add(new ScatterChartRenderer());
174
        $this->renderers->add(new ChartRenderer());
175
        $this->renderers->add(new DelayedOutputRenderer());
176
        $this->renderers->add(new DashboardItemRenderer($this->renderers));
177
        $this->renderers->add(new ActionPanelRenderer($this->renderers, $this->actions, $this->fields));
178
        $this->renderers->add(new DataTableRenderer($this->renderers));
179
        $this->renderers->add(new TableRenderer($this->renderers, $links));
180
        $this->renderers->add(new ListRenderer($this->renderers, $links));
181
        $this->renderers->add(new MapRenderer($this->renderers, $links));
182
        $this->renderers->add(new ObjectRenderer($this->renderers, $this->types, $links));
183
    }
184
185
    private function registerFields() {
186
        $this->fields->add(new StringField());
187
        $this->fields->add(new NumberField());
188
        $this->fields->add(new RangeField($this->detector));
189
        $this->fields->add(new BooleanField());
190
        $this->fields->add(new ColorField());
191
        $this->fields->add(new FileField());
192
        $this->fields->add(new ImageField());
193
        $this->fields->add(new TextField());
194
        $this->fields->add(new HtmlField());
195
        $this->fields->add(new DateTimeField());
196
        $this->fields->add(new DateIntervalField());
197
        $this->fields->add(new ArrayField($this->fields, $this->detector));
198
        $this->fields->add(new NullableField($this->fields));
199
        $this->fields->add(new ActionField($this->fields, $this->actions));
200
        $this->fields->add(new ObjectField($this->types, $this->fields));
201
        $this->fields->add(new MultiField($this->fields));
202
        $this->fields->add(new IdentifierField($this->fields, $this->identifiers));
203
        $this->fields->add(new EnumerationField($this->fields));
204
    }
205
}