orionis 0.391.0__py3-none-any.whl → 0.393.0__py3-none-any.whl
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.
- config/__init__.py +0 -0
- config/app.py +79 -0
- orionis/__init__.py +4 -2
- orionis/foundation/application.py +771 -7
- orionis/foundation/contracts/application.py +470 -1
- orionis/metadata/framework.py +1 -1
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/METADATA +1 -1
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/RECORD +12 -10
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/top_level.txt +1 -0
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/WHEEL +0 -0
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.391.0.dist-info → orionis-0.393.0.dist-info}/zip-safe +0 -0
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any, List, Type
|
|
2
2
|
from orionis.container.container import Container
|
|
3
3
|
from orionis.container.contracts.service_provider import IServiceProvider
|
|
4
|
-
from orionis.foundation.config.
|
|
4
|
+
from orionis.foundation.config.app.entities.app import App
|
|
5
|
+
from orionis.foundation.config.auth.entities.auth import Auth
|
|
6
|
+
from orionis.foundation.config.cache.entities.cache import Cache
|
|
7
|
+
from orionis.foundation.config.cors.entities.cors import Cors
|
|
8
|
+
from orionis.foundation.config.database.entities.database import Database
|
|
9
|
+
from orionis.foundation.config.filesystems.entitites.filesystems import Filesystems
|
|
10
|
+
from orionis.foundation.config.logging.entities.logging import Logging
|
|
11
|
+
from orionis.foundation.config.mail.entities.mail import Mail
|
|
12
|
+
from orionis.foundation.config.queue.entities.queue import Queue
|
|
13
|
+
from orionis.foundation.config.session.entities.session import Session
|
|
14
|
+
from orionis.foundation.config.startup import Configuration
|
|
15
|
+
from orionis.foundation.config.testing.entities.testing import Testing
|
|
5
16
|
from orionis.foundation.contracts.application import IApplication
|
|
6
17
|
|
|
7
18
|
class Application(Container, IApplication):
|
|
@@ -47,6 +58,8 @@ class Application(Container, IApplication):
|
|
|
47
58
|
# Singleton pattern - prevent multiple initializations
|
|
48
59
|
if not hasattr(self, '_Application__initialized'):
|
|
49
60
|
self.__providers: List[IServiceProvider] = []
|
|
61
|
+
self.__configurators : dict = {}
|
|
62
|
+
self.__config: dict = {}
|
|
50
63
|
self.__booted: bool = False
|
|
51
64
|
self.__initialized = True
|
|
52
65
|
|
|
@@ -144,14 +157,13 @@ class Application(Container, IApplication):
|
|
|
144
157
|
-------
|
|
145
158
|
Application
|
|
146
159
|
The application instance for method chaining
|
|
147
|
-
|
|
148
|
-
Examples
|
|
149
|
-
--------
|
|
150
|
-
>>> app.withProviders([CustomProvider, AnotherProvider])
|
|
151
160
|
"""
|
|
161
|
+
|
|
152
162
|
# Add each provider class
|
|
153
163
|
for provider_cls in providers:
|
|
154
164
|
self.addProvider(provider_cls)
|
|
165
|
+
|
|
166
|
+
# Return self instance for method chaining
|
|
155
167
|
return self
|
|
156
168
|
|
|
157
169
|
def addProvider(
|
|
@@ -176,14 +188,718 @@ class Application(Container, IApplication):
|
|
|
176
188
|
TypeError
|
|
177
189
|
If provider is not a subclass of IServiceProvider
|
|
178
190
|
"""
|
|
191
|
+
|
|
179
192
|
# Validate provider type
|
|
180
193
|
if not isinstance(provider, type) or not issubclass(provider, IServiceProvider):
|
|
181
194
|
raise TypeError(f"Expected IServiceProvider class, got {type(provider).__name__}")
|
|
182
195
|
|
|
183
196
|
# Instantiate and add provider
|
|
184
197
|
self.__providers.append(provider(self))
|
|
198
|
+
|
|
199
|
+
# Return self instance.
|
|
200
|
+
return self
|
|
201
|
+
|
|
202
|
+
def withConfigurators(
|
|
203
|
+
self,
|
|
204
|
+
*,
|
|
205
|
+
app: App = None,
|
|
206
|
+
auth: Auth = None,
|
|
207
|
+
cache : Cache = None,
|
|
208
|
+
cors : Cors = None,
|
|
209
|
+
database : Database = None,
|
|
210
|
+
filesystems : Filesystems = None,
|
|
211
|
+
logging : Logging = None,
|
|
212
|
+
mail : Mail = None,
|
|
213
|
+
queue : Queue = None,
|
|
214
|
+
session : Session = None,
|
|
215
|
+
testing : Testing = None,
|
|
216
|
+
) -> 'Application':
|
|
217
|
+
"""
|
|
218
|
+
Configure the application with various service configurators.
|
|
219
|
+
This method allows you to set up different aspects of the application by providing
|
|
220
|
+
configurator instances for various services like authentication, caching, database,
|
|
221
|
+
etc. If no configurator is provided for a service, a default instance will be created.
|
|
222
|
+
Parameters
|
|
223
|
+
----------
|
|
224
|
+
app : App, optional
|
|
225
|
+
Application configurator instance. If None, creates a default App() instance.
|
|
226
|
+
auth : Auth, optional
|
|
227
|
+
Authentication configurator instance. If None, creates a default Auth() instance.
|
|
228
|
+
cache : Cache, optional
|
|
229
|
+
Cache configurator instance. If None, creates a default Cache() instance.
|
|
230
|
+
cors : Cors, optional
|
|
231
|
+
CORS configurator instance. If None, creates a default Cors() instance.
|
|
232
|
+
database : Database, optional
|
|
233
|
+
Database configurator instance. If None, creates a default Database() instance.
|
|
234
|
+
filesystems : Filesystems, optional
|
|
235
|
+
Filesystems configurator instance. If None, creates a default Filesystems() instance.
|
|
236
|
+
logging : Logging, optional
|
|
237
|
+
Logging configurator instance. If None, creates a default Logging() instance.
|
|
238
|
+
mail : Mail, optional
|
|
239
|
+
Mail configurator instance. If None, creates a default Mail() instance.
|
|
240
|
+
queue : Queue, optional
|
|
241
|
+
Queue configurator instance. If None, creates a default Queue() instance.
|
|
242
|
+
session : Session, optional
|
|
243
|
+
Session configurator instance. If None, creates a default Session() instance.
|
|
244
|
+
testing : Testing, optional
|
|
245
|
+
Testing configurator instance. If None, creates a default Testing() instance.
|
|
246
|
+
Returns
|
|
247
|
+
-------
|
|
248
|
+
Application
|
|
249
|
+
Returns self to allow method chaining.
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
# Load each configurator with default or provided instances
|
|
253
|
+
self.loadConfigApp(app or App())
|
|
254
|
+
self.loadConfigAuth(auth or Auth())
|
|
255
|
+
self.loadConfigCache(cache or Cache())
|
|
256
|
+
self.loadConfigCors(cors or Cors())
|
|
257
|
+
self.loadConfigDatabase(database or Database())
|
|
258
|
+
self.loadConfigFilesystems(filesystems or Filesystems())
|
|
259
|
+
self.loadConfigLogging(logging or Logging())
|
|
260
|
+
self.loadConfigMail(mail or Mail())
|
|
261
|
+
self.loadConfigQueue(queue or Queue())
|
|
262
|
+
self.loadConfigSession(session or Session())
|
|
263
|
+
self.loadConfigTesting(testing or Testing())
|
|
264
|
+
|
|
265
|
+
# Return self instance for method chaining
|
|
266
|
+
return self
|
|
267
|
+
|
|
268
|
+
def configApp(self, **app_config) -> 'Application':
|
|
269
|
+
"""
|
|
270
|
+
Configure the application with various settings.
|
|
271
|
+
|
|
272
|
+
Parameters
|
|
273
|
+
----------
|
|
274
|
+
**app_config : dict
|
|
275
|
+
Configuration parameters for the application. Must match the fields
|
|
276
|
+
expected by the App dataclass (orionis.foundation.config.app.entities.app.App).
|
|
277
|
+
|
|
278
|
+
Returns
|
|
279
|
+
-------
|
|
280
|
+
Application
|
|
281
|
+
The application instance for method chaining
|
|
282
|
+
"""
|
|
283
|
+
|
|
284
|
+
# Create App instance with provided parameters
|
|
285
|
+
app = App(**app_config)
|
|
286
|
+
|
|
287
|
+
# Load configuration using App instance
|
|
288
|
+
self.loadConfigApp(app)
|
|
289
|
+
|
|
290
|
+
# Return the application instance for method chaining
|
|
291
|
+
return self
|
|
292
|
+
|
|
293
|
+
def loadConfigApp(
|
|
294
|
+
self,
|
|
295
|
+
app: App
|
|
296
|
+
) -> 'Application':
|
|
297
|
+
"""
|
|
298
|
+
Load the application configuration from an App instance.
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
config : App
|
|
303
|
+
The App instance containing application configuration
|
|
304
|
+
|
|
305
|
+
Returns
|
|
306
|
+
-------
|
|
307
|
+
Application
|
|
308
|
+
The application instance for method chaining
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
# Validate config type
|
|
312
|
+
if not isinstance(app, App):
|
|
313
|
+
raise TypeError(f"Expected App instance, got {type(app).__name__}")
|
|
314
|
+
|
|
315
|
+
# Store the configuration
|
|
316
|
+
self.__configurators['app'] = app
|
|
317
|
+
|
|
318
|
+
# Return the application instance for method chaining
|
|
319
|
+
return self
|
|
320
|
+
|
|
321
|
+
def configAuth(self, **auth_config) -> 'Application':
|
|
322
|
+
"""
|
|
323
|
+
Configure the authentication with various settings.
|
|
324
|
+
|
|
325
|
+
Parameters
|
|
326
|
+
----------
|
|
327
|
+
**auth_config : dict
|
|
328
|
+
Configuration parameters for authentication. Must match the fields
|
|
329
|
+
expected by the Auth dataclass (orionis.foundation.config.auth.entities.auth.Auth).
|
|
330
|
+
|
|
331
|
+
Returns
|
|
332
|
+
-------
|
|
333
|
+
Application
|
|
334
|
+
The application instance for method chaining
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
# Create Auth instance with provided parameters
|
|
338
|
+
auth = Auth(**auth_config)
|
|
339
|
+
|
|
340
|
+
# Load configuration using Auth instance
|
|
341
|
+
self.loadConfigAuth(auth)
|
|
342
|
+
|
|
343
|
+
# Return the application instance for method chaining
|
|
344
|
+
return self
|
|
345
|
+
|
|
346
|
+
def loadConfigAuth(
|
|
347
|
+
self,
|
|
348
|
+
auth: Auth
|
|
349
|
+
) -> 'Application':
|
|
350
|
+
"""
|
|
351
|
+
Load the application authentication configuration from an Auth instance.
|
|
352
|
+
|
|
353
|
+
Parameters
|
|
354
|
+
----------
|
|
355
|
+
auth : Auth
|
|
356
|
+
The Auth instance containing authentication configuration
|
|
357
|
+
|
|
358
|
+
Returns
|
|
359
|
+
-------
|
|
360
|
+
Application
|
|
361
|
+
The application instance for method chaining
|
|
362
|
+
"""
|
|
363
|
+
|
|
364
|
+
# Validate auth type
|
|
365
|
+
if not isinstance(auth, Auth):
|
|
366
|
+
raise TypeError(f"Expected Auth instance, got {type(auth).__name__}")
|
|
367
|
+
|
|
368
|
+
# Store the configuration
|
|
369
|
+
self.__configurators['auth'] = auth
|
|
370
|
+
|
|
371
|
+
# Return the application instance for method chaining
|
|
372
|
+
return self
|
|
373
|
+
|
|
374
|
+
def configCache(self, **cache_config) -> 'Application':
|
|
375
|
+
"""
|
|
376
|
+
Configure the cache with various settings.
|
|
377
|
+
|
|
378
|
+
Parameters
|
|
379
|
+
----------
|
|
380
|
+
**cache_config : dict
|
|
381
|
+
Configuration parameters for cache. Must match the fields
|
|
382
|
+
expected by the Cache dataclass (orionis.foundation.config.cache.entities.cache.Cache).
|
|
383
|
+
|
|
384
|
+
Returns
|
|
385
|
+
-------
|
|
386
|
+
Application
|
|
387
|
+
The application instance for method chaining
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
# Create Cache instance with provided parameters
|
|
391
|
+
cache = Cache(**cache_config)
|
|
392
|
+
|
|
393
|
+
# Load configuration using Cache instance
|
|
394
|
+
self.loadConfigCache(cache)
|
|
395
|
+
|
|
396
|
+
# Return the application instance for method chaining
|
|
397
|
+
return self
|
|
398
|
+
|
|
399
|
+
def loadConfigCache(
|
|
400
|
+
self,
|
|
401
|
+
cache: Cache
|
|
402
|
+
) -> 'Application':
|
|
403
|
+
"""
|
|
404
|
+
Load the application cache configuration from a Cache instance.
|
|
405
|
+
|
|
406
|
+
Parameters
|
|
407
|
+
----------
|
|
408
|
+
cache : Cache
|
|
409
|
+
The Cache instance containing cache configuration
|
|
410
|
+
|
|
411
|
+
Returns
|
|
412
|
+
-------
|
|
413
|
+
Application
|
|
414
|
+
The application instance for method chaining
|
|
415
|
+
"""
|
|
416
|
+
|
|
417
|
+
# Validate cache type
|
|
418
|
+
if not isinstance(cache, Cache):
|
|
419
|
+
raise TypeError(f"Expected Cache instance, got {type(cache).__name__}")
|
|
420
|
+
|
|
421
|
+
# Store the configuration
|
|
422
|
+
self.__configurators['cache'] = cache
|
|
423
|
+
|
|
424
|
+
# Return the application instance for method chaining
|
|
425
|
+
return self
|
|
426
|
+
|
|
427
|
+
def configCors(self, **cors_config) -> 'Application':
|
|
428
|
+
"""
|
|
429
|
+
Configure the CORS with various settings.
|
|
430
|
+
|
|
431
|
+
Parameters
|
|
432
|
+
----------
|
|
433
|
+
**cors_config : dict
|
|
434
|
+
Configuration parameters for CORS. Must match the fields
|
|
435
|
+
expected by the Cors dataclass (orionis.foundation.config.cors.entities.cors.Cors).
|
|
436
|
+
|
|
437
|
+
Returns
|
|
438
|
+
-------
|
|
439
|
+
Application
|
|
440
|
+
The application instance for method chaining
|
|
441
|
+
"""
|
|
442
|
+
|
|
443
|
+
# Create Cors instance with provided parameters
|
|
444
|
+
cors = Cors(**cors_config)
|
|
445
|
+
|
|
446
|
+
# Load configuration using Cors instance
|
|
447
|
+
self.loadConfigCors(cors)
|
|
448
|
+
|
|
449
|
+
# Return the application instance for method chaining
|
|
450
|
+
return self
|
|
451
|
+
|
|
452
|
+
def loadConfigCors(
|
|
453
|
+
self,
|
|
454
|
+
cors: Cors
|
|
455
|
+
) -> 'Application':
|
|
456
|
+
"""
|
|
457
|
+
Load the application CORS configuration from a Cors instance.
|
|
458
|
+
|
|
459
|
+
Parameters
|
|
460
|
+
----------
|
|
461
|
+
cors : Cors
|
|
462
|
+
The Cors instance containing CORS configuration
|
|
463
|
+
|
|
464
|
+
Returns
|
|
465
|
+
-------
|
|
466
|
+
Application
|
|
467
|
+
The application instance for method chaining
|
|
468
|
+
"""
|
|
469
|
+
|
|
470
|
+
# Validate cors type
|
|
471
|
+
if not isinstance(cors, Cors):
|
|
472
|
+
raise TypeError(f"Expected Cors instance, got {type(cors).__name__}")
|
|
473
|
+
|
|
474
|
+
# Store the configuration
|
|
475
|
+
self.__configurators['cors'] = cors
|
|
476
|
+
|
|
477
|
+
# Return the application instance for method chaining
|
|
478
|
+
return self
|
|
479
|
+
|
|
480
|
+
def configDatabase(
|
|
481
|
+
self,
|
|
482
|
+
**database_config
|
|
483
|
+
) -> 'Application':
|
|
484
|
+
"""
|
|
485
|
+
Configure the database with various settings.
|
|
486
|
+
|
|
487
|
+
Parameters
|
|
488
|
+
----------
|
|
489
|
+
**database_config : dict
|
|
490
|
+
Configuration parameters for database. Must match the fields
|
|
491
|
+
expected by the Database dataclass (orionis.foundation.config.database.entities.database.Database).
|
|
492
|
+
|
|
493
|
+
Returns
|
|
494
|
+
-------
|
|
495
|
+
Application
|
|
496
|
+
The application instance for method chaining
|
|
497
|
+
"""
|
|
498
|
+
|
|
499
|
+
# Create Database instance with provided parameters
|
|
500
|
+
database = Database(**database_config)
|
|
501
|
+
|
|
502
|
+
# Load configuration using Database instance
|
|
503
|
+
self.loadConfigDatabase(database)
|
|
504
|
+
|
|
505
|
+
# Return the application instance for method chaining
|
|
506
|
+
return self
|
|
507
|
+
|
|
508
|
+
def loadConfigDatabase(
|
|
509
|
+
self,
|
|
510
|
+
database: Database
|
|
511
|
+
) -> 'Application':
|
|
512
|
+
"""
|
|
513
|
+
Load the application database configuration from a Database instance.
|
|
514
|
+
|
|
515
|
+
Parameters
|
|
516
|
+
----------
|
|
517
|
+
database : Database
|
|
518
|
+
The Database instance containing database configuration
|
|
519
|
+
|
|
520
|
+
Returns
|
|
521
|
+
-------
|
|
522
|
+
Application
|
|
523
|
+
The application instance for method chaining
|
|
524
|
+
"""
|
|
525
|
+
|
|
526
|
+
# Validate database type
|
|
527
|
+
if not isinstance(database, Database):
|
|
528
|
+
raise TypeError(f"Expected Database instance, got {type(database).__name__}")
|
|
529
|
+
|
|
530
|
+
# Store the configuration
|
|
531
|
+
self.__configurators['database'] = database
|
|
532
|
+
|
|
533
|
+
# Return the application instance for method chaining
|
|
534
|
+
return self
|
|
535
|
+
|
|
536
|
+
def configFilesystems(
|
|
537
|
+
self,
|
|
538
|
+
**filesystems_config
|
|
539
|
+
) -> 'Application':
|
|
540
|
+
"""
|
|
541
|
+
Configure the filesystems with various settings.
|
|
542
|
+
|
|
543
|
+
Parameters
|
|
544
|
+
----------
|
|
545
|
+
**filesystems_config : dict
|
|
546
|
+
Configuration parameters for filesystems. Must match the fields
|
|
547
|
+
expected by the Filesystems dataclass (orionis.foundation.config.filesystems.entitites.filesystems.Filesystems).
|
|
548
|
+
|
|
549
|
+
Returns
|
|
550
|
+
-------
|
|
551
|
+
Application
|
|
552
|
+
The application instance for method chaining
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
# Create Filesystems instance with provided parameters
|
|
556
|
+
filesystems = Filesystems(**filesystems_config)
|
|
557
|
+
|
|
558
|
+
# Load configuration using Filesystems instance
|
|
559
|
+
self.loadConfigFilesystems(filesystems)
|
|
560
|
+
|
|
561
|
+
# Return the application instance for method chaining
|
|
562
|
+
return self
|
|
563
|
+
|
|
564
|
+
def loadConfigFilesystems(
|
|
565
|
+
self,
|
|
566
|
+
filesystems: Filesystems
|
|
567
|
+
) -> 'Application':
|
|
568
|
+
"""
|
|
569
|
+
Load the application filesystems configuration from a Filesystems instance.
|
|
570
|
+
|
|
571
|
+
Parameters
|
|
572
|
+
----------
|
|
573
|
+
filesystems : Filesystems
|
|
574
|
+
The Filesystems instance containing filesystems configuration
|
|
575
|
+
|
|
576
|
+
Returns
|
|
577
|
+
-------
|
|
578
|
+
Application
|
|
579
|
+
The application instance for method chaining
|
|
580
|
+
"""
|
|
581
|
+
|
|
582
|
+
# Validate filesystems type
|
|
583
|
+
if not isinstance(filesystems, Filesystems):
|
|
584
|
+
raise TypeError(f"Expected Filesystems instance, got {type(filesystems).__name__}")
|
|
585
|
+
|
|
586
|
+
# Store the configuration
|
|
587
|
+
self.__configurators['filesystems'] = filesystems
|
|
588
|
+
|
|
589
|
+
# Return the application instance for method chaining
|
|
590
|
+
return self
|
|
591
|
+
|
|
592
|
+
def configLogging(
|
|
593
|
+
self,
|
|
594
|
+
**logging_config
|
|
595
|
+
) -> 'Application':
|
|
596
|
+
"""
|
|
597
|
+
Configure the logging system with various channel settings.
|
|
598
|
+
|
|
599
|
+
Parameters
|
|
600
|
+
----------
|
|
601
|
+
**logging_config : dict
|
|
602
|
+
Configuration parameters for logging. Must match the fields
|
|
603
|
+
expected by the Logging dataclass (orionis.foundation.config.logging.entities.logging.Logging).
|
|
604
|
+
|
|
605
|
+
Returns
|
|
606
|
+
-------
|
|
607
|
+
Application
|
|
608
|
+
The application instance for method chaining
|
|
609
|
+
"""
|
|
610
|
+
|
|
611
|
+
# Create Logging instance with provided parameters
|
|
612
|
+
logging = Logging(**logging_config)
|
|
613
|
+
|
|
614
|
+
# Load configuration using Logging instance
|
|
615
|
+
self.loadConfigLogging(logging)
|
|
616
|
+
|
|
617
|
+
# Return the application instance for method chaining
|
|
618
|
+
return self
|
|
619
|
+
|
|
620
|
+
def loadConfigLogging(
|
|
621
|
+
self,
|
|
622
|
+
logging: Logging
|
|
623
|
+
) -> 'Application':
|
|
624
|
+
"""
|
|
625
|
+
Load the application logging configuration from a Logging instance.
|
|
626
|
+
|
|
627
|
+
Parameters
|
|
628
|
+
----------
|
|
629
|
+
logging : Logging
|
|
630
|
+
The Logging instance containing logging configuration
|
|
631
|
+
|
|
632
|
+
Returns
|
|
633
|
+
-------
|
|
634
|
+
Application
|
|
635
|
+
The application instance for method chaining
|
|
636
|
+
"""
|
|
637
|
+
|
|
638
|
+
# Validate logging type
|
|
639
|
+
if not isinstance(logging, Logging):
|
|
640
|
+
raise TypeError(f"Expected Logging instance, got {type(logging).__name__}")
|
|
641
|
+
|
|
642
|
+
# Store the configuration
|
|
643
|
+
self.__configurators['logging'] = logging
|
|
644
|
+
|
|
645
|
+
# Return the application instance for method chaining
|
|
646
|
+
return self
|
|
647
|
+
|
|
648
|
+
def configMail(
|
|
649
|
+
self,
|
|
650
|
+
**mail_config
|
|
651
|
+
) -> 'Application':
|
|
652
|
+
"""
|
|
653
|
+
Configure the mail system with various settings.
|
|
654
|
+
|
|
655
|
+
Parameters
|
|
656
|
+
----------
|
|
657
|
+
**mail_config : dict
|
|
658
|
+
Configuration parameters for mail. Must match the fields
|
|
659
|
+
expected by the Mail dataclass (orionis.foundation.config.mail.entities.mail.Mail).
|
|
660
|
+
|
|
661
|
+
Returns
|
|
662
|
+
-------
|
|
663
|
+
Application
|
|
664
|
+
The application instance for method chaining
|
|
665
|
+
"""
|
|
666
|
+
|
|
667
|
+
# Create Mail instance with provided parameters
|
|
668
|
+
mail = Mail(**mail_config)
|
|
669
|
+
|
|
670
|
+
# Load configuration using Mail instance
|
|
671
|
+
self.loadConfigMail(mail)
|
|
672
|
+
|
|
673
|
+
# Return the application instance for method chaining
|
|
674
|
+
return self
|
|
675
|
+
|
|
676
|
+
def loadConfigMail(
|
|
677
|
+
self,
|
|
678
|
+
mail: Mail
|
|
679
|
+
) -> 'Application':
|
|
680
|
+
"""
|
|
681
|
+
Load the application mail configuration from a Mail instance.
|
|
682
|
+
|
|
683
|
+
Parameters
|
|
684
|
+
----------
|
|
685
|
+
mail : Mail
|
|
686
|
+
The Mail instance containing mail configuration
|
|
687
|
+
|
|
688
|
+
Returns
|
|
689
|
+
-------
|
|
690
|
+
Application
|
|
691
|
+
The application instance for method chaining
|
|
692
|
+
"""
|
|
693
|
+
|
|
694
|
+
# Validate mail type
|
|
695
|
+
if not isinstance(mail, Mail):
|
|
696
|
+
raise TypeError(f"Expected Mail instance, got {type(mail).__name__}")
|
|
697
|
+
|
|
698
|
+
# Store the configuration
|
|
699
|
+
self.__configurators['mail'] = mail
|
|
700
|
+
|
|
701
|
+
# Return the application instance for method chaining
|
|
702
|
+
return self
|
|
703
|
+
|
|
704
|
+
def configQueue(
|
|
705
|
+
self,
|
|
706
|
+
**queue_config
|
|
707
|
+
) -> 'Application':
|
|
708
|
+
"""
|
|
709
|
+
Configure the queue system with various settings.
|
|
710
|
+
|
|
711
|
+
Parameters
|
|
712
|
+
----------
|
|
713
|
+
**queue_config : dict
|
|
714
|
+
Configuration parameters for queue. Must match the fields
|
|
715
|
+
expected by the Queue dataclass (orionis.foundation.config.queue.entities.queue.Queue).
|
|
716
|
+
|
|
717
|
+
Returns
|
|
718
|
+
-------
|
|
719
|
+
Application
|
|
720
|
+
The application instance for method chaining
|
|
721
|
+
"""
|
|
722
|
+
|
|
723
|
+
# Create Queue instance with provided parameters
|
|
724
|
+
queue = Queue(**queue_config)
|
|
725
|
+
|
|
726
|
+
# Load configuration using Queue instance
|
|
727
|
+
self.loadConfigQueue(queue)
|
|
728
|
+
|
|
729
|
+
# Return the application instance for method chaining
|
|
730
|
+
return self
|
|
731
|
+
|
|
732
|
+
def loadConfigQueue(
|
|
733
|
+
self,
|
|
734
|
+
queue: Queue
|
|
735
|
+
) -> 'Application':
|
|
736
|
+
"""
|
|
737
|
+
Load the application queue configuration from a Queue instance.
|
|
738
|
+
|
|
739
|
+
Parameters
|
|
740
|
+
----------
|
|
741
|
+
queue : Queue
|
|
742
|
+
The Queue instance containing queue configuration
|
|
743
|
+
|
|
744
|
+
Returns
|
|
745
|
+
-------
|
|
746
|
+
Application
|
|
747
|
+
The application instance for method chaining
|
|
748
|
+
"""
|
|
749
|
+
|
|
750
|
+
# Validate queue type
|
|
751
|
+
if not isinstance(queue, Queue):
|
|
752
|
+
raise TypeError(f"Expected Queue instance, got {type(queue).__name__}")
|
|
753
|
+
|
|
754
|
+
# Store the configuration
|
|
755
|
+
self.__configurators['queue'] = queue
|
|
756
|
+
|
|
757
|
+
# Return the application instance for method chaining
|
|
758
|
+
return self
|
|
759
|
+
|
|
760
|
+
def configSession(
|
|
761
|
+
self,
|
|
762
|
+
**session_config
|
|
763
|
+
) -> 'Application':
|
|
764
|
+
"""
|
|
765
|
+
Configure the session with various settings.
|
|
766
|
+
|
|
767
|
+
Parameters
|
|
768
|
+
----------
|
|
769
|
+
**session_config : dict
|
|
770
|
+
Configuration parameters for session. Must match the fields
|
|
771
|
+
expected by the Session dataclass (orionis.foundation.config.session.entities.session.Session).
|
|
772
|
+
|
|
773
|
+
Returns
|
|
774
|
+
-------
|
|
775
|
+
Application
|
|
776
|
+
The application instance for method chaining
|
|
777
|
+
"""
|
|
778
|
+
|
|
779
|
+
# Create Session instance with provided parameters
|
|
780
|
+
session = Session(**session_config)
|
|
781
|
+
|
|
782
|
+
# Load configuration using Session instance
|
|
783
|
+
self.loadConfigSession(session)
|
|
784
|
+
|
|
785
|
+
# Return the application instance for method chaining
|
|
786
|
+
return self
|
|
787
|
+
|
|
788
|
+
def loadConfigSession(
|
|
789
|
+
self,
|
|
790
|
+
session: Session
|
|
791
|
+
) -> 'Application':
|
|
792
|
+
"""
|
|
793
|
+
Load the application session configuration from a Session instance.
|
|
794
|
+
|
|
795
|
+
Parameters
|
|
796
|
+
----------
|
|
797
|
+
session : Session
|
|
798
|
+
The Session instance containing session configuration
|
|
799
|
+
|
|
800
|
+
Returns
|
|
801
|
+
-------
|
|
802
|
+
Application
|
|
803
|
+
The application instance for method chaining
|
|
804
|
+
"""
|
|
805
|
+
|
|
806
|
+
# Validate session type
|
|
807
|
+
if not isinstance(session, Session):
|
|
808
|
+
raise TypeError(f"Expected Session instance, got {type(session).__name__}")
|
|
809
|
+
|
|
810
|
+
# Store the configuration
|
|
811
|
+
self.__configurators['session'] = session
|
|
812
|
+
|
|
813
|
+
# Return the application instance for method chaining
|
|
814
|
+
return self
|
|
815
|
+
|
|
816
|
+
def configTesting(
|
|
817
|
+
self,
|
|
818
|
+
**testing_config
|
|
819
|
+
) -> 'Application':
|
|
820
|
+
"""
|
|
821
|
+
Configure the testing with various settings.
|
|
822
|
+
|
|
823
|
+
Parameters
|
|
824
|
+
----------
|
|
825
|
+
**testing_config : dict
|
|
826
|
+
Configuration parameters for testing. Must match the fields
|
|
827
|
+
expected by the Testing dataclass (orionis.foundation.config.testing.entities.testing.Testing).
|
|
828
|
+
|
|
829
|
+
Returns
|
|
830
|
+
-------
|
|
831
|
+
Application
|
|
832
|
+
The application instance for method chaining
|
|
833
|
+
"""
|
|
834
|
+
|
|
835
|
+
# Create Testing instance with provided parameters
|
|
836
|
+
testing = Testing(**testing_config)
|
|
837
|
+
|
|
838
|
+
# Load configuration using Testing instance
|
|
839
|
+
self.loadConfigTesting(testing)
|
|
840
|
+
|
|
841
|
+
# Return the application instance for method chaining
|
|
842
|
+
return self
|
|
843
|
+
|
|
844
|
+
def loadConfigTesting(
|
|
845
|
+
self,
|
|
846
|
+
testing: Testing
|
|
847
|
+
) -> 'Application':
|
|
848
|
+
"""
|
|
849
|
+
Load the application testing configuration from a Testing instance.
|
|
850
|
+
|
|
851
|
+
Parameters
|
|
852
|
+
----------
|
|
853
|
+
testing : Testing
|
|
854
|
+
The Testing instance containing testing configuration
|
|
855
|
+
|
|
856
|
+
Returns
|
|
857
|
+
-------
|
|
858
|
+
Application
|
|
859
|
+
The application instance for method chaining
|
|
860
|
+
"""
|
|
861
|
+
|
|
862
|
+
# Validate testing type
|
|
863
|
+
if not isinstance(testing, Testing):
|
|
864
|
+
raise TypeError(f"Expected Testing instance, got {type(testing).__name__}")
|
|
865
|
+
|
|
866
|
+
# Store the configuration
|
|
867
|
+
self.__configurators['testing'] = testing
|
|
868
|
+
|
|
869
|
+
# Return the application instance for method chaining
|
|
185
870
|
return self
|
|
186
871
|
|
|
872
|
+
def __loadConfig(
|
|
873
|
+
self,
|
|
874
|
+
) -> None:
|
|
875
|
+
"""
|
|
876
|
+
Retrieve a configuration value by key.
|
|
877
|
+
|
|
878
|
+
Returns
|
|
879
|
+
-------
|
|
880
|
+
None
|
|
881
|
+
Initializes the application configuration if not already set.
|
|
882
|
+
"""
|
|
883
|
+
|
|
884
|
+
# Try to load the configuration
|
|
885
|
+
try:
|
|
886
|
+
|
|
887
|
+
# Check if configuration is a dictionary
|
|
888
|
+
if not self.__config:
|
|
889
|
+
|
|
890
|
+
# Initialize with default configuration
|
|
891
|
+
if not self.__configurators:
|
|
892
|
+
self.__config = Configuration().toDict()
|
|
893
|
+
|
|
894
|
+
# If configurators are provided, use them to create the configuration
|
|
895
|
+
else:
|
|
896
|
+
self.__config = Configuration(**self.__configurators).toDict()
|
|
897
|
+
|
|
898
|
+
except Exception as e:
|
|
899
|
+
|
|
900
|
+
# Handle any exceptions during configuration loading
|
|
901
|
+
raise RuntimeError(f"Failed to load application configuration: {str(e)}")
|
|
902
|
+
|
|
187
903
|
def create(
|
|
188
904
|
self
|
|
189
905
|
) -> 'Application':
|
|
@@ -206,7 +922,55 @@ class Application(Container, IApplication):
|
|
|
206
922
|
self.__registerProviders()
|
|
207
923
|
self.__bootProviders()
|
|
208
924
|
|
|
925
|
+
# Load configuration if not already set
|
|
926
|
+
self.__loadConfig()
|
|
927
|
+
|
|
209
928
|
# Mark as booted
|
|
210
929
|
self.__booted = True
|
|
211
930
|
|
|
212
|
-
return self
|
|
931
|
+
return self
|
|
932
|
+
|
|
933
|
+
def config(
|
|
934
|
+
self,
|
|
935
|
+
key: str,
|
|
936
|
+
default: Any = None
|
|
937
|
+
) -> Any:
|
|
938
|
+
"""
|
|
939
|
+
Retrieve a configuration value by key.
|
|
940
|
+
|
|
941
|
+
Parameters
|
|
942
|
+
----------
|
|
943
|
+
key : str
|
|
944
|
+
The configuration key to retrieve using dot notation (e.g. "app.name") (default is None)
|
|
945
|
+
default : Any, optional
|
|
946
|
+
Default value to return if key is not found
|
|
947
|
+
|
|
948
|
+
Returns
|
|
949
|
+
-------
|
|
950
|
+
Any
|
|
951
|
+
The configuration value or the entire configuration if key is None
|
|
952
|
+
"""
|
|
953
|
+
|
|
954
|
+
# If key is None, raise an error to prevent ambiguity
|
|
955
|
+
if key is None:
|
|
956
|
+
raise ValueError("Key cannot be None. Use config() without arguments to get the entire configuration.")
|
|
957
|
+
|
|
958
|
+
# Split the key by dot notation
|
|
959
|
+
parts = key.split('.')
|
|
960
|
+
|
|
961
|
+
# Start with the full config
|
|
962
|
+
config_value = self.__config
|
|
963
|
+
|
|
964
|
+
# Traverse the config dictionary based on the key parts
|
|
965
|
+
for part in parts:
|
|
966
|
+
|
|
967
|
+
# If part is not in config_value, return default
|
|
968
|
+
if isinstance(config_value, dict) and part in config_value:
|
|
969
|
+
config_value = config_value[part]
|
|
970
|
+
|
|
971
|
+
# If part is not found, return default value
|
|
972
|
+
else:
|
|
973
|
+
return default
|
|
974
|
+
|
|
975
|
+
# Return the final configuration value
|
|
976
|
+
return config_value
|