node-dependency-injection 4.0.0-alpha.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +16 -0
- package/.github/workflows/build.yml +24 -0
- package/.github/workflows/publish.yml +43 -0
- package/.mocharc.yaml +0 -1
- package/CHANGELOG-3.md +6 -1
- package/CONTRIBUTING.md +2 -2
- package/README.md +340 -112
- package/UPGRADE-3.0.md +4 -1
- package/UPGRADE-4.0.md +50 -0
- package/assets/logo.png +0 -0
- package/bin/Resources/services.yaml +7 -0
- package/bin/Services/File/XmlAdapter.js +53 -0
- package/bin/ndi-config:create.js +2 -1
- package/bin/ndi-container:graph.js +82 -0
- package/bin/ndi-container:service.js +5 -0
- package/bin/ndi-container:validate.js +120 -0
- package/bin/ndi.js +2 -0
- package/dist/bin/Resources/services.yaml +7 -0
- package/dist/bin/Services/File/BaseAdapter.js +1 -50
- package/dist/bin/Services/File/FileManager.js +1 -55
- package/dist/bin/Services/File/JsAdapter.js +1 -62
- package/dist/bin/Services/File/JsonAdapter.js +1 -60
- package/dist/bin/Services/File/XmlAdapter.js +1 -0
- package/dist/bin/Services/File/YamlAdapter.js +1 -67
- package/dist/bin/ndi-config:check.js +1 -55
- package/dist/bin/ndi-config:create.js +1 -40
- package/dist/bin/ndi-container:graph.js +2 -0
- package/dist/bin/ndi-container:service.js +1 -131
- package/dist/bin/ndi-container:validate.js +2 -0
- package/dist/bin/ndi.js +1 -9
- package/dist/lib/Autowire.js +1 -281
- package/dist/lib/AutowireIdentifier.js +1 -0
- package/dist/lib/Compiler.js +1 -101
- package/dist/lib/CompilerPass/AutowireOverridePass.js +1 -0
- package/dist/lib/CompilerPass/DecoratePass.js +1 -118
- package/dist/lib/CompilerPass/OptimizePass.js +1 -60
- package/dist/lib/CompilerPass/RemovePass.js +1 -57
- package/dist/lib/CompilerPass/index.js +1 -131
- package/dist/lib/Condition.js +1 -0
- package/dist/lib/ContainerBuilder.js +1 -463
- package/dist/lib/ContainerValidator.js +1 -0
- package/dist/lib/Definition.js +1 -371
- package/dist/lib/Dump/Dumper.js +1 -0
- package/dist/lib/Dump/JsDumper.js +1 -0
- package/dist/lib/Dump/JsonDumper.js +1 -0
- package/dist/lib/Dump/XmlDumper.js +1 -0
- package/dist/lib/Dump/YamlDumper.js +1 -0
- package/dist/lib/Exception/AbstractServiceException.js +1 -47
- package/dist/lib/Exception/AttributesMapException.js +1 -44
- package/dist/lib/Exception/CannotAutowireOverrideSearch.js +1 -0
- package/dist/lib/Exception/ConfigurationFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ContainerDefaultDirMustBeSet.js +1 -0
- package/dist/lib/Exception/ContainerValidationError.js +1 -0
- package/dist/lib/Exception/DefinitionNotFoundException.js +1 -47
- package/dist/lib/Exception/FrozenContainerException.js +1 -44
- package/dist/lib/Exception/KeyedGroupNoDefaultException.js +1 -0
- package/dist/lib/Exception/KeyedGroupNotFoundException.js +1 -0
- package/dist/lib/Exception/KeyedServiceNotFoundException.js +1 -0
- package/dist/lib/Exception/LoadMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/LoggerWarnMethodNotFoundException.js +1 -44
- package/dist/lib/Exception/MethodCallEmptyException.js +1 -44
- package/dist/lib/Exception/MethodCallNotFoundException.js +1 -47
- package/dist/lib/Exception/NotAbstractServiceException.js +1 -47
- package/dist/lib/Exception/PrivateServiceException.js +1 -47
- package/dist/lib/Exception/ProcessMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/RootDirectoryMustBeAbsolute.js +1 -0
- package/dist/lib/Exception/RootDirectoryNotFound.js +1 -0
- package/dist/lib/Exception/ServiceCircularReferenceException.js +1 -44
- package/dist/lib/Exception/ServiceFileNotAbsolute.js +1 -0
- package/dist/lib/Exception/ServiceFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotLoadedException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotValidExtension.js +1 -0
- package/dist/lib/Exception/ServiceNotFoundException.js +1 -48
- package/dist/lib/Exception/UnableToGetInstanceFromId.js +1 -0
- package/dist/lib/Exception/WrongCompilerPassTypeException.js +1 -47
- package/dist/lib/Exception/WrongDefinitionException.js +1 -44
- package/dist/lib/GraphExporter.js +1 -0
- package/dist/lib/InstanceManager.js +1 -363
- package/dist/lib/KeyedGroupReference.js +1 -0
- package/dist/lib/KeyedReference.js +1 -0
- package/dist/lib/Loader/Argument.js +1 -0
- package/dist/lib/Loader/FileLoader.js +1 -417
- package/dist/lib/Loader/JsFileLoader.js +1 -68
- package/dist/lib/Loader/JsonFileLoader.js +1 -40
- package/dist/lib/Loader/XmlFileLoader.js +1 -0
- package/dist/lib/Loader/YamlFileLoader.js +1 -88
- package/dist/lib/LoggerHelper.js +1 -0
- package/dist/lib/PackageReference.js +1 -37
- package/dist/lib/ParameterReference.js +1 -0
- package/dist/lib/PassConfig.js +1 -78
- package/dist/lib/Reference.js +1 -49
- package/dist/lib/ServiceFile.js +1 -0
- package/dist/lib/TagReference.js +1 -37
- package/dist/lib/ValidationResult.js +1 -0
- package/dist/lib/index.js +1 -79
- package/dist/lib/schema/services.xsd +163 -0
- package/dist/lib/types/index.d.ts +218 -10
- package/dist/lib/types/tests.ts +36 -2
- package/package.json +25 -11
- package/tsconfig.json +8 -1
- package/.travis.yml +0 -14
|
@@ -1,463 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _path = _interopRequireDefault(require("path"));
|
|
19
|
-
|
|
20
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
21
|
-
|
|
22
|
-
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
23
|
-
|
|
24
|
-
var _PassConfig = _interopRequireDefault(require("./PassConfig"));
|
|
25
|
-
|
|
26
|
-
var _Compiler = _interopRequireDefault(require("./Compiler"));
|
|
27
|
-
|
|
28
|
-
var _CompilerPass = _interopRequireDefault(require("./CompilerPass"));
|
|
29
|
-
|
|
30
|
-
var _InstanceManager = _interopRequireDefault(require("./InstanceManager"));
|
|
31
|
-
|
|
32
|
-
var _DefinitionNotFoundException = _interopRequireDefault(require("./Exception/DefinitionNotFoundException"));
|
|
33
|
-
|
|
34
|
-
var _LoadMethodNotFoundException = _interopRequireDefault(require("./Exception/LoadMethodNotFoundException"));
|
|
35
|
-
|
|
36
|
-
var _LoggerWarnMethodNotFoundException = _interopRequireDefault(require("./Exception/LoggerWarnMethodNotFoundException"));
|
|
37
|
-
|
|
38
|
-
var _WrongDefinitionException = _interopRequireDefault(require("./Exception/WrongDefinitionException"));
|
|
39
|
-
|
|
40
|
-
var _FrozenContainerException = _interopRequireDefault(require("./Exception/FrozenContainerException"));
|
|
41
|
-
|
|
42
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
43
|
-
|
|
44
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
45
|
-
|
|
46
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
47
|
-
|
|
48
|
-
var ContainerBuilder = /*#__PURE__*/function () {
|
|
49
|
-
/**
|
|
50
|
-
* @param {boolean} containerReferenceAsService
|
|
51
|
-
* @param {String} defaultDir
|
|
52
|
-
*/
|
|
53
|
-
function ContainerBuilder() {
|
|
54
|
-
var containerReferenceAsService = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
55
|
-
var defaultDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
56
|
-
(0, _classCallCheck2["default"])(this, ContainerBuilder);
|
|
57
|
-
this.ensureIsAbsolute(defaultDir);
|
|
58
|
-
this.ensureDirectoryExists(defaultDir);
|
|
59
|
-
this._definitions = new Map();
|
|
60
|
-
this._parameters = new Map();
|
|
61
|
-
this._alias = new Map();
|
|
62
|
-
this._container = new Map();
|
|
63
|
-
this._frozen = false;
|
|
64
|
-
this._compilerPass = new _CompilerPass["default"](this);
|
|
65
|
-
this._extensions = [];
|
|
66
|
-
this._logger = console;
|
|
67
|
-
this._instanceManager = undefined;
|
|
68
|
-
this._containerReferenceAsService = containerReferenceAsService;
|
|
69
|
-
this._defaultDir = defaultDir;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
(0, _createClass2["default"])(ContainerBuilder, [{
|
|
73
|
-
key: "ensureDirectoryExists",
|
|
74
|
-
value: function ensureDirectoryExists(directory) {
|
|
75
|
-
if (directory && _fs["default"].existsSync(directory) === false) {
|
|
76
|
-
throw new Error('Root directory not found');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
key: "ensureIsAbsolute",
|
|
81
|
-
value: function ensureIsAbsolute(directory) {
|
|
82
|
-
if (directory && _path["default"].isAbsolute(directory) === false) {
|
|
83
|
-
throw new Error('Root directory must be absolute');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* @returns {String}
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
}, {
|
|
91
|
-
key: "defaultDir",
|
|
92
|
-
get: function get() {
|
|
93
|
-
return this._defaultDir;
|
|
94
|
-
},
|
|
95
|
-
set: function set(value) {
|
|
96
|
-
this.ensureIsAbsolute(value);
|
|
97
|
-
this.ensureDirectoryExists(value);
|
|
98
|
-
this._defaultDir = value;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @returns {boolean}
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
}, {
|
|
105
|
-
key: "containerReferenceAsService",
|
|
106
|
-
get: function get() {
|
|
107
|
-
return this._containerReferenceAsService;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @returns {Map}
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
}, {
|
|
114
|
-
key: "definitions",
|
|
115
|
-
get: function get() {
|
|
116
|
-
return this._definitions;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* @returns {boolean}
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
}, {
|
|
123
|
-
key: "frozen",
|
|
124
|
-
get: function get() {
|
|
125
|
-
return this._frozen;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @param {boolean} value
|
|
129
|
-
*/
|
|
130
|
-
,
|
|
131
|
-
set: function set(value) {
|
|
132
|
-
this._frozen = value;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* @return {InstanceManager}
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
}, {
|
|
139
|
-
key: "instanceManager",
|
|
140
|
-
get: function get() {
|
|
141
|
-
if (!this._instanceManager) {
|
|
142
|
-
this._instanceManager = new _InstanceManager["default"](this, this._definitions, this._alias);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return this._instanceManager;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @returns {Array}
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
}, {
|
|
152
|
-
key: "extensions",
|
|
153
|
-
get: function get() {
|
|
154
|
-
return this._extensions;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @returns {Console|*}
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
}, {
|
|
161
|
-
key: "logger",
|
|
162
|
-
get: function get() {
|
|
163
|
-
return this._logger;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* @param {Console|*} value
|
|
167
|
-
*/
|
|
168
|
-
,
|
|
169
|
-
set: function set(value) {
|
|
170
|
-
if (typeof value.warn !== 'function') {
|
|
171
|
-
throw new _LoggerWarnMethodNotFoundException["default"]();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this._logger = value;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* @return {Map}
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
}, {
|
|
181
|
-
key: "services",
|
|
182
|
-
get: function get() {
|
|
183
|
-
return this._container;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* @param {string} id
|
|
187
|
-
* @param {*|null} object
|
|
188
|
-
* @param {Array} args
|
|
189
|
-
* @returns {Definition}
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
}, {
|
|
193
|
-
key: "register",
|
|
194
|
-
value: function register(id) {
|
|
195
|
-
var object = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
196
|
-
var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
197
|
-
|
|
198
|
-
if (!this.frozen) {
|
|
199
|
-
var definition = new _Definition["default"]();
|
|
200
|
-
definition.Object = object;
|
|
201
|
-
definition.args = args;
|
|
202
|
-
|
|
203
|
-
if (!object) {
|
|
204
|
-
definition.synthetic = true;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return this.setDefinition(id, definition);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
throw new _FrozenContainerException["default"]();
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* @param {string|} id
|
|
214
|
-
*/
|
|
215
|
-
|
|
216
|
-
}, {
|
|
217
|
-
key: "get",
|
|
218
|
-
value: function get(id) {
|
|
219
|
-
return this.instanceManager.getInstance(id);
|
|
220
|
-
}
|
|
221
|
-
}, {
|
|
222
|
-
key: "compile",
|
|
223
|
-
value: function compile() {
|
|
224
|
-
new _Compiler["default"](this).run();
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* @param {*} compilerPass
|
|
228
|
-
* @param {string} type
|
|
229
|
-
* @param {number} priority
|
|
230
|
-
*/
|
|
231
|
-
|
|
232
|
-
}, {
|
|
233
|
-
key: "addCompilerPass",
|
|
234
|
-
value: function addCompilerPass(compilerPass) {
|
|
235
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _PassConfig["default"].TYPE_BEFORE_OPTIMIZATION;
|
|
236
|
-
var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
237
|
-
|
|
238
|
-
this._compilerPass.register(compilerPass, type, priority);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* @param {string} alias
|
|
242
|
-
* @param {string} id
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
}, {
|
|
246
|
-
key: "setAlias",
|
|
247
|
-
value: function setAlias(alias, id) {
|
|
248
|
-
this._alias.set(alias, id);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* @param {string} alias
|
|
252
|
-
* @returns {boolean}
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
}, {
|
|
256
|
-
key: "hasAlias",
|
|
257
|
-
value: function hasAlias(alias) {
|
|
258
|
-
return this._alias.has(alias);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* @param {string} id
|
|
262
|
-
* @param {Definition} definition
|
|
263
|
-
* @returns {Definition}
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
}, {
|
|
267
|
-
key: "setDefinition",
|
|
268
|
-
value: function setDefinition(id, definition) {
|
|
269
|
-
if (definition instanceof _Definition["default"]) {
|
|
270
|
-
this._definitions.set(id, definition);
|
|
271
|
-
|
|
272
|
-
return definition;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
throw new _WrongDefinitionException["default"]();
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* @param {string} name
|
|
279
|
-
* @returns {Map}
|
|
280
|
-
*/
|
|
281
|
-
|
|
282
|
-
}, {
|
|
283
|
-
key: "findTaggedServiceIds",
|
|
284
|
-
value: function findTaggedServiceIds(name) {
|
|
285
|
-
var taggedServices = new Map();
|
|
286
|
-
|
|
287
|
-
var _iterator = _createForOfIteratorHelper(this._definitions),
|
|
288
|
-
_step;
|
|
289
|
-
|
|
290
|
-
try {
|
|
291
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
292
|
-
var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
|
|
293
|
-
id = _step$value[0],
|
|
294
|
-
definition = _step$value[1];
|
|
295
|
-
|
|
296
|
-
if (definition.tags.some(function (tag) {
|
|
297
|
-
return tag.name === name;
|
|
298
|
-
})) {
|
|
299
|
-
taggedServices.set(id, definition);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
} catch (err) {
|
|
303
|
-
_iterator.e(err);
|
|
304
|
-
} finally {
|
|
305
|
-
_iterator.f();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return taggedServices;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* @param {string} key
|
|
312
|
-
* @param {string||Array|boolean|Object} value
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
}, {
|
|
316
|
-
key: "setParameter",
|
|
317
|
-
value: function setParameter(key, value) {
|
|
318
|
-
if (typeof value !== 'string' && !Array.isArray(value) && typeof value !== 'boolean' && (0, _typeof2["default"])(value) !== 'object') {
|
|
319
|
-
throw new TypeError('The expected value is not a flat string, an array, a boolean or an object');
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
this._parameters.set(key, value);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* @param {string} key
|
|
326
|
-
* @returns {string|Array}
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
}, {
|
|
330
|
-
key: "getParameter",
|
|
331
|
-
value: function getParameter(key) {
|
|
332
|
-
return this._parameters.get(key);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* @param {string} key
|
|
336
|
-
* @returns {boolean}
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
}, {
|
|
340
|
-
key: "hasParameter",
|
|
341
|
-
value: function hasParameter(key) {
|
|
342
|
-
return this._parameters.has(key);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* @param {string} key
|
|
346
|
-
* @returns {boolean}
|
|
347
|
-
*/
|
|
348
|
-
|
|
349
|
-
}, {
|
|
350
|
-
key: "hasDefinition",
|
|
351
|
-
value: function hasDefinition(key) {
|
|
352
|
-
return this._definitions.has(key);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* @param {string} key
|
|
356
|
-
* @returns {boolean}
|
|
357
|
-
*/
|
|
358
|
-
|
|
359
|
-
}, {
|
|
360
|
-
key: "has",
|
|
361
|
-
value: function has(key) {
|
|
362
|
-
return this._definitions.has(key) || this._parameters.has(key) || this._alias.has(key);
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* @param {string} method
|
|
366
|
-
* @param {string} key
|
|
367
|
-
* @returns {Definition|boolean}
|
|
368
|
-
* @private
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
}, {
|
|
372
|
-
key: "_definition",
|
|
373
|
-
value: function _definition(method, key) {
|
|
374
|
-
if (this._definitions.has(key)) {
|
|
375
|
-
return this._definitions[method](key);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
throw new _DefinitionNotFoundException["default"](key);
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* @param {string} key
|
|
382
|
-
* @returns {Definition}
|
|
383
|
-
*/
|
|
384
|
-
|
|
385
|
-
}, {
|
|
386
|
-
key: "getDefinition",
|
|
387
|
-
value: function getDefinition(key) {
|
|
388
|
-
return this._definition('get', key);
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* @param {string} key
|
|
392
|
-
* @returns {boolean}
|
|
393
|
-
*/
|
|
394
|
-
|
|
395
|
-
}, {
|
|
396
|
-
key: "removeDefinition",
|
|
397
|
-
value: function removeDefinition(key) {
|
|
398
|
-
return this._definition('delete', key);
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* @param {string} key
|
|
402
|
-
* @returns {Definition}
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
|
-
}, {
|
|
406
|
-
key: "findDefinition",
|
|
407
|
-
value: function findDefinition(key) {
|
|
408
|
-
key = this._alias.get(key) || key;
|
|
409
|
-
|
|
410
|
-
if (this._definitions.has(key)) {
|
|
411
|
-
return this._definitions.get(key);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
throw new _DefinitionNotFoundException["default"](key);
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* @param {*} extension
|
|
418
|
-
*/
|
|
419
|
-
|
|
420
|
-
}, {
|
|
421
|
-
key: "registerExtension",
|
|
422
|
-
value: function registerExtension(extension) {
|
|
423
|
-
if (typeof extension.load !== 'function') {
|
|
424
|
-
throw new _LoadMethodNotFoundException["default"](extension.constructor.name);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
this._extensions.push(extension);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* @param {string} id
|
|
431
|
-
* @param {*} instance
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
}, {
|
|
435
|
-
key: "set",
|
|
436
|
-
value: function set(id, instance) {
|
|
437
|
-
this._container.set(id, instance);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* @param {string} id
|
|
441
|
-
*/
|
|
442
|
-
|
|
443
|
-
}, {
|
|
444
|
-
key: "remove",
|
|
445
|
-
value: function remove(id) {
|
|
446
|
-
this._container["delete"](id);
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* @param {string} id
|
|
450
|
-
* @returns {boolean}
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
}, {
|
|
454
|
-
key: "isSet",
|
|
455
|
-
value: function isSet(id) {
|
|
456
|
-
return this._container.has(id);
|
|
457
|
-
}
|
|
458
|
-
}]);
|
|
459
|
-
return ContainerBuilder;
|
|
460
|
-
}();
|
|
461
|
-
|
|
462
|
-
var _default = ContainerBuilder;
|
|
463
|
-
exports["default"] = _default;
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _path=_interopRequireDefault(require("path"));var _fs=_interopRequireDefault(require("fs"));var _Definition=_interopRequireDefault(require("./Definition"));var _PassConfig=_interopRequireDefault(require("./PassConfig"));var _Compiler=_interopRequireDefault(require("./Compiler"));var _CompilerPass=_interopRequireDefault(require("./CompilerPass"));var _InstanceManager=_interopRequireDefault(require("./InstanceManager"));var _DefinitionNotFoundException=_interopRequireDefault(require("./Exception/DefinitionNotFoundException"));var _LoadMethodNotFoundException=_interopRequireDefault(require("./Exception/LoadMethodNotFoundException"));var _LoggerWarnMethodNotFoundException=_interopRequireDefault(require("./Exception/LoggerWarnMethodNotFoundException"));var _WrongDefinitionException=_interopRequireDefault(require("./Exception/WrongDefinitionException"));var _FrozenContainerException=_interopRequireDefault(require("./Exception/FrozenContainerException"));var _RootDirectoryNotFound=_interopRequireDefault(require("./Exception/RootDirectoryNotFound"));var _RootDirectoryMustBeAbsolute=_interopRequireDefault(require("./Exception/RootDirectoryMustBeAbsolute"));var _KeyedGroupNotFoundException=_interopRequireDefault(require("./Exception/KeyedGroupNotFoundException"));var _KeyedServiceNotFoundException=_interopRequireDefault(require("./Exception/KeyedServiceNotFoundException"));var _KeyedGroupNoDefaultException=_interopRequireDefault(require("./Exception/KeyedGroupNoDefaultException"));var _ServiceFile=_interopRequireDefault(require("./ServiceFile"));var _LoggerHelper=_interopRequireDefault(require("./LoggerHelper"));var _ContainerValidator=_interopRequireDefault(require("./ContainerValidator"));var _ContainerValidationError=_interopRequireDefault(require("./Exception/ContainerValidationError"));var _GraphExporter=_interopRequireDefault(require("./GraphExporter"));function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var ContainerBuilder=function(){function ContainerBuilder(){var containerReferenceAsService=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var defaultDir=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;(0,_classCallCheck2["default"])(this,ContainerBuilder);this.ensureIsAbsolute(defaultDir);this.ensureDirectoryExists(defaultDir);this._definitions=new Map();this._parameters=new Map();this._alias=new Map();this._container=new Map();this._objectToId=new Map();this._frozen=false;this._compilerPass=new _CompilerPass["default"](this);this._extensions=[];this._logger=console;this._verbosity='warn';this._loggerHelper=new _LoggerHelper["default"](this._logger,this._verbosity);this._instanceManager=undefined;this._containerReferenceAsService=containerReferenceAsService;this._defaultDir=defaultDir;this._autowire=null;this._binds=new Map();this._keyedGroups=new Map();}return(0,_createClass2["default"])(ContainerBuilder,[{key:"autowire",get:function get(){return this._autowire;},set:function set(autowire){this._autowire=autowire;}},{key:"binds",get:function get(){return this._binds;}},{key:"addBind",value:function addBind(name,value){this._binds.set(name,value);}},{key:"ensureDirectoryExists",value:function ensureDirectoryExists(directory){if(directory&&_fs["default"].existsSync(directory)===false){throw new _RootDirectoryNotFound["default"]();}}},{key:"ensureIsAbsolute",value:function ensureIsAbsolute(directory){if(directory&&_path["default"].isAbsolute(directory)===false){throw new _RootDirectoryMustBeAbsolute["default"]();}}},{key:"defaultDir",get:function get(){return this._defaultDir;},set:function set(value){this.ensureIsAbsolute(value);this.ensureDirectoryExists(value);this._defaultDir=value;}},{key:"containerReferenceAsService",get:function get(){return this._containerReferenceAsService;}},{key:"definitions",get:function get(){return this._definitions;}},{key:"objectToId",get:function get(){return this._objectToId;}},{key:"frozen",get:function get(){return this._frozen;},set:function set(value){this._frozen=value;}},{key:"instanceManager",get:function get(){if(!this._instanceManager){this._instanceManager=new _InstanceManager["default"](this,this._definitions,this._alias);}return this._instanceManager;}},{key:"extensions",get:function get(){return this._extensions;}},{key:"logger",get:function get(){return this._logger;},set:function set(value){if(typeof value.warn!=='function'){throw new _LoggerWarnMethodNotFoundException["default"]();}this._logger=value;this._loggerHelper=new _LoggerHelper["default"](this._logger,this._verbosity);}},{key:"verbosity",get:function get(){return this._verbosity;},set:function set(value){this._verbosity=value;this._loggerHelper=new _LoggerHelper["default"](this._logger,this._verbosity);}},{key:"loggerHelper",get:function get(){return this._loggerHelper;}},{key:"services",get:function get(){return this._container;}},{key:"register",value:function register(id){var object=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var args=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];if(!this.frozen){var definition=new _Definition["default"]();definition.Object=object;definition.args=args;if(!object){definition.synthetic=true;}return this.setDefinition(id,definition);}throw new _FrozenContainerException["default"]();}},{key:"get",value:function get(id){return this.instanceManager.getInstance(id);}},{key:"registerKeyed",value:function registerKeyed(group,key){var object=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var args=arguments.length>3&&arguments[3]!==undefined?arguments[3]:[];var id="".concat(group,".").concat(key);var definition=this.register(id,object,args);definition.keyedGroup=group;definition.keyedKey=key;this._addToKeyedGroup(group,key,id);return definition;}},{key:"_addToKeyedGroup",value:function _addToKeyedGroup(group,key,id){if(!this._keyedGroups.has(group)){this._keyedGroups.set(group,new Map());}this._keyedGroups.get(group).set(key,id);}},{key:"getKeyed",value:function getKeyed(group){var key=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var groupMap=this._keyedGroups.get(group);if(!groupMap){throw new _KeyedGroupNotFoundException["default"](group);}if(key!==null){var id=groupMap.get(key);if(!id){throw new _KeyedServiceNotFoundException["default"](group,key);}return this.get(id);}var _iterator=_createForOfIteratorHelper(groupMap),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _step$value=(0,_slicedToArray2["default"])(_step.value,2),_id=_step$value[1];var definition=this._definitions.get(_id);if(definition&&definition.keyedDefault){return this.get(_id);}}}catch(err){_iterator.e(err);}finally{_iterator.f();}throw new _KeyedGroupNoDefaultException["default"](group);}},{key:"getKeyedGroup",value:function getKeyedGroup(group){var groupMap=this._keyedGroups.get(group);if(!groupMap){throw new _KeyedGroupNotFoundException["default"](group);}var result=new Map();var _iterator2=_createForOfIteratorHelper(groupMap),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _step2$value=(0,_slicedToArray2["default"])(_step2.value,2),key=_step2$value[0],id=_step2$value[1];result.set(key,this.get(id));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return result;}},{key:"compile",value:function(){var _compile=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(){var _this$_autowire;var options,validationResult,shouldValidateAfterCompile,validator,_validator,_args=arguments;return _regenerator["default"].wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:options=_args.length>0&&_args[0]!==undefined?_args[0]:{};shouldValidateAfterCompile=false;if(!(options.validate===true)){_context.next=10;break;}validator=new _ContainerValidator["default"](this);validationResult=validator.validate();if(validationResult.isValid){_context.next=9;break;}if(!(options.throwOnError!==false)){_context.next=8;break;}throw new _ContainerValidationError["default"](validationResult);case 8:return _context.abrupt("return",validationResult);case 9:shouldValidateAfterCompile=true;case 10:_context.next=12;return new _Compiler["default"](this).run();case 12:if(!shouldValidateAfterCompile){_context.next=17;break;}_validator=new _ContainerValidator["default"](this);validationResult=_validator.validate();if(!(!validationResult.isValid&&options.throwOnError!==false)){_context.next=17;break;}throw new _ContainerValidationError["default"](validationResult);case 17:if(!(((_this$_autowire=this._autowire)===null||_this$_autowire===void 0?void 0:_this$_autowire.serviceFile)instanceof _ServiceFile["default"])){_context.next=20;break;}_context.next=20;return this._autowire.serviceFile.generateFromContainer(this);case 20:return _context.abrupt("return",validationResult);case 21:case"end":return _context.stop();}},_callee,this);}));function compile(){return _compile.apply(this,arguments);}return compile;}()},{key:"exportGraph",value:function exportGraph(){var format=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'mermaid';var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return new _GraphExporter["default"](this)["export"](format,options);}},{key:"addCompilerPass",value:function addCompilerPass(compilerPass){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:_PassConfig["default"].TYPE_BEFORE_OPTIMIZATION;var priority=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;this._compilerPass.register(compilerPass,type,priority);}},{key:"setAlias",value:function setAlias(alias,id){this._alias.set(alias,id);}},{key:"hasAlias",value:function hasAlias(alias){return this._alias.has(alias);}},{key:"setDefinition",value:function setDefinition(id,definition){if(definition instanceof _Definition["default"]){this._definitions.set(id,definition);if(definition.Object){if(!this._objectToId.has(definition.Object)){this._objectToId.set(definition.Object,new Set());}this._objectToId.get(definition.Object).add(id);}return definition;}throw new _WrongDefinitionException["default"]();}},{key:"findTaggedServiceIds",value:_regenerator["default"].mark(function findTaggedServiceIds(name){var _iterator3,_step3,_step3$value,id,definition;return _regenerator["default"].wrap(function findTaggedServiceIds$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:_iterator3=_createForOfIteratorHelper(this._definitions);_context2.prev=1;_iterator3.s();case 3:if((_step3=_iterator3.n()).done){_context2.next=10;break;}_step3$value=(0,_slicedToArray2["default"])(_step3.value,2),id=_step3$value[0],definition=_step3$value[1];if(!definition.tags.some(function(tag){return tag.name===name;})){_context2.next=8;break;}_context2.next=8;return{id:id,definition:definition};case 8:_context2.next=3;break;case 10:_context2.next=15;break;case 12:_context2.prev=12;_context2.t0=_context2["catch"](1);_iterator3.e(_context2.t0);case 15:_context2.prev=15;_iterator3.f();return _context2.finish(15);case 18:case"end":return _context2.stop();}},findTaggedServiceIds,this,[[1,12,15,18]]);})},{key:"setParameter",value:function setParameter(key,value){if(typeof value!=='string'&&!Array.isArray(value)&&typeof value!=='boolean'&&(0,_typeof2["default"])(value)!=='object'){throw new TypeError('The expected value is not a flat string, an array, a boolean or an object');}this._parameters.set(key,value);}},{key:"getParameter",value:function getParameter(key){return this._parameters.get(key);}},{key:"hasParameter",value:function hasParameter(key){return this._parameters.has(key);}},{key:"hasDefinition",value:function hasDefinition(key){return this._definitions.has(key);}},{key:"has",value:function has(key){return this._definitions.has(key)||this._parameters.has(key)||this._alias.has(key);}},{key:"_definition",value:function _definition(method,key){if(this._definitions.has(key)){return this._definitions[method](key);}throw new _DefinitionNotFoundException["default"](key);}},{key:"getDefinition",value:function getDefinition(key){return this._definition('get',key);}},{key:"removeDefinition",value:function removeDefinition(key){if(this._definitions.has(key)){var definition=this._definitions.get(key);if(definition.Object){var ids=this._objectToId.get(definition.Object);if(ids){ids["delete"](key);if(ids.size===0){this._objectToId["delete"](definition.Object);}}}return this._definitions["delete"](key);}throw new _DefinitionNotFoundException["default"](key);}},{key:"findDefinition",value:(function(){var _findDefinition=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(key){return _regenerator["default"].wrap(function _callee2$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:key=this._alias.get(key)||key;if(!this._definitions.has(key)){_context3.next=3;break;}return _context3.abrupt("return",this._definitions.get(key));case 3:throw new _DefinitionNotFoundException["default"](key);case 4:case"end":return _context3.stop();}},_callee2,this);}));function findDefinition(_x){return _findDefinition.apply(this,arguments);}return findDefinition;}())},{key:"registerExtension",value:function registerExtension(extension){if(typeof extension.load!=='function'){throw new _LoadMethodNotFoundException["default"](extension.constructor.name);}this._extensions.push(extension);}},{key:"set",value:function set(id,instance){this._container.set(id,instance);}},{key:"remove",value:function remove(id){this._container["delete"](id);}},{key:"isSet",value:function isSet(id){return this._container.has(id);}}]);}();var _default=exports["default"]=ContainerBuilder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _Reference=_interopRequireDefault(require("./Reference"));var _TagReference=_interopRequireDefault(require("./TagReference"));var _ParameterReference=_interopRequireDefault(require("./ParameterReference"));var _ValidationResult=_interopRequireDefault(require("./ValidationResult"));function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var ContainerValidator=exports["default"]=function(){function ContainerValidator(container){(0,_classCallCheck2["default"])(this,ContainerValidator);this._container=container;}return(0,_createClass2["default"])(ContainerValidator,[{key:"validate",value:function validate(){var result=new _ValidationResult["default"]();result.serviceCount=this._container.definitions.size;this._checkMissingDependencies(result);this._checkCircularDependencies(result);this._checkUnresolvedParameters(result);this._checkUnusedNullableFallbacks(result);this._checkDeprecatedServicesInUse(result);this._checkOrphanTaggedServices(result);this._checkKeyedGroupsWithNoDefault(result);return result;}},{key:"_checkMissingDependencies",value:function _checkMissingDependencies(result){var _iterator=_createForOfIteratorHelper(this._container.definitions),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _step$value=(0,_slicedToArray2["default"])(_step.value,2),id=_step$value[0],definition=_step$value[1];if(definition["abstract"]||definition.synthetic){continue;}var allArgs=this._collectAllArgs(definition);var _iterator2=_createForOfIteratorHelper(allArgs),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var arg=_step2.value;if(arg instanceof _Reference["default"]&&!arg.nullable){var refId=arg.id;if(!this._serviceExists(refId)){result.addError('missing_dependency',id,"@".concat(refId),"Service '".concat(id,"' references undefined service '@").concat(refId,"'"));}}}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}}}catch(err){_iterator.e(err);}finally{_iterator.f();}}},{key:"_checkCircularDependencies",value:function _checkCircularDependencies(result){var definitions=this._container.definitions;var visited=new Set();var reported=new Set();var _iterator3=_createForOfIteratorHelper(definitions.keys()),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var id=_step3.value;if(visited.has(id)){continue;}var cycle=this._detectCycle(id,[],new Set(),definitions);if(cycle){var cycleKey=cycle.join(' → ');if(!reported.has(cycleKey)){reported.add(cycleKey);result.addError('circular_dependency',cycle[0],cycleKey,"Circular dependency detected: ".concat(cycleKey));}}visited.add(id);}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}},{key:"_detectCycle",value:function _detectCycle(id,path,inStack,definitions){if(inStack.has(id)){var cycleStart=path.indexOf(id);return[].concat((0,_toConsumableArray2["default"])(path.slice(cycleStart)),[id]);}if(!definitions.has(id)){return null;}inStack.add(id);path.push(id);var definition=definitions.get(id);var deps=this._getDirectServiceDeps(definition);var _iterator4=_createForOfIteratorHelper(deps),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var depId=_step4.value;var cycle=this._detectCycle(depId,path,inStack,definitions);if(cycle){return cycle;}}}catch(err){_iterator4.e(err);}finally{_iterator4.f();}path.pop();inStack["delete"](id);return null;}},{key:"_getDirectServiceDeps",value:function _getDirectServiceDeps(definition){var deps=[];var allArgs=this._collectAllArgs(definition);var _iterator5=_createForOfIteratorHelper(allArgs),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var arg=_step5.value;if(arg instanceof _Reference["default"]){deps.push(this._resolveAlias(arg.id));}}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}return deps;}},{key:"_checkUnresolvedParameters",value:function _checkUnresolvedParameters(result){var _iterator6=_createForOfIteratorHelper(this._container.definitions),_step6;try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var _step6$value=(0,_slicedToArray2["default"])(_step6.value,2),id=_step6$value[0],definition=_step6$value[1];if(definition["abstract"]||definition.synthetic){continue;}var allArgs=this._collectAllArgs(definition);var _iterator7=_createForOfIteratorHelper(allArgs),_step7;try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){var arg=_step7.value;if(arg instanceof _ParameterReference["default"]){if(!this._container.hasParameter(arg.key)){result.addError('unresolved_parameter',id,"%".concat(arg.key,"%"),"Service '".concat(id,"' uses undefined parameter '%").concat(arg.key,"%'"));}}}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}}}catch(err){_iterator6.e(err);}finally{_iterator6.f();}}},{key:"_checkUnusedNullableFallbacks",value:function _checkUnusedNullableFallbacks(result){var _iterator8=_createForOfIteratorHelper(this._container.definitions),_step8;try{for(_iterator8.s();!(_step8=_iterator8.n()).done;){var _step8$value=(0,_slicedToArray2["default"])(_step8.value,2),id=_step8$value[0],definition=_step8$value[1];if(definition["abstract"]||definition.synthetic){continue;}var allArgs=this._collectAllArgs(definition);var _iterator9=_createForOfIteratorHelper(allArgs),_step9;try{for(_iterator9.s();!(_step9=_iterator9.n()).done;){var arg=_step9.value;if(arg instanceof _Reference["default"]&&arg.nullable){var refId=arg.id;if(this._serviceExists(refId)){result.addWarning('unused_nullable_fallback',id,"@?".concat(refId),"Service '".concat(id,"' uses a nullable reference to '@").concat(refId,"' but it always exists (dead optional)"));}}}}catch(err){_iterator9.e(err);}finally{_iterator9.f();}}}catch(err){_iterator8.e(err);}finally{_iterator8.f();}}},{key:"_checkDeprecatedServicesInUse",value:function _checkDeprecatedServicesInUse(result){var definitions=this._container.definitions;var _iterator0=_createForOfIteratorHelper(definitions),_step0;try{for(_iterator0.s();!(_step0=_iterator0.n()).done;){var _step0$value=(0,_slicedToArray2["default"])(_step0.value,2),id=_step0$value[0],definition=_step0$value[1];if(definition.deprecated||definition["abstract"]||definition.synthetic){continue;}var allArgs=this._collectAllArgs(definition);var _iterator1=_createForOfIteratorHelper(allArgs),_step1;try{for(_iterator1.s();!(_step1=_iterator1.n()).done;){var arg=_step1.value;if(arg instanceof _Reference["default"]){var refId=this._resolveAlias(arg.id);if(definitions.has(refId)){var refDef=definitions.get(refId);if(refDef.deprecated){result.addWarning('deprecated_service_in_use',id,"@".concat(refId),"'".concat(id,"' uses deprecated service '@").concat(refId,"': ").concat(refDef.deprecated));}}}}}catch(err){_iterator1.e(err);}finally{_iterator1.f();}}}catch(err){_iterator0.e(err);}finally{_iterator0.f();}}},{key:"_checkOrphanTaggedServices",value:function _checkOrphanTaggedServices(result){var usedTags=new Set();var _iterator10=_createForOfIteratorHelper(this._container.definitions.values()),_step10;try{for(_iterator10.s();!(_step10=_iterator10.n()).done;){var definition=_step10.value;var allArgs=this._collectAllArgs(definition);var _iterator13=_createForOfIteratorHelper(allArgs),_step13;try{for(_iterator13.s();!(_step13=_iterator13.n()).done;){var arg=_step13.value;if(arg instanceof _TagReference["default"]){usedTags.add(arg.name);}}}catch(err){_iterator13.e(err);}finally{_iterator13.f();}}}catch(err){_iterator10.e(err);}finally{_iterator10.f();}var definedTags=new Map();var _iterator11=_createForOfIteratorHelper(this._container.definitions),_step11;try{for(_iterator11.s();!(_step11=_iterator11.n()).done;){var _step11$value=(0,_slicedToArray2["default"])(_step11.value,2),id=_step11$value[0],_definition=_step11$value[1];var _iterator14=_createForOfIteratorHelper(_definition.tags),_step14;try{for(_iterator14.s();!(_step14=_iterator14.n()).done;){var tag=_step14.value;if(!definedTags.has(tag.name)){definedTags.set(tag.name,[]);}definedTags.get(tag.name).push(id);}}catch(err){_iterator14.e(err);}finally{_iterator14.f();}}}catch(err){_iterator11.e(err);}finally{_iterator11.f();}var _iterator12=_createForOfIteratorHelper(definedTags),_step12;try{for(_iterator12.s();!(_step12=_iterator12.n()).done;){var _step12$value=(0,_slicedToArray2["default"])(_step12.value,1),tagName=_step12$value[0];if(!usedTags.has(tagName)){result.addInfo('orphan_tagged_service','',"tag:".concat(tagName),"Tag '".concat(tagName,"' is defined on services but no consumer uses it via TagReference"));}}}catch(err){_iterator12.e(err);}finally{_iterator12.f();}}},{key:"_checkKeyedGroupsWithNoDefault",value:function _checkKeyedGroupsWithNoDefault(result){var tagGroups=new Map();var _iterator15=_createForOfIteratorHelper(this._container.definitions),_step15;try{for(_iterator15.s();!(_step15=_iterator15.n()).done;){var _step15$value=(0,_slicedToArray2["default"])(_step15.value,2),id=_step15$value[0],definition=_step15$value[1];var _iterator17=_createForOfIteratorHelper(definition.tags),_step17;try{for(_iterator17.s();!(_step17=_iterator17.n()).done;){var tag=_step17.value;if(!tagGroups.has(tag.name)){tagGroups.set(tag.name,[]);}tagGroups.get(tag.name).push({id:id,attributes:tag.attributes});}}catch(err){_iterator17.e(err);}finally{_iterator17.f();}}}catch(err){_iterator15.e(err);}finally{_iterator15.f();}var _iterator16=_createForOfIteratorHelper(tagGroups),_step16;try{for(_iterator16.s();!(_step16=_iterator16.n()).done;){var _step16$value=(0,_slicedToArray2["default"])(_step16.value,2),tagName=_step16$value[0],services=_step16$value[1];if(services.length>1){var hasDefault=services.some(function(s){return s.attributes&&s.attributes.get('default')===true;});if(!hasDefault){result.addInfo('keyed_group_no_default','',"tag:".concat(tagName),"Tag group '".concat(tagName,"' has ").concat(services.length," services but none has 'default: true' (autowiring ambiguity)"));}}}}catch(err){_iterator16.e(err);}finally{_iterator16.f();}}},{key:"_collectAllArgs",value:function _collectAllArgs(definition){var args=[];var _iterator18=_createForOfIteratorHelper(definition.args),_step18;try{for(_iterator18.s();!(_step18=_iterator18.n()).done;){var arg=_step18.value;args.push(arg);}}catch(err){_iterator18.e(err);}finally{_iterator18.f();}var _iterator19=_createForOfIteratorHelper(definition.appendArgs),_step19;try{for(_iterator19.s();!(_step19=_iterator19.n()).done;){var _arg=_step19.value;args.push(_arg);}}catch(err){_iterator19.e(err);}finally{_iterator19.f();}var _iterator20=_createForOfIteratorHelper(this._collectParentAppendArgs(definition.parent)),_step20;try{for(_iterator20.s();!(_step20=_iterator20.n()).done;){var _arg2=_step20.value;args.push(_arg2);}}catch(err){_iterator20.e(err);}finally{_iterator20.f();}var _iterator21=_createForOfIteratorHelper(definition.calls),_step21;try{for(_iterator21.s();!(_step21=_iterator21.n()).done;){var call=_step21.value;var _iterator23=_createForOfIteratorHelper(call.args),_step23;try{for(_iterator23.s();!(_step23=_iterator23.n()).done;){var _arg3=_step23.value;args.push(_arg3);}}catch(err){_iterator23.e(err);}finally{_iterator23.f();}}}catch(err){_iterator21.e(err);}finally{_iterator21.f();}var _iterator22=_createForOfIteratorHelper(definition.properties),_step22;try{for(_iterator22.s();!(_step22=_iterator22.n()).done;){var _step22$value=(0,_slicedToArray2["default"])(_step22.value,2),value=_step22$value[1];args.push(value);}}catch(err){_iterator22.e(err);}finally{_iterator22.f();}if(definition.factory&&definition.factory.Object instanceof _Reference["default"]){args.push(definition.factory.Object);}return args;}},{key:"_serviceExists",value:function _serviceExists(id){var resolvedId=this._resolveAlias(id);return this._container.definitions.has(resolvedId)||resolvedId==='service_container'&&this._container.containerReferenceAsService;}},{key:"_resolveAlias",value:function _resolveAlias(id){var definitions=this._container.definitions;var alias=this._container._alias;if(!alias||definitions.has(id)){return id;}var resolvedId=id;var seen=new Set();while(!definitions.has(resolvedId)&&alias.has(resolvedId)){if(seen.has(resolvedId)){return resolvedId;}seen.add(resolvedId);resolvedId=alias.get(resolvedId);}return resolvedId;}},{key:"_collectParentAppendArgs",value:function _collectParentAppendArgs(definitionParent){if(!definitionParent||!this._container.definitions.has(definitionParent)){return[];}var parentDefinition=this._container.definitions.get(definitionParent);var args=(0,_toConsumableArray2["default"])(parentDefinition.appendArgs);if(parentDefinition.parent){args.push.apply(args,(0,_toConsumableArray2["default"])(this._collectParentAppendArgs(parentDefinition.parent)));}return args;}}]);}();
|