Passed
Push — main ( 305d80...a9cad4 )
by Dimitri
03:37
created

Services::encrypter()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 5
cp 0
crap 12
rs 10
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Container;
13
14
use BlitzPHP\Autoloader\Autoloader;
15
use BlitzPHP\Autoloader\Locator;
16
use BlitzPHP\Autoloader\LocatorInterface;
17
use BlitzPHP\Cache\Cache;
18
use BlitzPHP\Cache\ResponseCache;
19
use BlitzPHP\Config\Config;
20
use BlitzPHP\Contracts\Database\ConnectionResolverInterface;
21
use BlitzPHP\Contracts\Security\EncrypterInterface;
22
use BlitzPHP\Contracts\Session\CookieManagerInterface;
23
use BlitzPHP\Debug\Logger;
24
use BlitzPHP\Debug\Timer;
25
use BlitzPHP\Debug\Toolbar;
26
use BlitzPHP\Event\EventManager;
27
use BlitzPHP\Filesystem\Filesystem;
28
use BlitzPHP\Filesystem\FilesystemManager;
29
use BlitzPHP\Http\Negotiator;
30
use BlitzPHP\Http\Redirection;
31
use BlitzPHP\Http\Request;
32
use BlitzPHP\Http\Response;
33
use BlitzPHP\Http\ResponseEmitter;
34
use BlitzPHP\Http\ServerRequest;
35
use BlitzPHP\Http\Uri;
36
use BlitzPHP\Http\UrlGenerator;
37
use BlitzPHP\Mail\Mail;
38
use BlitzPHP\Router\RouteCollection;
39
use BlitzPHP\Router\Router;
40
use BlitzPHP\Security\Encryption\Encryption;
41
use BlitzPHP\Session\Cookie\Cookie;
42
use BlitzPHP\Session\Cookie\CookieManager;
43
use BlitzPHP\Session\Handlers\Database as DatabaseSessionHandler;
44
use BlitzPHP\Session\Handlers\Database\MySQL as MySQLSessionHandler;
45
use BlitzPHP\Session\Handlers\Database\Postgre as PostgreSessionHandler;
46
use BlitzPHP\Session\Store;
47
use BlitzPHP\Translator\Translate;
48
use BlitzPHP\Utilities\Helpers;
49
use BlitzPHP\Utilities\String\Text;
50
use BlitzPHP\View\View;
51
use Psr\Log\LoggerInterface;
52
use stdClass;
53
54
/**
55
 * Service
56
 *
57
 * Les services sont simplement d'autres classes/bibliothèques que le système utilise
58
 * pour faire son travail. Ceci est utilisé par BlitzPHP pour permettre au coeur du
59
 * framework à échanger facilement sans affecter l'utilisation à l'intérieur
60
 * le reste de votre application.
61
 *
62
 * Ceci est utilisé à la place d'un conteneur d'injection de dépendance principalement
63
 * en raison de sa simplicité, qui permet un meilleur entretien à long terme
64
 * des applications construites sur BlitzPHP. Un effet secondaire bonus
65
 * est que les IDE sont capables de déterminer quelle classe vous appelez
66
 * alors qu'avec les conteneurs DI, il n'y a généralement aucun moyen pour eux de le faire.
67
 */
68
class Services
69
{
70
    /**
71
     * Cache des instances des services demander comme instance "partagee".
72
     * La cle est le FQCN du service.
73
     */
74
    protected static array $instances = [];
75
76
    /**
77
     * Objets simulés à tester qui sont renvoyés s'ils existent.
78
     */
79
    protected static array $mocks = [];
80
81
    /**
82
     * Cache d'autres classe de que nous avons trouver via la methode cacheService.
83
     */
84
    protected static array $services = [];
85
86
    /**
87
     * Avons-nous déjà découvert d'autres Services ?
88
     */
89
    protected static bool $discovered = false;
90
91
    /**
92
     * Un cache des noms de classes de services trouvés.
93
     *
94
     * @var array<string>
95
     */
96
    private static array $serviceNames = [];
97
98
    /**
99
     * La classe Autoloader permet de charger les fichiers simplement.
100
     */
101
    public static function autoloader(bool $shared = true): Autoloader
102
    {
103
        if (true === $shared && isset(static::$instances[Autoloader::class])) {
104 50
            return static::$instances[Autoloader::class];
105
        }
106
107 2
        $config  = static::config()->get('autoload');
108 2
        $helpers = array_merge(['url'], ($config['helpers'] ?? []));
109
110 2
        return static::$instances[Autoloader::class] = new Autoloader($config, $helpers);
0 ignored issues
show
Bug introduced by
It seems like $config can also be of type null; however, parameter $config of BlitzPHP\Autoloader\Autoloader::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

110
        return static::$instances[Autoloader::class] = new Autoloader(/** @scrutinizer ignore-type */ $config, $helpers);
Loading history...
111
    }
112
113
    /**
114
     * La classe de cache fournit un moyen simple de stocker et de récupérer
115
     * données complexes pour plus tard
116
     */
117
    public static function cache(?array $config = null, bool $shared = true): Cache
118
    {
119
        if (empty($config)) {
120
            $config = static::config()->get('cache');
121
        }
122
123
        if (true === $shared && isset(static::$instances[Cache::class])) {
124
            $instance = static::$instances[Cache::class];
125
            if (empty(func_get_args()[0])) {
126
                return $instance;
127
            }
128
129
            return $instance->setConfig($config);
130
        }
131
132
        return static::$instances[Cache::class] = new Cache($config);
133
    }
134
135
    /**
136
     * La clase Config offre une api fluide por gerer les configurations de l'application
137
     */
138
    public static function config(bool $shared = true): Config
139
    {
140
        if (true === $shared && isset(static::$instances[Config::class])) {
141 99
            return static::$instances[Config::class];
142
        }
143
144
        return static::$instances[Config::class] = new Config();
145
    }
146
147
    /**
148
     * Conteneur d'injection de dependances
149
     */
150
    public static function container(bool $shared = true): Container
151
    {
152
        if (true === $shared && isset(static::$instances[Container::class])) {
153 34
            return static::$instances[Container::class];
154
        }
155
156
        return static::$instances[Container::class] = new Container();
157
    }
158
159
    /**
160
     * Gestionnaire de cookies
161
     */
162
    public static function cookie(bool $shared = true): CookieManagerInterface
163
    {
164
        if (true === $shared && isset(static::$instances[CookieManager::class])) {
165 2
            return static::$instances[CookieManager::class];
166
        }
167
168 2
        $config = (object) static::config()->get('cookie');
169
170
        return static::$instances[CookieManager::class] = (new CookieManager())->setDefaultPathAndDomain(
171
            $config->path ?: '/',
172
            $config->domain ?: '',
173
            $config->secure ?: false,
174
            $config->httponly ?: true,
175
            $config->samesite ?: 'Lax'
176 2
        );
177
    }
178
179
    /**
180
     * Émetteur de réponse au client
181
     */
182
    public static function emitter(bool $shared = true): ResponseEmitter
183
    {
184
        if (true === $shared && isset(static::$instances[ResponseEmitter::class])) {
185 2
            return static::$instances[ResponseEmitter::class];
186
        }
187
188 2
        return static::$instances[ResponseEmitter::class] = new ResponseEmitter();
189
    }
190
191
    /**
192
     * La classe Encryption fournit un cryptage bidirectionnel.
193
     */
194
    public static function encrypter(?array $config = null, bool $shared = false): EncrypterInterface
195
    {
196
        if (true === $shared && isset(static::$instances[Encryption::class])) {
197
            return static::$instances[Encryption::class];
198
        }
199
200
        $config ??= config('encryption');
201
        $config     = (object) $config;
202
        $encryption = new Encryption($config);
203
204
        return static::$instances[Encryption::class] = $encryption->initialize($config);
205
    }
206
207
    /**
208
     * Gestionnaire d'evenement
209
     */
210
    public static function event(bool $shared = true): EventManager
211
    {
212
        if (true === $shared && isset(static::$instances[EventManager::class])) {
213
            return static::$instances[EventManager::class];
214
        }
215
216
        return static::$instances[EventManager::class] = new EventManager();
217
    }
218
219
    /**
220
     * System de gestion de fichier
221
     */
222
    public static function fs(bool $shared = true): Filesystem
223
    {
224
        if (true === $shared && isset(static::$instances[Filesystem::class])) {
225 2
            return static::$instances[Filesystem::class];
226
        }
227
228 2
        return static::$instances[Filesystem::class] = new Filesystem();
229
    }
230
231
    /**
232
     * Responsable du chargement des traductions des chaînes de langue.
233
     *
234
     * @deprecated 0.9 use translators instead
235
     */
236
    public static function language(?string $locale = null, bool $shared = true): Translate
237
    {
238
        return static::translator($locale, $shared);
239
    }
240
241
    /**
242
     * Le file locator fournit des methodes utilitaire pour chercher les fichiers non-classes
243
     * dans les dossiers de namespace. C'est une excelente methode pour charger les 'vues', 'helpers', et 'libraries'.
244
     */
245
    public static function locator(bool $shared = true): LocatorInterface
246
    {
247
        if ($shared && isset(static::$instances[Locator::class])) {
248 67
            return static::$instances[Locator::class];
249
        }
250
251
        return static::$instances[Locator::class] = new Locator(static::autoloader());
252
    }
253
254
    /**
255
     * La classe Logger est une classe Logging compatible PSR-3 qui prend en charge
256
     * plusieurs gestionnaires qui traitent la journalisation réelle.
257
     *
258
     * @return Logger
259
     */
260
    public static function logger(bool $shared = true): LoggerInterface
261
    {
262
        if ($shared && isset(static::$instances[Logger::class])) {
263 9
            return static::$instances[Logger::class];
264
        }
265
266
        return static::$instances[Logger::class] = new Logger();
267
    }
268
269
    /**
270
     * La classe de mail vous permet d'envoyer par courrier électronique via mail, sendmail, SMTP.
271
     */
272
    public static function mail(?array $config = null, bool $shared = true): Mail
273
    {
274
        if (empty($config)) {
275
            $config = static::config()->get('mail');
276
        }
277
278
        if (true === $shared && isset(static::$instances[Mail::class])) {
279
            /** @var Mail $instance */
280
            $instance = static::$instances[Mail::class];
281
            if (empty(func_get_args()[0])) {
282
                return $instance;
283
            }
284
285
            return $instance->merge($config);
286
        }
287
288
        return static::$instances[Mail::class] = new Mail($config);
289
    }
290
291
    /**
292
     * La classe Input générale modélise une requête HTTP.
293
     */
294
    public static function negotiator(?ServerRequest $request = null, bool $shared = true): Negotiator
295
    {
296
        if (empty($request)) {
297 2
            $request = static::request(true);
298
        }
299
300
        if (true === $shared && isset(static::$instances[Negotiator::class])) {
301 2
            $instance = static::$instances[Negotiator::class];
302
            if (empty(func_get_args()[0])) {
303
                return $instance;
304
            }
305
306
            return $instance->setRequest($request);
307
        }
308
309 2
        return static::$instances[Negotiator::class] = new Negotiator($request);
310
    }
311
312
    /**
313
     * La classe des redirections HTTP
314
     */
315
    public static function redirection(bool $shared = true): Redirection
316
    {
317
        if (true === $shared && isset(static::$instances[Redirection::class])) {
318
            return static::$instances[Redirection::class];
319
        }
320
321
        return static::$instances[Redirection::class] = new Redirection(static::factory(UrlGenerator::class));
322
    }
323
324
    /**
325
     * La classe Resquest modélise une reqûete HTTP.
326
     */
327
    public static function request(bool $shared = true): Request
328
    {
329
        if (true === $shared && isset(static::$instances[Request::class])) {
330 30
            return static::$instances[Request::class];
331
        }
332
333
        return static::$instances[Request::class] = new Request();
334
    }
335
336
    /**
337
     * La classe Response modélise une réponse HTTP.
338
     */
339
    public static function response(bool $shared = true): Response
340
    {
341
        if (true === $shared && isset(static::$instances[Response::class])) {
342 4
            return static::$instances[Response::class];
343
        }
344
345 2
        return static::$instances[Response::class] = new Response();
346
    }
347
348
    /**
349
     * CacheResponse
350
     */
351
    public static function responsecache(bool $shared = true): ResponseCache
352
    {
353
        if (true === $shared && isset(static::$instances[ResponseCache::class])) {
354
            return static::$instances[ResponseCache::class];
355
        }
356
357
        return static::$instances[ResponseCache::class] = new ResponseCache(static::cache(), static::config()->get('cache.cache_query_string'));
0 ignored issues
show
Bug introduced by
It seems like static::config()->get('cache.cache_query_string') can also be of type null; however, parameter $cacheQueryString of BlitzPHP\Cache\ResponseCache::__construct() does only seem to accept array|boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

357
        return static::$instances[ResponseCache::class] = new ResponseCache(static::cache(), /** @scrutinizer ignore-type */ static::config()->get('cache.cache_query_string'));
Loading history...
358
    }
359
360
    /**
361
     * Le service Routes est une classe qui permet de construire facilement
362
     * une collection d'itinéraires.
363
     */
364
    public static function routes(bool $shared = true): RouteCollection
365
    {
366
        if (true === $shared && isset(static::$instances[RouteCollection::class])) {
367 2
            return static::$instances[RouteCollection::class];
368
        }
369
370 8
        return static::$instances[RouteCollection::class] = new RouteCollection(static::locator(), (object) static::config()->get('routing'));
371
    }
372
373
    /**
374
     * La classe Router utilise le tableau de routes d'une RouteCollection et détermine
375
     * le contrôleur et la méthode corrects à exécuter.
376
     */
377
    public static function router(?RouteCollection $routes = null, ?ServerRequest $request = null, bool $shared = true): Router
378
    {
379
        if (true === $shared && isset(static::$instances[Router::class])) {
380 8
            return static::$instances[Router::class];
381
        }
382
383
        if (empty($routes)) {
384 8
            $routes = static::routes(true);
385
        }
386
        if (empty($request)) {
387 8
            $request = static::request(true);
388
        }
389
390 8
        return static::$instances[Router::class] = new Router($routes, $request);
391
    }
392
393
    /**
394
     * Retourne le gestionnaire de session.
395
     */
396
    public static function session(bool $shared = true): Store
397
    {
398
        if (true === $shared && isset(static::$instances[Store::class])) {
399 7
            return static::$instances[Store::class];
400
        }
401
402 7
        $config = static::config()->get('session');
403 7
        $db     = null;
404
405
        if (Text::contains($config['handler'], [DatabaseSessionHandler::class, 'database'])) {
406 7
            $group = $config['group'] ?? static::config()->get('database.connection');
407
            $db    = static::singleton(ConnectionResolverInterface::class)->connection($group);
408
409
            $driver = $db->getPlatform();
410
411
            if (Text::contains($driver, ['mysql', MySQLSessionHandler::class])) {
412
                $config['handler'] = MySQLSessionHandler::class;
413
            } elseif (Text::contains($driver, ['postgre', PostgreSessionHandler::class])) {
414
                $config['handler'] = PostgreSessionHandler::class;
415
            }
416
        }
417
418 7
        Cookie::setDefaults($cookies = static::config()->get('cookie'));
0 ignored issues
show
Bug introduced by
It seems like $cookies = static::config()->get('cookie') can also be of type null; however, parameter $options of BlitzPHP\Session\Cookie\Cookie::setDefaults() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

418
        Cookie::setDefaults(/** @scrutinizer ignore-type */ $cookies = static::config()->get('cookie'));
Loading history...
419 7
        $session = new Store($config, $cookies, Helpers::ipAddress());
0 ignored issues
show
Bug introduced by
It seems like $config can also be of type null; however, parameter $config of BlitzPHP\Session\Store::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

419
        $session = new Store(/** @scrutinizer ignore-type */ $config, $cookies, Helpers::ipAddress());
Loading history...
Bug introduced by
It seems like $cookies can also be of type null; however, parameter $cookie of BlitzPHP\Session\Store::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

419
        $session = new Store($config, /** @scrutinizer ignore-type */ $cookies, Helpers::ipAddress());
Loading history...
420 7
        $session->setLogger(static::logger());
421 7
        $session->setDatabase($db);
422
423
        if (session_status() === PHP_SESSION_NONE) {
424 7
            $session->start();
425
        }
426
427 7
        return static::$instances[Store::class] = $session;
428
    }
429
430
    /**
431
     * System de gestion de fichier par disque
432
     */
433
    public static function storage(bool $shared = true): FilesystemManager
434
    {
435
        if ($shared && isset(static::$instances[FilesystemManager::class])) {
436 2
            return static::$instances[FilesystemManager::class];
437
        }
438
439 2
        return static::$instances[FilesystemManager::class] = new FilesystemManager(static::config()->get('filesystems'));
0 ignored issues
show
Bug introduced by
It seems like static::config()->get('filesystems') can also be of type null; however, parameter $config of BlitzPHP\Filesystem\File...mManager::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

439
        return static::$instances[FilesystemManager::class] = new FilesystemManager(/** @scrutinizer ignore-type */ static::config()->get('filesystems'));
Loading history...
440
    }
441
442
    /**
443
     * La classe Timer fournit un moyen simple d'évaluer des parties de votre application.
444
     */
445
    public static function timer(bool $shared = true): Timer
446
    {
447
        if (true === $shared && isset(static::$instances[Timer::class])) {
448
            return static::$instances[Timer::class];
449
        }
450
451
        return static::$instances[Timer::class] = new Timer();
452
    }
453
454
    /**
455
     * Renvoie la barre d'outils de débogage.
456
     */
457
    public static function toolbar(?stdClass $config = null, bool $shared = true): Toolbar
458
    {
459
        if ($shared && isset(static::$instances[Toolbar::class])) {
460
            return static::$instances[Toolbar::class];
461
        }
462
463
        $config ??= (object) config('toolbar');
464
465
        return static::$instances[Toolbar::class] = new Toolbar($config);
0 ignored issues
show
Bug introduced by
It seems like $config can also be of type BlitzPHP\Config\Config; however, parameter $config of BlitzPHP\Debug\Toolbar::__construct() does only seem to accept null|stdClass, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

465
        return static::$instances[Toolbar::class] = new Toolbar(/** @scrutinizer ignore-type */ $config);
Loading history...
466
    }
467
468
    /**
469
     * Responsable du chargement des traductions des chaînes de langue.
470
     */
471
    public static function translator(?string $locale = null, bool $shared = true): Translate
472
    {
473
        if (empty($locale)) {
474
            if (empty($locale = static::$instances[Translate::class . 'locale'] ?? null)) {
475 2
                $config = static::config()->get('app');
476
477
                if (empty($locale = static::negotiator()->language($config['supported_locales']))) {
478 2
                    $locale = $config['language'];
479
                }
480
481 2
                static::$instances[Translate::class . 'locale'] = $locale;
482
            }
483
        }
484
485
        if (true === $shared && isset(static::$instances[Translate::class])) {
486 22
            return static::$instances[Translate::class]->setLocale($locale);
487
        }
488
489 2
        return static::$instances[Translate::class] = new Translate($locale, static::locator());
490
    }
491
492
    /**
493
     * La classe URI fournit un moyen de modéliser et de manipuler les URI.
494
     */
495
    public static function uri(?string $uri = null, bool $shared = true): Uri
496
    {
497
        if (true === $shared && isset(static::$instances[Uri::class])) {
498
            return static::$instances[Uri::class]->setURI($uri);
499
        }
500
501
        return static::$instances[Uri::class] = new Uri($uri);
502
    }
503
504
    /**
505
     * La classe Renderer est la classe qui affiche réellement un fichier à l'utilisateur.
506
     * La classe View par défaut dans BlitzPHP est intentionnellement simple, mais
507
     * le service peut facilement être remplacé par un moteur de modèle si l'utilisateur en a besoin.
508
     */
509
    public static function viewer(bool $shared = true): View
510
    {
511
        if (true === $shared && isset(static::$instances[View::class])) {
512 2
            return static::$instances[View::class];
513
        }
514
515 2
        return static::$instances[View::class] = new View();
516
    }
517
518
    /**
519
     * Offre la possibilité d'effectuer des appels insensibles à la casse des noms de service.
520
     *
521
     * @return mixed
522
     */
523
    public static function __callStatic(string $name, array $arguments)
524
    {
525
        if (null === $service = static::serviceExists($name)) {
526
            return static::discoverServices($name, $arguments);
527
        }
528
529
        return $service::$name(...$arguments);
530
    }
531
532
    /**
533
     * Vérifiez si le service demandé est défini et renvoyez la classe déclarante.
534
     * Renvoie null s'il n'est pas trouvé.
535
     */
536
    public static function serviceExists(string $name): ?string
537
    {
538
        static::cacheServices();
539
        $services = array_merge(self::$serviceNames, [self::class]);
540
        $name     = strtolower($name);
541
542
        foreach ($services as $service) {
543
            if (method_exists($service, $name)) {
544
                return $service;
545
            }
546
        }
547
548
        return null;
549
    }
550
551
    /**
552
     * Injectez un objet fictif pour les tests.
553
     */
554
    public static function injectMock(string $name, object $mock): void
555
    {
556 3
        static::$mocks[strtolower($name)] = $mock;
557
    }
558
559
    /**
560
     * Essaie d'obtenir un service à partir du conteneur
561
     *
562
     * @return mixed
563
     */
564
    protected static function discoverServices(string $name, array $arguments)
565
    {
566
        if (true !== array_pop($arguments)) {
567
            return static::factory($name, $arguments);
568
        }
569
570
        return static::singleton($name, ...$arguments);
571
    }
572
573
    protected static function cacheServices(): void
574
    {
575
        if (! static::$discovered) {
576
            $locator = static::locator();
577
            $files   = $locator->search('Config/Services');
578
579
            // Obtenez des instances de toutes les classes de service et mettez-les en cache localement.
580
            foreach ($files as $file) {
581
                if (false === $classname = $locator->findQualifiedNameFromPath($file)) {
582
                    continue;
583
                }
584
                if (self::class !== $classname) {
585
                    self::$serviceNames[] = $classname;
586
                    static::$services[]   = new $classname();
587
                }
588
            }
589
590
            static::$discovered = true;
591
        }
592
    }
593
594
    /**
595
     * Injecter une seule instance de la classe donnée
596
     *
597
     * @return mixed
598
     */
599
    public static function singleton(string $name)
600
    {
601
        $arguments = func_get_args();
602
        $name      = array_shift($arguments);
603
604
        if (empty(static::$instances[$name])) {
605
            if (! empty($arguments)) {
606
                static::$instances[$name] = static::factory($name, $arguments);
607
            } else {
608
                static::$instances[$name] = static::container()->get($name);
609
            }
610
        }
611
612
        return static::$instances[$name];
613
    }
614
615
    /**
616
     * Injecter une nouvelle instance de la classe donnée
617
     *
618
     * @return mixed
619
     */
620
    public static function factory(string $name, array $arguments = [])
621
    {
622
        return static::container()->make($name, $arguments);
623
    }
624
625
    /**
626
     * Définissez un objet ou une valeur dans le conteneur.
627
     *
628
     * @param string $name  Nom de l'entrée
629
     * @param mixed  $value utilisez les aides à la définition pour définir les objets
630
     */
631
    public static function set(string $name, $value)
632
    {
633 30
        static::$instances[$name] = $value;
634 30
        static::container()->set($name, $value);
635
    }
636
637
    /**
638
     * Réinitialisez les instances partagées et les simulations pour les tests.
639
     */
640
    public static function reset(bool $initAutoloader = true): void
641
    {
642
        // static::$mocks     = [];
643
        static::$instances = [];
644
645
        if ($initAutoloader) {
646
            static::autoloader()->initialize();
647
        }
648
    }
649
}
650