Passed
Push — main ( 4ddaea...7c5fe7 )
by Thierry
04:58
created
jaxon-core/src/App/View/ViewInterface.php 1 patch
Switch Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 interface ViewInterface
6 6
 {
7
-    /**
7
+/**
8 8
      * Add a namespace to the view renderer
9 9
      *
10 10
      * @param string $sNamespace    The namespace name
@@ -13,14 +13,14 @@  discard block
 block discarded – undo
13 13
      *
14 14
      * @return void
15 15
      */
16
-    public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void;
16
+public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void;
17 17
 
18
-    /**
18
+/**
19 19
      * Render a view
20 20
      *
21 21
      * @param Store $store    A store populated with the view data
22 22
      *
23 23
      * @return string
24 24
      */
25
-    public function render(Store $store): string;
25
+public function render(Store $store): string;
26 26
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/View/Helper/EventAttr.php 1 patch
Switch Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -23,33 +23,33 @@  discard block
 block discarded – undo
23 23
 
24 24
 class EventAttr
25 25
 {
26
-    /**
26
+/**
27 27
      * @var array
28 28
      */
29
-    private array $aHandlers = [];
29
+private array $aHandlers = [];
30 30
 
31
-    /**
31
+/**
32 32
      * The constructor
33 33
      *
34 34
      * @param string $sSelector
35 35
      */
36
-    public function __construct(private string $sSelector)
37
-    {}
36
+public function __construct(private string $sSelector)
37
+{}
38 38
 
39
-    /**
39
+/**
40 40
      * Set a selector for the next event handler
41 41
      *
42 42
      * @param string $sSelector
43 43
      *
44 44
      * @return self
45 45
      */
46
-    public function select(string $sSelector): self
47
-    {
48
-        $this->sSelector = trim($sSelector);
49
-        return $this;
50
-    }
46
+public function select(string $sSelector): self
47
+{
48
+$this->sSelector = trim($sSelector);
49
+return $this;
50
+}
51 51
 
52
-    /**
52
+/**
53 53
      * Set an event handler with the "on" keyword
54 54
      *
55 55
      * @param string $event
@@ -57,43 +57,43 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return self
59 59
      */
60
-    public function on(string $event, JsExpr $xJsExpr): self
61
-    {
62
-        if($this->sSelector === '')
63
-        {
64
-            return $this;
65
-        }
60
+public function on(string $event, JsExpr $xJsExpr): self
61
+{
62
+if($this->sSelector === '')
63
+{
64
+return $this;
65
+}
66 66
 
67
-        $this->aHandlers[] = [
68
-            'select' => $this->sSelector,
69
-            'event' => trim($event),
70
-            'handler' => $xJsExpr,
71
-        ];
72
-        $this->sSelector = '';
73
-        return $this;
74
-    }
67
+$this->aHandlers[] = [
68
+'select' => $this->sSelector,
69
+'event' => trim($event),
70
+'handler' => $xJsExpr,
71
+];
72
+$this->sSelector = '';
73
+return $this;
74
+}
75 75
 
76
-    /**
76
+/**
77 77
      * Shortcut to set a click event handler
78 78
      *
79 79
      * @param JsExpr $xJsExpr
80 80
      *
81 81
      * @return self
82 82
      */
83
-    public function click(JsExpr $xJsExpr): self
84
-    {
85
-        return $this->on('click', $xJsExpr);
86
-    }
83
+public function click(JsExpr $xJsExpr): self
84
+{
85
+return $this->on('click', $xJsExpr);
86
+}
87 87
 
88
-    /**
88
+/**
89 89
      * Convert to string.
90 90
      *
91 91
      * @return string
92 92
      */
93
-    public function __toString(): string
94
-    {
95
-        // No output if no handler is defined.
96
-        return count($this->aHandlers) === 0 ? '' : 'jxn-event="' .
97
-            htmlentities(json_encode($this->aHandlers)) . '"';
98
-    }
93
+public function __toString(): string
94
+{
95
+// No output if no handler is defined.
96
+return count($this->aHandlers) === 0 ? '' : 'jxn-event="' .
97
+htmlentities(json_encode($this->aHandlers)) . '"';
98
+}
99 99
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/View/Helper/HtmlAttrHelper.php 1 patch
Switch Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -31,40 +31,40 @@  discard block
 block discarded – undo
31 31
 
32 32
 class HtmlAttrHelper
33 33
 {
34
-    /**
34
+/**
35 35
      * @var string|null
36 36
      */
37
-    private string|null $sPaginationComponent = null;
37
+private string|null $sPaginationComponent = null;
38 38
 
39
-    /**
39
+/**
40 40
      * The constructor
41 41
      *
42 42
      * @param ComponentContainer $cdi
43 43
      */
44
-    public function __construct(protected ComponentContainer $cdi)
45
-    {}
44
+public function __construct(protected ComponentContainer $cdi)
45
+{}
46 46
 
47
-    /**
47
+/**
48 48
      * Get the component HTML code
49 49
      *
50 50
      * @param JxnCall $xJsCall
51 51
      *
52 52
      * @return string
53 53
      */
54
-    public function html(JxnCall $xJsCall): string
55
-    {
56
-        $sClassName = $xJsCall->_class();
57
-        if(!$sClassName)
58
-        {
59
-            return '';
60
-        }
61
-
62
-        $xComponent = $this->cdi->makeComponent($sClassName);
63
-        return is_a($xComponent, NodeComponent::class) ?
64
-            (string)$xComponent->html() : '';
65
-    }
66
-
67
-    /**
54
+public function html(JxnCall $xJsCall): string
55
+{
56
+$sClassName = $xJsCall->_class();
57
+if(!$sClassName)
58
+{
59
+return '';
60
+}
61
+
62
+$xComponent = $this->cdi->makeComponent($sClassName);
63
+return is_a($xComponent, NodeComponent::class) ?
64
+(string)$xComponent->html() : '';
65
+}
66
+
67
+/**
68 68
      * Attach a component to a DOM node
69 69
      *
70 70
      * @param JxnCall $xJsCall
@@ -72,41 +72,41 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @return string
74 74
      */
75
-    public function bind(JxnCall $xJsCall, string $item = ''): string
76
-    {
77
-        $item = trim($item);
78
-        return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"');
79
-    }
75
+public function bind(JxnCall $xJsCall, string $item = ''): string
76
+{
77
+$item = trim($item);
78
+return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"');
79
+}
80 80
 
81
-    /**
81
+/**
82 82
      * Attach the pagination component to a DOM node
83 83
      *
84 84
      * @param JxnCall $xJsCall
85 85
      *
86 86
      * @return string
87 87
      */
88
-    public function pagination(JxnCall $xJsCall): string
89
-    {
90
-        // The pagination is always rendered with the same Pagination component.
91
-        $sComponent = $this->sPaginationComponent ?:
92
-            ($this->sPaginationComponent = rq(Pagination::class)->_class());
93
-        $sItem = $xJsCall->_class();
94
-        return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\"";
95
-    }
96
-
97
-    /**
88
+public function pagination(JxnCall $xJsCall): string
89
+{
90
+// The pagination is always rendered with the same Pagination component.
91
+$sComponent = $this->sPaginationComponent ?:
92
+($this->sPaginationComponent = rq(Pagination::class)->_class());
93
+$sItem = $xJsCall->_class();
94
+return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\"";
95
+}
96
+
97
+/**
98 98
      * Set a selector for the next event handler
99 99
      *
100 100
      * @param string $sSelector
101 101
      *
102 102
      * @return EventAttr
103 103
      */
104
-    public function select(string $sSelector): EventAttr
105
-    {
106
-        return new EventAttr($sSelector);
107
-    }
104
+public function select(string $sSelector): EventAttr
105
+{
106
+return new EventAttr($sSelector);
107
+}
108 108
 
109
-    /**
109
+/**
110 110
      * Set an event handler
111 111
      *
112 112
      * @param string $event
@@ -114,83 +114,83 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return string
116 116
      */
117
-    public function on(string $event, JsExpr $xJsExpr): string
118
-    {
119
-        $event = trim($event);
120
-        $sCall = htmlentities(json_encode($xJsExpr->jsonSerialize()));
121
-        return "jxn-on=\"$event\" jxn-call=\"$sCall\"";
122
-    }
123
-
124
-    /**
117
+public function on(string $event, JsExpr $xJsExpr): string
118
+{
119
+$event = trim($event);
120
+$sCall = htmlentities(json_encode($xJsExpr->jsonSerialize()));
121
+return "jxn-on=\"$event\" jxn-call=\"$sCall\"";
122
+}
123
+
124
+/**
125 125
      * Shortcut to set a click event handler
126 126
      *
127 127
      * @param JsExpr $xJsExpr
128 128
      *
129 129
      * @return string
130 130
      */
131
-    public function click(JsExpr $xJsExpr): string
132
-    {
133
-        return $this->on('click', $xJsExpr);
134
-    }
131
+public function click(JsExpr $xJsExpr): string
132
+{
133
+return $this->on('click', $xJsExpr);
134
+}
135 135
 
136
-    /**
136
+/**
137 137
      * @param array $aHandler
138 138
      *
139 139
      * @return bool
140 140
      */
141
-    private function eventIsValid(array $aHandler): bool
142
-    {
143
-        return count($aHandler) === 3 &&
144
-            isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) &&
145
-            is_string($aHandler[0]) && is_string($aHandler[1]) &&
146
-            is_a($aHandler[2], JsExpr::class);
147
-    }
148
-
149
-    /**
141
+private function eventIsValid(array $aHandler): bool
142
+{
143
+return count($aHandler) === 3 &&
144
+isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) &&
145
+is_string($aHandler[0]) && is_string($aHandler[1]) &&
146
+is_a($aHandler[2], JsExpr::class);
147
+}
148
+
149
+/**
150 150
      * @param array $aHandler
151 151
      * @param EventAttr|null $xAttr
152 152
      *
153 153
      * @return EventAttr|null
154 154
      */
155
-    private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null
156
-    {
157
-        if(!$this->eventIsValid($aHandler))
158
-        {
159
-            return $xAttr;
160
-        }
161
-        // The array content is valid.
162
-        [$sSelector, $sEvent, $xJsExpr] = $aHandler;
163
-        return !$xAttr ?
164
-            $this->select($sSelector)->on($sEvent, $xJsExpr) :
165
-            $xAttr->select($sSelector)->on($sEvent, $xJsExpr);
166
-    }
167
-
168
-    /**
155
+private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null
156
+{
157
+if(!$this->eventIsValid($aHandler))
158
+{
159
+return $xAttr;
160
+}
161
+// The array content is valid.
162
+[$sSelector, $sEvent, $xJsExpr] = $aHandler;
163
+return !$xAttr ?
164
+$this->select($sSelector)->on($sEvent, $xJsExpr) :
165
+$xAttr->select($sSelector)->on($sEvent, $xJsExpr);
166
+}
167
+
168
+/**
169 169
      * Set an event handler
170 170
      *
171 171
      * @param array $aHandler
172 172
      *
173 173
      * @return string
174 174
      */
175
-    public function event(array $aHandler): string
176
-    {
177
-        return $this->setEventHandler($aHandler)?->__toString() ?? '';
178
-    }
175
+public function event(array $aHandler): string
176
+{
177
+return $this->setEventHandler($aHandler)?->__toString() ?? '';
178
+}
179 179
 
180
-    /**
180
+/**
181 181
      * Set event handlers
182 182
      *
183 183
      * @param array $aHandlers
184 184
      *
185 185
      * @return string
186 186
      */
187
-    public function events(array $aHandlers): string
188
-    {
189
-        return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler)
190
-            => $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? '';
191
-    }
187
+public function events(array $aHandlers): string
188
+{
189
+return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler)
190
+=> $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? '';
191
+}
192 192
 
193
-    /**
193
+/**
194 194
      * Get the HTML or Javascript ready code for a package
195 195
      *
196 196
      * @param string $sClass
@@ -198,17 +198,17 @@  discard block
 block discarded – undo
198 198
      *
199 199
      * @return string
200 200
      */
201
-    public function package(string $sClass, string $sType = 'html'): string
202
-    {
203
-        $sCode = match($sType) {
204
-            'html' => jaxon()->package($sClass)?->getHtml() ?? '',
205
-            'ready' => jaxon()->package($sClass)?->getReadyScript() ?? '',
206
-            default => ''
207
-        };
208
-        $sCode = trim($sCode);
209
-
210
-        return $sType !== 'ready' || $sCode === '' ? $sCode :
211
-            // Call the ready code with the jaxon.dom.ready function.
212
-            "jaxon.dom.ready(() => $sCode)";
213
-    }
201
+public function package(string $sClass, string $sType = 'html'): string
202
+{
203
+$sCode = match($sType) {
204
+'html' => jaxon()->package($sClass)?->getHtml() ?? '',
205
+'ready' => jaxon()->package($sClass)?->getReadyScript() ?? '',
206
+default => ''
207
+};
208
+$sCode = trim($sCode);
209
+
210
+return $sType !== 'ready' || $sCode === '' ? $sCode :
211
+// Call the ready code with the jaxon.dom.ready function.
212
+"jaxon.dom.ready(() => $sCode)";
213
+}
214 214
 }
Please login to merge, or discard this patch.
jaxon-annotations/src/Annotation/ExportAnnotation.php 1 patch
Switch Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,41 +26,41 @@
 block discarded – undo
26 26
  */
27 27
 class ExportAnnotation extends AbstractAnnotation
28 28
 {
29
-    /**
29
+/**
30 30
      * @var array
31 31
      */
32
-    private $aMethods = [];
32
+private $aMethods = [];
33 33
 
34
-    /**
34
+/**
35 35
      * @inheritDoc
36 36
      */
37
-    public static function parseAnnotation($value)
38
-    {
39
-        $aParams = json_decode($value, true);
40
-        return is_array($aParams) ? $aParams : [];
41
-    }
37
+public static function parseAnnotation($value)
38
+{
39
+$aParams = json_decode($value, true);
40
+return is_array($aParams) ? $aParams : [];
41
+}
42 42
 
43
-    /**
43
+/**
44 44
      * @inheritDoc
45 45
      * @throws AnnotationException
46 46
      */
47
-    public function initAnnotation(array $properties)
48
-    {
49
-        foreach(['base', 'only', 'except'] as $key)
50
-        {
51
-            if(isset($properties[$key]) && is_array($properties[$key]) &&
52
-                count($properties[$key]) > 0)
53
-            {
54
-                $this->aMethods[$key] = $properties[$key];
55
-            }
56
-        }
57
-    }
47
+public function initAnnotation(array $properties)
48
+{
49
+foreach(['base', 'only', 'except'] as $key)
50
+{
51
+if(isset($properties[$key]) && is_array($properties[$key]) &&
52
+    count($properties[$key]) > 0)
53
+{
54
+    $this->aMethods[$key] = $properties[$key];
55
+}
56
+}
57
+}
58 58
 
59
-    /**
59
+/**
60 60
      * @inheritDoc
61 61
      */
62
-    public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
63
-    {
64
-        $xMetadata->export($sMethod)->setMethods($this->aMethods);
65
-    }
62
+public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
63
+{
64
+$xMetadata->export($sMethod)->setMethods($this->aMethods);
65
+}
66 66
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/Metadata/Data/ExportData.php 1 patch
Switch Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -22,53 +22,53 @@
 block discarded – undo
22 22
 
23 23
 class ExportData extends AbstractData
24 24
 {
25
-    /**
25
+/**
26 26
      * @var array<string, array<string>>
27 27
      */
28
-    private array $aMethods = [];
28
+private array $aMethods = [];
29 29
 
30
-    /**
30
+/**
31 31
      * @return string
32 32
      */
33
-    public function getName(): string
34
-    {
35
-        return 'export';
36
-    }
33
+public function getName(): string
34
+{
35
+return 'export';
36
+}
37 37
 
38
-    /**
38
+/**
39 39
      * @return mixed
40 40
      */
41
-    public function getValue(): mixed
42
-    {
43
-        return $this->aMethods;
44
-    }
41
+public function getValue(): mixed
42
+{
43
+return $this->aMethods;
44
+}
45 45
 
46
-    /**
46
+/**
47 47
      * @param array $aMethods
48 48
      *
49 49
      * @return void
50 50
      */
51
-    public function setMethods(array $aMethods): void
51
+public function setMethods(array $aMethods): void
52
+{
53
+foreach(['base', 'only', 'except'] as $sKey)
54
+{
55
+foreach($aMethods[$sKey] ?? [] as $sMethod)
56
+{
57
+    if(!is_string($sMethod) || !$this->validateMethod($sMethod))
52 58
     {
53
-        foreach(['base', 'only', 'except'] as $sKey)
54
-        {
55
-            foreach($aMethods[$sKey] ?? [] as $sMethod)
56
-            {
57
-                if(!is_string($sMethod) || !$this->validateMethod($sMethod))
58
-                {
59
-                    throw new SetupException("'$sMethod' is not a valid method name.");
60
-                }
61
-            }
62
-        }
63
-        $this->aMethods = $aMethods;
59
+        throw new SetupException("'$sMethod' is not a valid method name.");
64 60
     }
61
+}
62
+}
63
+$this->aMethods = $aMethods;
64
+}
65 65
 
66
-    /**
66
+/**
67 67
      * @inheritDoc
68 68
      */
69
-    public function encode(string $sVarName): array
70
-    {
71
-        $sMethods = addslashes(json_encode($this->aMethods));
72
-        return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"];
73
-    }
69
+public function encode(string $sVarName): array
70
+{
71
+$sMethods = addslashes(json_encode($this->aMethods));
72
+return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"];
73
+}
74 74
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/ComponentOptions.php 1 patch
Switch Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -34,224 +34,224 @@  discard block
 block discarded – undo
34 34
 
35 35
 class ComponentOptions
36 36
 {
37
-    /**
37
+/**
38 38
      * Check if the js code for this object must be generated
39 39
      *
40 40
      * @var bool
41 41
      */
42
-    private $bExcluded = false;
42
+private $bExcluded = false;
43 43
 
44
-    /**
44
+/**
45 45
      * The character to use as separator in javascript class names
46 46
      *
47 47
      * @var string
48 48
      */
49
-    private $sSeparator = '.';
49
+private $sSeparator = '.';
50 50
 
51
-    /**
51
+/**
52 52
      * A list of methods of the user registered callable object the library can export to javascript
53 53
      *
54 54
      * @var array
55 55
      */
56
-    private $aPublicMethods = [];
56
+private $aPublicMethods = [];
57 57
 
58
-    /**
58
+/**
59 59
      * The methods in the export attributes
60 60
      *
61 61
      * @var array
62 62
      */
63
-    private $aExportMethods = ['except' => []];
63
+private $aExportMethods = ['except' => []];
64 64
 
65
-    /**
65
+/**
66 66
      * A list of methods to call before processing the request
67 67
      *
68 68
      * @var array
69 69
      */
70
-    private $aBeforeMethods = [];
70
+private $aBeforeMethods = [];
71 71
 
72
-    /**
72
+/**
73 73
      * A list of methods to call after processing the request
74 74
      *
75 75
      * @var array
76 76
      */
77
-    private $aAfterMethods = [];
77
+private $aAfterMethods = [];
78 78
 
79
-    /**
79
+/**
80 80
      * The javascript class options
81 81
      *
82 82
      * @var array
83 83
      */
84
-    private $aJsOptions = [];
84
+private $aJsOptions = [];
85 85
 
86
-    /**
86
+/**
87 87
      * The DI options
88 88
      *
89 89
      * @var array
90 90
      */
91
-    private $aDiOptions = [];
91
+private $aDiOptions = [];
92 92
 
93
-    /**
93
+/**
94 94
      * The constructor
95 95
      *
96 96
      * @param array $aMethods
97 97
      * @param array $aOptions
98 98
      * @param Metadata|null $xMetadata
99 99
      */
100
-    public function __construct(array $aMethods, array $aOptions, Metadata|null $xMetadata)
101
-    {
102
-        $this->bExcluded = ($xMetadata?->isExcluded() ?? false) ||
103
-            (bool)($aOptions['excluded'] ?? false);
104
-
105
-        // Options from the config.
106
-        $sSeparator = $aOptions['separator'] ?? '.';
107
-        $this->sSeparator = $sSeparator === '_' ? '_' : '.';
108
-        $this->addProtectedMethods($aOptions['protected'] ?? []);
109
-        foreach($aOptions['functions'] ?? [] as $sNames => $aFunctionOptions)
110
-        {
111
-            // Names are in a comma-separated list.
112
-            $aFunctionNames = explode(',', $sNames);
113
-            foreach($aFunctionNames as $sFunctionName)
114
-            {
115
-                $this->addFunctionOptions($sFunctionName, $aFunctionOptions);
116
-            }
117
-        }
100
+public function __construct(array $aMethods, array $aOptions, Metadata|null $xMetadata)
101
+{
102
+$this->bExcluded = ($xMetadata?->isExcluded() ?? false) ||
103
+(bool)($aOptions['excluded'] ?? false);
104
+
105
+// Options from the config.
106
+$sSeparator = $aOptions['separator'] ?? '.';
107
+$this->sSeparator = $sSeparator === '_' ? '_' : '.';
108
+$this->addProtectedMethods($aOptions['protected'] ?? []);
109
+foreach($aOptions['functions'] ?? [] as $sNames => $aFunctionOptions)
110
+{
111
+// Names are in a comma-separated list.
112
+$aFunctionNames = explode(',', $sNames);
113
+foreach($aFunctionNames as $sFunctionName)
114
+{
115
+    $this->addFunctionOptions($sFunctionName, $aFunctionOptions);
116
+}
117
+}
118 118
 
119
-        // Options from the attributes or annotations.
120
-        if($xMetadata !== null)
121
-        {
122
-            $this->readMetadataOptions($xMetadata);
123
-        }
119
+// Options from the attributes or annotations.
120
+if($xMetadata !== null)
121
+{
122
+$this->readMetadataOptions($xMetadata);
123
+}
124 124
 
125
-        $this->aPublicMethods = $this->filterPublicMethods($aMethods);
126
-    }
125
+$this->aPublicMethods = $this->filterPublicMethods($aMethods);
126
+}
127 127
 
128
-    /**
128
+/**
129 129
      * @param array|string $xMethods
130 130
      *
131 131
      * @return void
132 132
      */
133
-    private function addProtectedMethods(array|string $xMethods): void
134
-    {
135
-        $this->aExportMethods['except'] = array_merge($this->aExportMethods['except'],
136
-            !is_array($xMethods) ? [trim((string)$xMethods)] :
137
-            array_map(fn($sMethod) => trim((string)$sMethod), $xMethods));
138
-    }
133
+private function addProtectedMethods(array|string $xMethods): void
134
+{
135
+$this->aExportMethods['except'] = array_merge($this->aExportMethods['except'],
136
+!is_array($xMethods) ? [trim((string)$xMethods)] :
137
+array_map(fn($sMethod) => trim((string)$sMethod), $xMethods));
138
+}
139 139
 
140
-    /**
140
+/**
141 141
      * @param Metadata $xMetadata
142 142
      *
143 143
      * @return void
144 144
      */
145
-    private function readMetadataOptions(Metadata $xMetadata): void
146
-    {
147
-        // Excluded methods must be merged with the existing ones.
148
-        $aExportMethods = $xMetadata->getExportMethods();
149
-        $aExportMethods['except'] = array_unique(array_merge(
150
-            $aExportMethods['except'] ?? [], $this->aExportMethods['except']));
151
-        $this->aExportMethods = $aExportMethods;
152
-        foreach($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions)
153
-        {
154
-            $this->addFunctionOptions($sFunctionName, $aFunctionOptions);
155
-        }
156
-    }
145
+private function readMetadataOptions(Metadata $xMetadata): void
146
+{
147
+// Excluded methods must be merged with the existing ones.
148
+$aExportMethods = $xMetadata->getExportMethods();
149
+$aExportMethods['except'] = array_unique(array_merge(
150
+$aExportMethods['except'] ?? [], $this->aExportMethods['except']));
151
+$this->aExportMethods = $aExportMethods;
152
+foreach($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions)
153
+{
154
+$this->addFunctionOptions($sFunctionName, $aFunctionOptions);
155
+}
156
+}
157 157
 
158
-    /**
158
+/**
159 159
      * @param array $aMethods
160 160
      *
161 161
      * @return array
162 162
      */
163
-    private function filterPublicMethods(array $aMethods): array
164
-    {
165
-        if($this->bExcluded || in_array('*', $this->aExportMethods['except']))
166
-        {
167
-            return [];
168
-        }
163
+private function filterPublicMethods(array $aMethods): array
164
+{
165
+if($this->bExcluded || in_array('*', $this->aExportMethods['except']))
166
+{
167
+return [];
168
+}
169 169
 
170
-        $aBaseMethods = $aMethods[1];
171
-        $aNoMethods = $aMethods[2];
172
-        $aMethods = $aMethods[0];
173
-        if(isset($this->aExportMethods['only']))
174
-        {
175
-            $aMethods = array_intersect($aMethods, $this->aExportMethods['only']);
176
-        }
177
-        $aMethods = array_diff($aMethods, $this->aExportMethods['except']);
178
-        if(count($aBaseMethods) > 0 && isset($this->aExportMethods['base']))
179
-        {
180
-            $aBaseMethods = array_diff($aBaseMethods, $this->aExportMethods['base']);
181
-        }
170
+$aBaseMethods = $aMethods[1];
171
+$aNoMethods = $aMethods[2];
172
+$aMethods = $aMethods[0];
173
+if(isset($this->aExportMethods['only']))
174
+{
175
+$aMethods = array_intersect($aMethods, $this->aExportMethods['only']);
176
+}
177
+$aMethods = array_diff($aMethods, $this->aExportMethods['except']);
178
+if(count($aBaseMethods) > 0 && isset($this->aExportMethods['base']))
179
+{
180
+$aBaseMethods = array_diff($aBaseMethods, $this->aExportMethods['base']);
181
+}
182 182
 
183
-        return array_values(array_diff($aMethods, $aBaseMethods, $aNoMethods));
184
-    }
183
+return array_values(array_diff($aMethods, $aBaseMethods, $aNoMethods));
184
+}
185 185
 
186
-    /**
186
+/**
187 187
      * @return array
188 188
      */
189
-    public function getPublicMethods(): array
190
-    {
191
-        return $this->aPublicMethods;
192
-    }
189
+public function getPublicMethods(): array
190
+{
191
+return $this->aPublicMethods;
192
+}
193 193
 
194
-    /**
194
+/**
195 195
      * @param string $sMethodName
196 196
      *
197 197
      * @return bool
198 198
      */
199
-    public function isPublicMethod(string $sMethodName): bool
200
-    {
201
-        return in_array($sMethodName, $this->aPublicMethods);
202
-    }
199
+public function isPublicMethod(string $sMethodName): bool
200
+{
201
+return in_array($sMethodName, $this->aPublicMethods);
202
+}
203 203
 
204
-    /**
204
+/**
205 205
      * Check if the js code for this object must be generated
206 206
      *
207 207
      * @return bool
208 208
      */
209
-    public function excluded(): bool
210
-    {
211
-        return $this->bExcluded;
212
-    }
209
+public function excluded(): bool
210
+{
211
+return $this->bExcluded;
212
+}
213 213
 
214
-    /**
214
+/**
215 215
      * @return string
216 216
      */
217
-    public function separator(): string
218
-    {
219
-        return $this->sSeparator;
220
-    }
217
+public function separator(): string
218
+{
219
+return $this->sSeparator;
220
+}
221 221
 
222
-    /**
222
+/**
223 223
      * @return array
224 224
      */
225
-    public function beforeMethods(): array
226
-    {
227
-        return $this->aBeforeMethods;
228
-    }
225
+public function beforeMethods(): array
226
+{
227
+return $this->aBeforeMethods;
228
+}
229 229
 
230
-    /**
230
+/**
231 231
      * @return array
232 232
      */
233
-    public function afterMethods(): array
234
-    {
235
-        return $this->aAfterMethods;
236
-    }
233
+public function afterMethods(): array
234
+{
235
+return $this->aAfterMethods;
236
+}
237 237
 
238
-    /**
238
+/**
239 239
      * @return array
240 240
      */
241
-    public function diOptions(): array
242
-    {
243
-        return $this->aDiOptions;
244
-    }
241
+public function diOptions(): array
242
+{
243
+return $this->aDiOptions;
244
+}
245 245
 
246
-    /**
246
+/**
247 247
      * @return array
248 248
      */
249
-    public function jsOptions(): array
250
-    {
251
-        return $this->aJsOptions;
252
-    }
249
+public function jsOptions(): array
250
+{
251
+return $this->aJsOptions;
252
+}
253 253
 
254
-    /**
254
+/**
255 255
      * Set hook methods
256 256
      *
257 257
      * @param array $aHookMethods    The array of hook methods
@@ -259,36 +259,36 @@  discard block
 block discarded – undo
259 259
      *
260 260
      * @return void
261 261
      */
262
-    private function setHookMethods(array &$aHookMethods, $xValue): void
263
-    {
264
-        foreach($xValue as $sCalledMethod => $xMethodToCall)
265
-        {
266
-            if(!isset($aHookMethods[$sCalledMethod]))
267
-            {
268
-                $aHookMethods[$sCalledMethod] = [];
269
-            }
270
-            if(is_array($xMethodToCall))
271
-            {
272
-                $aHookMethods[$sCalledMethod] =
273
-                    array_merge($aHookMethods[$sCalledMethod], $xMethodToCall);
274
-                continue;
275
-            }
276
-            if(is_string($xMethodToCall))
277
-            {
278
-                $aHookMethods[$sCalledMethod][] = $xMethodToCall;
279
-            }
280
-        }
281
-    }
262
+private function setHookMethods(array &$aHookMethods, $xValue): void
263
+{
264
+foreach($xValue as $sCalledMethod => $xMethodToCall)
265
+{
266
+if(!isset($aHookMethods[$sCalledMethod]))
267
+{
268
+    $aHookMethods[$sCalledMethod] = [];
269
+}
270
+if(is_array($xMethodToCall))
271
+{
272
+    $aHookMethods[$sCalledMethod] =
273
+        array_merge($aHookMethods[$sCalledMethod], $xMethodToCall);
274
+    continue;
275
+}
276
+if(is_string($xMethodToCall))
277
+{
278
+    $aHookMethods[$sCalledMethod][] = $xMethodToCall;
279
+}
280
+}
281
+}
282 282
 
283
-    /**
283
+/**
284 284
      * @param array $aDiOptions
285 285
      */
286
-    private function addDiOption(array $aDiOptions): void
287
-    {
288
-        $this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions);
289
-    }
286
+private function addDiOption(array $aDiOptions): void
287
+{
288
+$this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions);
289
+}
290 290
 
291
-    /**
291
+/**
292 292
      * Set configuration options / call options for each method
293 293
      *
294 294
      * @param string $sName    The name of the configuration option
@@ -296,25 +296,25 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return void
298 298
      */
299
-    private function addOption(string $sName, $xValue): void
300
-    {
301
-        switch($sName)
302
-        {
303
-        // Set the methods to call before processing the request
304
-        case '__before':
305
-            $this->setHookMethods($this->aBeforeMethods, $xValue);
306
-            break;
307
-        // Set the methods to call after processing the request
308
-        case '__after':
309
-            $this->setHookMethods($this->aAfterMethods, $xValue);
310
-            break;
311
-        // Set the attributes to inject in the callable object
312
-        case '__di':
313
-            $this->addDiOption($xValue);
314
-            break;
315
-        default:
316
-            break;
317
-        }
299
+private function addOption(string $sName, $xValue): void
300
+{
301
+switch($sName)
302
+{
303
+// Set the methods to call before processing the request
304
+case '__before':
305
+$this->setHookMethods($this->aBeforeMethods, $xValue);
306
+break;
307
+// Set the methods to call after processing the request
308
+case '__after':
309
+$this->setHookMethods($this->aAfterMethods, $xValue);
310
+break;
311
+// Set the attributes to inject in the callable object
312
+case '__di':
313
+$this->addDiOption($xValue);
314
+break;
315
+default:
316
+break;
317
+}
318 318
     }
319 319
 
320 320
     /**
Please login to merge, or discard this patch.
jaxon-annotations/src/AnnotationReader.php 1 patch
Switch Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -37,207 +37,207 @@
 block discarded – undo
37 37
 
38 38
 class AnnotationReader implements MetadataReaderInterface
39 39
 {
40
-    /**
40
+/**
41 41
      * @var AnnotationManager
42 42
      */
43
-    protected $xManager;
43
+protected $xManager;
44 44
 
45
-    /**
45
+/**
46 46
      * @var Metadata
47 47
      */
48
-    protected $xMetadata;
48
+protected $xMetadata;
49 49
 
50
-    /**
50
+/**
51 51
      * Properties types, read from the "var" annotations.
52 52
      *
53 53
      * @var array
54 54
      */
55
-    protected $aPropTypes;
55
+protected $aPropTypes;
56 56
 
57
-    /**
57
+/**
58 58
      * The type of the class member being currently processed.
59 59
      *
60 60
      * @var string
61 61
      */
62
-    protected $sCurrMemberType;
62
+protected $sCurrMemberType;
63 63
 
64
-    /**
64
+/**
65 65
      * The constructor
66 66
      *
67 67
      * @param AnnotationManager $xManager
68 68
      */
69
-    public function __construct(AnnotationManager $xManager)
70
-    {
71
-        $this->xManager = $xManager;
72
-        $this->xManager->registry['upload'] = UploadAnnotation::class;
73
-        $this->xManager->registry['databag'] = DatabagAnnotation::class;
74
-        $this->xManager->registry['exclude'] = ExcludeAnnotation::class;
75
-        $this->xManager->registry['export'] = ExportAnnotation::class;
76
-        $this->xManager->registry['before'] = BeforeAnnotation::class;
77
-        $this->xManager->registry['after'] = AfterAnnotation::class;
78
-        $this->xManager->registry['di'] = ContainerAnnotation::class;
79
-        $this->xManager->registry['callback'] = CallbackAnnotation::class;
80
-        // Missing standard annotations.
81
-        // We need to define this, otherwise they throw an exception, and make the whole processing fail.
82
-        $this->xManager->registry['const'] = false;
83
-        $this->xManager->registry['inheritDoc'] = false;
84
-        $this->xManager->registry['template'] = false;
85
-        $this->xManager->registry['param-closure-this'] = false;
86
-    }
69
+public function __construct(AnnotationManager $xManager)
70
+{
71
+$this->xManager = $xManager;
72
+$this->xManager->registry['upload'] = UploadAnnotation::class;
73
+$this->xManager->registry['databag'] = DatabagAnnotation::class;
74
+$this->xManager->registry['exclude'] = ExcludeAnnotation::class;
75
+$this->xManager->registry['export'] = ExportAnnotation::class;
76
+$this->xManager->registry['before'] = BeforeAnnotation::class;
77
+$this->xManager->registry['after'] = AfterAnnotation::class;
78
+$this->xManager->registry['di'] = ContainerAnnotation::class;
79
+$this->xManager->registry['callback'] = CallbackAnnotation::class;
80
+// Missing standard annotations.
81
+// We need to define this, otherwise they throw an exception, and make the whole processing fail.
82
+$this->xManager->registry['const'] = false;
83
+$this->xManager->registry['inheritDoc'] = false;
84
+$this->xManager->registry['template'] = false;
85
+$this->xManager->registry['param-closure-this'] = false;
86
+}
87 87
 
88
-    /**
88
+/**
89 89
      * @return array
90 90
      */
91
-    public function getPropTypes(): array
92
-    {
93
-        return $this->aPropTypes;
94
-    }
91
+public function getPropTypes(): array
92
+{
93
+return $this->aPropTypes;
94
+}
95 95
 
96
-    /**
96
+/**
97 97
      * @return bool
98 98
      */
99
-    public function annotationIsOnProperty(): bool
100
-    {
101
-        return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY;
102
-    }
99
+public function annotationIsOnProperty(): bool
100
+{
101
+return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY;
102
+}
103 103
 
104
-    /**
104
+/**
105 105
      * @param string $sClass
106 106
      *
107 107
      * @return void
108 108
      * @throws AnnotationException
109 109
      */
110
-    private function readClassAnnotations(string $sClass): void
111
-    {
112
-        // Only keep the annotations declared in this package.
113
-        /** @var array<AbstractAnnotation> */
114
-        $aAnnotations = array_filter(
115
-            $this->xManager->getClassAnnotations($sClass),
116
-            fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
117
-        );
118
-        // First check if the class is excluded.
119
-        foreach($aAnnotations as $xAnnotation)
120
-        {
121
-            if(is_a($xAnnotation, ExcludeAnnotation::class))
122
-            {
123
-                $xAnnotation->saveValue($this->xMetadata);
124
-            }
125
-        }
126
-        if($this->xMetadata->isExcluded())
127
-        {
128
-            return;
129
-        }
130
-
131
-        foreach($aAnnotations as $xAnnotation)
132
-        {
133
-            if(!is_a($xAnnotation, ExcludeAnnotation::class))
134
-            {
135
-                $xAnnotation->saveValue($this->xMetadata);
136
-            }
137
-        }
138
-    }
110
+private function readClassAnnotations(string $sClass): void
111
+{
112
+// Only keep the annotations declared in this package.
113
+/** @var array<AbstractAnnotation> */
114
+$aAnnotations = array_filter(
115
+$this->xManager->getClassAnnotations($sClass),
116
+fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
117
+);
118
+// First check if the class is excluded.
119
+foreach($aAnnotations as $xAnnotation)
120
+{
121
+if(is_a($xAnnotation, ExcludeAnnotation::class))
122
+{
123
+    $xAnnotation->saveValue($this->xMetadata);
124
+}
125
+}
126
+if($this->xMetadata->isExcluded())
127
+{
128
+return;
129
+}
139 130
 
140
-    /**
131
+foreach($aAnnotations as $xAnnotation)
132
+{
133
+if(!is_a($xAnnotation, ExcludeAnnotation::class))
134
+{
135
+    $xAnnotation->saveValue($this->xMetadata);
136
+}
137
+}
138
+}
139
+
140
+/**
141 141
      * @param string $sClass
142 142
      * @param string $sProperty
143 143
      *
144 144
      * @return void
145 145
      * @throws AnnotationException
146 146
      */
147
-    private function readPropertyAnnotations(string $sClass, string $sProperty): void
147
+private function readPropertyAnnotations(string $sClass, string $sProperty): void
148
+{
149
+/** @var array<ContainerAnnotation> */
150
+// Only keep the annotations declared in this package.
151
+$aAnnotations = array_filter(
152
+$this->xManager->getPropertyAnnotations($sClass, $sProperty),
153
+function($xAnnotation) use($sProperty) {
154
+    // Save the property type
155
+    if(is_a($xAnnotation, VarAnnotation::class))
148 156
     {
149
-        /** @var array<ContainerAnnotation> */
150
-        // Only keep the annotations declared in this package.
151
-        $aAnnotations = array_filter(
152
-            $this->xManager->getPropertyAnnotations($sClass, $sProperty),
153
-            function($xAnnotation) use($sProperty) {
154
-                // Save the property type
155
-                if(is_a($xAnnotation, VarAnnotation::class))
156
-                {
157
-                    $this->aPropTypes[$sProperty] = $xAnnotation->type;
158
-                }
159
-                // Only container annotations are allowed on properties
160
-                return is_a($xAnnotation, ContainerAnnotation::class);
161
-            }
162
-        );
163
-        if(count($aAnnotations) > 1)
164
-        {
165
-            throw new AnnotationException('Only one @di annotation is allowed on a property');
166
-        }
167
-
168
-        foreach($aAnnotations as $xAnnotation)
169
-        {
170
-            $xAnnotation->setAttr($sProperty);
171
-            $xAnnotation->saveValue($this->xMetadata);
172
-        }
157
+        $this->aPropTypes[$sProperty] = $xAnnotation->type;
173 158
     }
159
+    // Only container annotations are allowed on properties
160
+    return is_a($xAnnotation, ContainerAnnotation::class);
161
+}
162
+);
163
+if(count($aAnnotations) > 1)
164
+{
165
+throw new AnnotationException('Only one @di annotation is allowed on a property');
166
+}
167
+
168
+foreach($aAnnotations as $xAnnotation)
169
+{
170
+$xAnnotation->setAttr($sProperty);
171
+$xAnnotation->saveValue($this->xMetadata);
172
+}
173
+}
174 174
 
175
-    /**
175
+/**
176 176
      * @param string $sClass
177 177
      * @param string $sMethod
178 178
      *
179 179
      * @return void
180 180
      * @throws AnnotationException
181 181
      */
182
-    private function readMethodAnnotations(string $sClass, string $sMethod): void
183
-    {
184
-        // Only keep the annotations declared in this package.
185
-        /** @var array<AbstractAnnotation> */
186
-        $aAnnotations = array_filter(
187
-            $this->xManager->getMethodAnnotations($sClass, $sMethod),
188
-            fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
189
-        );
190
-        foreach($aAnnotations as $xAnnotation)
191
-        {
192
-            $xAnnotation->saveValue($this->xMetadata, $sMethod);
193
-        }
194
-    }
182
+private function readMethodAnnotations(string $sClass, string $sMethod): void
183
+{
184
+// Only keep the annotations declared in this package.
185
+/** @var array<AbstractAnnotation> */
186
+$aAnnotations = array_filter(
187
+$this->xManager->getMethodAnnotations($sClass, $sMethod),
188
+fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
189
+);
190
+foreach($aAnnotations as $xAnnotation)
191
+{
192
+$xAnnotation->saveValue($this->xMetadata, $sMethod);
193
+}
194
+}
195 195
 
196
-    /**
196
+/**
197 197
      * @throws SetupException
198 198
      */
199
-    public function getAttributes(InputData $xInput): Metadata
200
-    {
201
-        ContainerAnnotation::$xReader = $this;
202
-        $this->aPropTypes = [];
203
-        $this->xMetadata = new Metadata();
204
-        $sClass = $xInput->getReflectionClass()->getName();
205
-
206
-        try
207
-        {
208
-            // Processing class annotations
209
-            $this->sCurrMemberType = AnnotationManager::MEMBER_CLASS;
210
-
211
-            $this->readClassAnnotations($sClass);
212
-
213
-            // Processing properties annotations
214
-            $this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY;
215
-
216
-            // Properties annotations
217
-            foreach($xInput->getProperties() as $sProperty)
218
-            {
219
-                $this->readPropertyAnnotations($sClass, $sProperty);
220
-            }
221
-
222
-            // The methods annotations are not taken for excluded classes.
223
-            if($this->xMetadata->isExcluded())
224
-            {
225
-                return $this->xMetadata;
226
-            }
227
-
228
-            // Processing methods annotations
229
-            $this->sCurrMemberType = AnnotationManager::MEMBER_METHOD;
230
-
231
-            foreach($xInput->getMethods() as $sMethod)
232
-            {
233
-                $this->readMethodAnnotations($sClass, $sMethod);
234
-            }
235
-
236
-            return $this->xMetadata;
237
-        }
238
-        catch(AnnotationException $e)
239
-        {
240
-            throw new SetupException($e->getMessage());
241
-        }
242
-    }
199
+public function getAttributes(InputData $xInput): Metadata
200
+{
201
+ContainerAnnotation::$xReader = $this;
202
+$this->aPropTypes = [];
203
+$this->xMetadata = new Metadata();
204
+$sClass = $xInput->getReflectionClass()->getName();
205
+
206
+try
207
+{
208
+// Processing class annotations
209
+$this->sCurrMemberType = AnnotationManager::MEMBER_CLASS;
210
+
211
+$this->readClassAnnotations($sClass);
212
+
213
+// Processing properties annotations
214
+$this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY;
215
+
216
+// Properties annotations
217
+foreach($xInput->getProperties() as $sProperty)
218
+{
219
+    $this->readPropertyAnnotations($sClass, $sProperty);
220
+}
221
+
222
+// The methods annotations are not taken for excluded classes.
223
+if($this->xMetadata->isExcluded())
224
+{
225
+    return $this->xMetadata;
226
+}
227
+
228
+// Processing methods annotations
229
+$this->sCurrMemberType = AnnotationManager::MEMBER_METHOD;
230
+
231
+foreach($xInput->getMethods() as $sMethod)
232
+{
233
+    $this->readMethodAnnotations($sClass, $sMethod);
234
+}
235
+
236
+return $this->xMetadata;
237
+}
238
+catch(AnnotationException $e)
239
+{
240
+throw new SetupException($e->getMessage());
241
+}
242
+}
243 243
 }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Traits/ComponentTrait.php 1 patch
Switch Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -241,83 +241,83 @@
 block discarded – undo
241 241
                 $this->aComponentPublicMethods['node'],
242 242
             $xReflectionClass->isSubclassOf(FuncComponent::class) =>
243 243
                 $this->aComponentPublicMethods['func'],
244
-            default => [[], []],
245
-        };
244
+default => [[], []],
245
+};
246 246
 
247
-        return [$aMethods, ...$aBaseMethods];
248
-    }
247
+return [$aMethods, ...$aBaseMethods];
248
+}
249 249
 
250
-    /**
250
+/**
251 251
      * @param ReflectionClass $xReflectionClass
252 252
      * @param array $aMethods
253 253
      * @param array $aOptions
254 254
      *
255 255
      * @return Metadata|null
256 256
      */
257
-    private function getComponentMetadata(ReflectionClass $xReflectionClass,
258
-        array $aMethods, array $aOptions): Metadata|null
259
-    {
260
-        /** @var Config|null */
261
-        $xPackageConfig = $aOptions['config'] ?? null;
262
-        if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false))
263
-        {
264
-            return null;
265
-        }
266
-        $sMetadataFormat = $xPackageConfig->getOption('metadata.format');
267
-        if(!in_array($sMetadataFormat, ['attributes', 'annotations']))
268
-        {
269
-            return null;
270
-        }
257
+private function getComponentMetadata(ReflectionClass $xReflectionClass,
258
+array $aMethods, array $aOptions): Metadata|null
259
+{
260
+/** @var Config|null */
261
+$xPackageConfig = $aOptions['config'] ?? null;
262
+if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false))
263
+{
264
+return null;
265
+}
266
+$sMetadataFormat = $xPackageConfig->getOption('metadata.format');
267
+if(!in_array($sMetadataFormat, ['attributes', 'annotations']))
268
+{
269
+return null;
270
+}
271 271
 
272
-        // Try to get the class metadata from the cache.
273
-        $di = $this->cn();
274
-        $xMetadata = null;
275
-        $xMetadataCache = null;
276
-        $xConfig = $di->config();
277
-        if($xConfig->getAppOption('metadata.cache.enabled', false))
278
-        {
279
-            if(!$di->h('jaxon_metadata_cache_dir'))
280
-            {
281
-                $sCacheDir = $xConfig->getAppOption('metadata.cache.dir');
282
-                $di->val('jaxon_metadata_cache_dir', $sCacheDir);
283
-            }
284
-            $xMetadataCache = $di->getMetadataCache();
285
-            $xMetadata = $xMetadataCache->read($xReflectionClass->getName());
286
-            if($xMetadata !== null)
287
-            {
288
-                return $xMetadata;
289
-            }
290
-        }
272
+// Try to get the class metadata from the cache.
273
+$di = $this->cn();
274
+$xMetadata = null;
275
+$xMetadataCache = null;
276
+$xConfig = $di->config();
277
+if($xConfig->getAppOption('metadata.cache.enabled', false))
278
+{
279
+if(!$di->h('jaxon_metadata_cache_dir'))
280
+{
281
+    $sCacheDir = $xConfig->getAppOption('metadata.cache.dir');
282
+    $di->val('jaxon_metadata_cache_dir', $sCacheDir);
283
+}
284
+$xMetadataCache = $di->getMetadataCache();
285
+$xMetadata = $xMetadataCache->read($xReflectionClass->getName());
286
+if($xMetadata !== null)
287
+{
288
+    return $xMetadata;
289
+}
290
+}
291 291
 
292
-        $aProperties = array_map(fn($xProperty) => $xProperty->getName(),
293
-            $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC |
294
-                ReflectionProperty::IS_PROTECTED));
292
+$aProperties = array_map(fn($xProperty) => $xProperty->getName(),
293
+$xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC |
294
+    ReflectionProperty::IS_PROTECTED));
295 295
 
296
-        $xMetadataReader = $di->getMetadataReader($sMetadataFormat);
297
-        $xInput = new InputData($xReflectionClass, $aMethods, $aProperties);
298
-        $xMetadata = $xMetadataReader->getAttributes($xInput);
296
+$xMetadataReader = $di->getMetadataReader($sMetadataFormat);
297
+$xInput = new InputData($xReflectionClass, $aMethods, $aProperties);
298
+$xMetadata = $xMetadataReader->getAttributes($xInput);
299 299
 
300
-        // Try to save the metadata in the cache
301
-        if($xMetadataCache !== null)
302
-        {
303
-            $xMetadataCache->save($xReflectionClass->getName(), $xMetadata);
304
-        }
300
+// Try to save the metadata in the cache
301
+if($xMetadataCache !== null)
302
+{
303
+$xMetadataCache->save($xReflectionClass->getName(), $xMetadata);
304
+}
305 305
 
306
-        return $xMetadata;
307
-    }
306
+return $xMetadata;
307
+}
308 308
 
309
-    /**
309
+/**
310 310
      * @param ReflectionClass $xReflectionClass
311 311
      * @param array $aOptions
312 312
      *
313 313
      * @return ComponentOptions
314 314
      */
315
-    public function getComponentOptions(ReflectionClass $xReflectionClass,
316
-        array $aOptions): ComponentOptions
317
-    {
318
-        $aMethods = $this->getPublicMethods($xReflectionClass);
319
-        $xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions);
315
+public function getComponentOptions(ReflectionClass $xReflectionClass,
316
+array $aOptions): ComponentOptions
317
+{
318
+$aMethods = $this->getPublicMethods($xReflectionClass);
319
+$xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions);
320 320
 
321
-        return new ComponentOptions($aMethods, $aOptions, $xMetadata);
322
-    }
321
+return new ComponentOptions($aMethods, $aOptions, $xMetadata);
322
+}
323 323
 }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Traits/PluginTrait.php 1 patch
Switch Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -35,154 +35,154 @@  discard block
 block discarded – undo
35 35
 
36 36
 trait PluginTrait
37 37
 {
38
-    /**
38
+/**
39 39
      * Register the values into the container
40 40
      *
41 41
      * @return void
42 42
      */
43
-    private function registerPlugins(): void
44
-    {
45
-        // Plugin manager
46
-        $this->set(PluginManager::class, function($di) {
47
-            $xPluginManager = new PluginManager($di->g(Container::class),
48
-                $di->g(CodeGenerator::class), $di->g(Translator::class));
49
-            // Register the Jaxon request and response plugins
50
-            $xPluginManager->registerPlugins();
51
-            return $xPluginManager;
52
-        });
53
-        // Package manager
54
-        $this->set(PackageManager::class, function($di) {
55
-            return new PackageManager($di->g(Container::class), $di->g(Translator::class),
56
-                $di->g(PluginManager::class), $di->g(ConfigManager::class),
57
-                $di->g(CodeGenerator::class), $di->g(ViewRenderer::class),
58
-                $di->g(CallbackManager::class), $di->g(ComponentRegistry::class));
59
-        });
60
-        // Code Generation
61
-        $this->set(MinifierInterface::class, function() {
62
-            return new class extends FileMinifier implements MinifierInterface
63
-            {};
64
-        });
65
-        $this->set(AssetManager::class, function($di) {
66
-            return new AssetManager($di->g(ConfigManager::class),
67
-                $di->g(MinifierInterface::class));
68
-        });
69
-        $this->set(CodeGenerator::class, function($di) {
70
-            return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class),
71
-                $di->g(TemplateEngine::class));
72
-        });
73
-        $this->set(ConfigScriptGenerator::class, function($di) {
74
-            return new ConfigScriptGenerator($di->g(ParameterReader::class),
75
-                $di->g(TemplateEngine::class), $di->g(ConfigManager::class));
76
-        });
77
-        $this->set(ReadyScriptGenerator::class, function($di) {
78
-            return new ReadyScriptGenerator();
79
-        });
80
-
81
-        // Script response plugin
82
-        $this->set(ScriptPlugin::class, function($di) {
83
-            return new ScriptPlugin($di->g(CallFactory::class));
84
-        });
85
-        // Databag response plugin
86
-        $this->set(DatabagPlugin::class, function($di) {
87
-            return new DatabagPlugin($di->g(Container::class));
88
-        });
89
-        // Dialog response plugin
90
-        $this->set(DialogPlugin::class, function($di) {
91
-            return new DialogPlugin($di->g(DialogCommand::class));
92
-        });
93
-        // Paginator response plugin
94
-        $this->set(PaginatorPlugin::class, function($di) {
95
-            return new PaginatorPlugin($di->g(RendererInterface::class));
96
-        });
97
-    }
98
-
99
-    /**
43
+private function registerPlugins(): void
44
+{
45
+// Plugin manager
46
+$this->set(PluginManager::class, function($di) {
47
+$xPluginManager = new PluginManager($di->g(Container::class),
48
+    $di->g(CodeGenerator::class), $di->g(Translator::class));
49
+// Register the Jaxon request and response plugins
50
+$xPluginManager->registerPlugins();
51
+return $xPluginManager;
52
+});
53
+// Package manager
54
+$this->set(PackageManager::class, function($di) {
55
+return new PackageManager($di->g(Container::class), $di->g(Translator::class),
56
+    $di->g(PluginManager::class), $di->g(ConfigManager::class),
57
+    $di->g(CodeGenerator::class), $di->g(ViewRenderer::class),
58
+    $di->g(CallbackManager::class), $di->g(ComponentRegistry::class));
59
+});
60
+// Code Generation
61
+$this->set(MinifierInterface::class, function() {
62
+return new class extends FileMinifier implements MinifierInterface
63
+{};
64
+});
65
+$this->set(AssetManager::class, function($di) {
66
+return new AssetManager($di->g(ConfigManager::class),
67
+    $di->g(MinifierInterface::class));
68
+});
69
+$this->set(CodeGenerator::class, function($di) {
70
+return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class),
71
+    $di->g(TemplateEngine::class));
72
+});
73
+$this->set(ConfigScriptGenerator::class, function($di) {
74
+return new ConfigScriptGenerator($di->g(ParameterReader::class),
75
+    $di->g(TemplateEngine::class), $di->g(ConfigManager::class));
76
+});
77
+$this->set(ReadyScriptGenerator::class, function($di) {
78
+return new ReadyScriptGenerator();
79
+});
80
+
81
+// Script response plugin
82
+$this->set(ScriptPlugin::class, function($di) {
83
+return new ScriptPlugin($di->g(CallFactory::class));
84
+});
85
+// Databag response plugin
86
+$this->set(DatabagPlugin::class, function($di) {
87
+return new DatabagPlugin($di->g(Container::class));
88
+});
89
+// Dialog response plugin
90
+$this->set(DialogPlugin::class, function($di) {
91
+return new DialogPlugin($di->g(DialogCommand::class));
92
+});
93
+// Paginator response plugin
94
+$this->set(PaginatorPlugin::class, function($di) {
95
+return new PaginatorPlugin($di->g(RendererInterface::class));
96
+});
97
+}
98
+
99
+/**
100 100
      * Get the plugin manager
101 101
      *
102 102
      * @return PluginManager
103 103
      */
104
-    public function getPluginManager(): PluginManager
105
-    {
106
-        return $this->g(PluginManager::class);
107
-    }
104
+public function getPluginManager(): PluginManager
105
+{
106
+return $this->g(PluginManager::class);
107
+}
108 108
 
109
-    /**
109
+/**
110 110
      * Get the package manager
111 111
      *
112 112
      * @return PackageManager
113 113
      */
114
-    public function getPackageManager(): PackageManager
115
-    {
116
-        return $this->g(PackageManager::class);
117
-    }
114
+public function getPackageManager(): PackageManager
115
+{
116
+return $this->g(PackageManager::class);
117
+}
118 118
 
119
-    /**
119
+/**
120 120
      * Get the code generator
121 121
      *
122 122
      * @return CodeGenerator
123 123
      */
124
-    public function getCodeGenerator(): CodeGenerator
125
-    {
126
-        return $this->g(CodeGenerator::class);
127
-    }
124
+public function getCodeGenerator(): CodeGenerator
125
+{
126
+return $this->g(CodeGenerator::class);
127
+}
128 128
 
129
-    /**
129
+/**
130 130
      * Get the asset manager
131 131
      *
132 132
      * @return AssetManager
133 133
      */
134
-    public function getAssetManager(): AssetManager
135
-    {
136
-        return $this->g(AssetManager::class);
137
-    }
134
+public function getAssetManager(): AssetManager
135
+{
136
+return $this->g(AssetManager::class);
137
+}
138 138
 
139
-    /**
139
+/**
140 140
      * Get the jQuery plugin
141 141
      *
142 142
      * @return ScriptPlugin
143 143
      */
144
-    public function getScriptPlugin(): ScriptPlugin
145
-    {
146
-        return $this->g(ScriptPlugin::class);
147
-    }
144
+public function getScriptPlugin(): ScriptPlugin
145
+{
146
+return $this->g(ScriptPlugin::class);
147
+}
148 148
 
149
-    /**
149
+/**
150 150
      * Get the dialog plugin
151 151
      *
152 152
      * @return DialogPlugin
153 153
      */
154
-    public function getDialogPlugin(): DialogPlugin
155
-    {
156
-        return $this->g(DialogPlugin::class);
157
-    }
154
+public function getDialogPlugin(): DialogPlugin
155
+{
156
+return $this->g(DialogPlugin::class);
157
+}
158 158
 
159
-    /**
159
+/**
160 160
      * @param class-string $sClassName    The package class name
161 161
      *
162 162
      * @return string
163 163
      */
164
-    private function getPackageConfigKey(string $sClassName): string
165
-    {
166
-        return $sClassName . '_PackageConfig';
167
-    }
164
+private function getPackageConfigKey(string $sClassName): string
165
+{
166
+return $sClassName . '_PackageConfig';
167
+}
168 168
 
169
-    /**
169
+/**
170 170
      * @param class-string $sClassName    The package class name
171 171
      * @param-closure-this AbstractPackage $cSetter
172 172
      *
173 173
      * @return void
174 174
      */
175
-    private function extendPackage(string $sClassName, Closure $cSetter): void
176
-    {
177
-        // Initialize the package instance.
178
-        $this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) {
179
-            // Allow the setter to access protected attributes.
180
-            call_user_func($cSetter->bindTo($xPackage, $xPackage));
181
-            return $xPackage;
182
-        });
183
-    }
184
-
185
-    /**
175
+private function extendPackage(string $sClassName, Closure $cSetter): void
176
+{
177
+// Initialize the package instance.
178
+$this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) {
179
+// Allow the setter to access protected attributes.
180
+call_user_func($cSetter->bindTo($xPackage, $xPackage));
181
+return $xPackage;
182
+});
183
+}
184
+
185
+/**
186 186
      * Register a package
187 187
      *
188 188
      * @param class-string $sClassName    The package class name
@@ -191,45 +191,45 @@  discard block
 block discarded – undo
191 191
      * @return void
192 192
      * @throws SetupException
193 193
      */
194
-    public function registerPackage(string $sClassName, array $aUserOptions): void
195
-    {
196
-        // Register the user class, but only if the user didn't already.
197
-        if(!$this->h($sClassName))
198
-        {
199
-            $this->set($sClassName, fn() => $this->make($sClassName));
200
-        }
201
-
202
-        // Save the package config in the container.
203
-        $sConfigKey = $this->getPackageConfigKey($sClassName);
204
-        $this->set($sConfigKey, function($di) use($aUserOptions) {
205
-            $xOptionsProvider = $aUserOptions['provider'] ?? null;
206
-            // The user can provide a callable that returns the package options.
207
-            if(is_callable($xOptionsProvider))
208
-            {
209
-                $aUserOptions = $xOptionsProvider($aUserOptions);
210
-            }
211
-            return $di->g(ConfigManager::class)->newConfig($aUserOptions);
212
-        });
213
-
214
-        // Initialize the package instance.
215
-        $di = $this;
216
-        $this->extendPackage($sClassName, function() use($di, $sConfigKey) {
217
-            // $this here refers to the AbstractPackage instance.
218
-            $this->xPkgConfig = $di->g($sConfigKey);
219
-            $this->xRenderer = $di->g(ViewRenderer::class);
220
-            $this->init();
221
-        });
222
-    }
223
-
224
-    /**
194
+public function registerPackage(string $sClassName, array $aUserOptions): void
195
+{
196
+// Register the user class, but only if the user didn't already.
197
+if(!$this->h($sClassName))
198
+{
199
+$this->set($sClassName, fn() => $this->make($sClassName));
200
+}
201
+
202
+// Save the package config in the container.
203
+$sConfigKey = $this->getPackageConfigKey($sClassName);
204
+$this->set($sConfigKey, function($di) use($aUserOptions) {
205
+$xOptionsProvider = $aUserOptions['provider'] ?? null;
206
+// The user can provide a callable that returns the package options.
207
+if(is_callable($xOptionsProvider))
208
+{
209
+    $aUserOptions = $xOptionsProvider($aUserOptions);
210
+}
211
+return $di->g(ConfigManager::class)->newConfig($aUserOptions);
212
+});
213
+
214
+// Initialize the package instance.
215
+$di = $this;
216
+$this->extendPackage($sClassName, function() use($di, $sConfigKey) {
217
+// $this here refers to the AbstractPackage instance.
218
+$this->xPkgConfig = $di->g($sConfigKey);
219
+$this->xRenderer = $di->g(ViewRenderer::class);
220
+$this->init();
221
+});
222
+}
223
+
224
+/**
225 225
      * Get the config of a package
226 226
      *
227 227
      * @param class-string $sClassName    The package class name
228 228
      *
229 229
      * @return Config
230 230
      */
231
-    public function getPackageConfig(string $sClassName): Config
232
-    {
233
-        return $this->g($this->getPackageConfigKey($sClassName));
234
-    }
231
+public function getPackageConfig(string $sClassName): Config
232
+{
233
+return $this->g($this->getPackageConfigKey($sClassName));
234
+}
235 235
 }
Please login to merge, or discard this patch.