• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / CodeIgniter4 / 22495985083

27 Feb 2026 05:08PM UTC coverage: 86.622% (+0.03%) from 86.594%
22495985083

push

github

web-flow
refactor: remove deprecations in `Database` (#9986)

7 of 9 new or added lines in 2 files covered. (77.78%)

283 existing lines in 13 files now uncovered.

22513 of 25990 relevant lines covered (86.62%)

218.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.1
/system/Config/Services.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Config;
15

16
use CodeIgniter\Cache\CacheFactory;
17
use CodeIgniter\Cache\CacheInterface;
18
use CodeIgniter\Cache\ResponseCache;
19
use CodeIgniter\CLI\Commands;
20
use CodeIgniter\CodeIgniter;
21
use CodeIgniter\Context\Context;
22
use CodeIgniter\Database\ConnectionInterface;
23
use CodeIgniter\Database\MigrationRunner;
24
use CodeIgniter\Debug\Exceptions;
25
use CodeIgniter\Debug\Iterator;
26
use CodeIgniter\Debug\Timer;
27
use CodeIgniter\Debug\Toolbar;
28
use CodeIgniter\Email\Email;
29
use CodeIgniter\Encryption\EncrypterInterface;
30
use CodeIgniter\Encryption\Encryption;
31
use CodeIgniter\Filters\Filters;
32
use CodeIgniter\Format\Format;
33
use CodeIgniter\Honeypot\Honeypot;
34
use CodeIgniter\HTTP\CLIRequest;
35
use CodeIgniter\HTTP\ContentSecurityPolicy;
36
use CodeIgniter\HTTP\CURLRequest;
37
use CodeIgniter\HTTP\IncomingRequest;
38
use CodeIgniter\HTTP\Negotiate;
39
use CodeIgniter\HTTP\RedirectResponse;
40
use CodeIgniter\HTTP\Request;
41
use CodeIgniter\HTTP\RequestInterface;
42
use CodeIgniter\HTTP\Response;
43
use CodeIgniter\HTTP\ResponseInterface;
44
use CodeIgniter\HTTP\SiteURIFactory;
45
use CodeIgniter\HTTP\URI;
46
use CodeIgniter\HTTP\UserAgent;
47
use CodeIgniter\Images\Handlers\BaseHandler;
48
use CodeIgniter\Language\Language;
49
use CodeIgniter\Log\Logger;
50
use CodeIgniter\Pager\Pager;
51
use CodeIgniter\Router\RouteCollection;
52
use CodeIgniter\Router\RouteCollectionInterface;
53
use CodeIgniter\Router\Router;
54
use CodeIgniter\Security\Security;
55
use CodeIgniter\Session\Handlers\BaseHandler as SessionBaseHandler;
56
use CodeIgniter\Session\Handlers\Database\MySQLiHandler;
57
use CodeIgniter\Session\Handlers\Database\PostgreHandler;
58
use CodeIgniter\Session\Handlers\DatabaseHandler;
59
use CodeIgniter\Session\Session;
60
use CodeIgniter\Superglobals;
61
use CodeIgniter\Throttle\Throttler;
62
use CodeIgniter\Typography\Typography;
63
use CodeIgniter\Validation\Validation;
64
use CodeIgniter\Validation\ValidationInterface;
65
use CodeIgniter\View\Cell;
66
use CodeIgniter\View\Parser;
67
use CodeIgniter\View\RendererInterface;
68
use CodeIgniter\View\View;
69
use Config\App;
70
use Config\Cache;
71
use Config\ContentSecurityPolicy as ContentSecurityPolicyConfig;
72
use Config\ContentSecurityPolicy as CSPConfig;
73
use Config\Database;
74
use Config\Email as EmailConfig;
75
use Config\Encryption as EncryptionConfig;
76
use Config\Exceptions as ExceptionsConfig;
77
use Config\Filters as FiltersConfig;
78
use Config\Format as FormatConfig;
79
use Config\Honeypot as HoneypotConfig;
80
use Config\Images;
81
use Config\Logger as LoggerConfig;
82
use Config\Migrations;
83
use Config\Modules;
84
use Config\Pager as PagerConfig;
85
use Config\Paths;
86
use Config\Routing;
87
use Config\Security as SecurityConfig;
88
use Config\Services as AppServices;
89
use Config\Session as SessionConfig;
90
use Config\Toolbar as ToolbarConfig;
91
use Config\Validation as ValidationConfig;
92
use Config\View as ViewConfig;
93
use InvalidArgumentException;
94
use Locale;
95

96
/**
97
 * Services Configuration file.
98
 *
99
 * Services are simply other classes/libraries that the system uses
100
 * to do its job. This is used by CodeIgniter to allow the core of the
101
 * framework to be swapped out easily without affecting the usage within
102
 * the rest of your application.
103
 *
104
 * This is used in place of a Dependency Injection container primarily
105
 * due to its simplicity, which allows a better long-term maintenance
106
 * of the applications built on top of CodeIgniter. A bonus side-effect
107
 * is that IDEs are able to determine what class you are calling
108
 * whereas with DI Containers there usually isn't a way for them to do this.
109
 *
110
 * @see http://blog.ircmaxell.com/2015/11/simple-easy-risk-and-change.html
111
 * @see http://www.infoq.com/presentations/Simple-Made-Easy
112
 * @see \CodeIgniter\Config\ServicesTest
113
 */
114
class Services extends BaseService
115
{
116
    /**
117
     * The cache class provides a simple way to store and retrieve
118
     * complex data for later.
119
     *
120
     * @return CacheInterface
121
     */
122
    public static function cache(?Cache $config = null, bool $getShared = true)
123
    {
124
        if ($getShared) {
2,054✔
125
            return static::getSharedInstance('cache', $config);
2,051✔
126
        }
127

128
        $config ??= config(Cache::class);
2,054✔
129

130
        return CacheFactory::getHandler($config);
2,054✔
131
    }
132

133
    /**
134
     * The CLI Request class provides for ways to interact with
135
     * a command line request.
136
     *
137
     * @return CLIRequest
138
     *
139
     * @internal
140
     */
141
    public static function clirequest(?App $config = null, bool $getShared = true)
142
    {
143
        if ($getShared) {
18✔
144
            return static::getSharedInstance('clirequest', $config);
13✔
145
        }
146

147
        $config ??= config(App::class);
11✔
148

149
        return new CLIRequest($config);
11✔
150
    }
151

152
    /**
153
     * CodeIgniter, the core of the framework.
154
     *
155
     * @return CodeIgniter
156
     */
157
    public static function codeigniter(?App $config = null, bool $getShared = true)
158
    {
159
        if ($getShared) {
2✔
UNCOV
160
            return static::getSharedInstance('codeigniter', $config);
×
161
        }
162

163
        $config ??= config(App::class);
2✔
164

165
        return new CodeIgniter($config);
2✔
166
    }
167

168
    /**
169
     * The commands utility for running and working with CLI commands.
170
     *
171
     * @return Commands
172
     */
173
    public static function commands(bool $getShared = true)
174
    {
175
        if ($getShared) {
70✔
176
            return static::getSharedInstance('commands');
68✔
177
        }
178

179
        return new Commands();
70✔
180
    }
181

182
    /**
183
     * Content Security Policy
184
     *
185
     * @return ContentSecurityPolicy
186
     */
187
    public static function csp(?CSPConfig $config = null, bool $getShared = true)
188
    {
189
        if ($getShared) {
635✔
190
            return static::getSharedInstance('csp', $config);
633✔
191
        }
192

193
        $config ??= config(ContentSecurityPolicyConfig::class);
635✔
194

195
        return new ContentSecurityPolicy($config);
635✔
196
    }
197

198
    /**
199
     * The CURL Request class acts as a simple HTTP client for interacting
200
     * with other servers, typically through APIs.
201
     *
202
     * @todo v4.8.0 Remove $config parameter since unused
203
     *
204
     * @return CURLRequest
205
     */
206
    public static function curlrequest(array $options = [], ?ResponseInterface $response = null, ?App $config = null, bool $getShared = true)
207
    {
208
        if ($getShared) {
5✔
209
            return static::getSharedInstance('curlrequest', $options, $response, $config);
3✔
210
        }
211

212
        $config ??= config(App::class);
5✔
213
        $response ??= new Response();
5✔
214

215
        return new CURLRequest(
5✔
216
            $config,
5✔
217
            new URI($options['baseURI'] ?? null),
5✔
218
            $response,
5✔
219
            $options,
5✔
220
        );
5✔
221
    }
222

223
    /**
224
     * The Email class allows you to send email via mail, sendmail, SMTP.
225
     *
226
     * @param array|EmailConfig|null $config
227
     *
228
     * @return Email
229
     */
230
    public static function email($config = null, bool $getShared = true)
231
    {
232
        if ($getShared) {
5✔
233
            return static::getSharedInstance('email', $config);
1✔
234
        }
235

236
        if (empty($config) || (! is_array($config) && ! $config instanceof EmailConfig)) {
4✔
237
            $config = config(EmailConfig::class);
3✔
238
        }
239

240
        return new Email($config);
4✔
241
    }
242

243
    /**
244
     * The Encryption class provides two-way encryption.
245
     *
246
     * @param bool $getShared
247
     *
248
     * @return EncrypterInterface Encryption handler
249
     */
250
    public static function encrypter(?EncryptionConfig $config = null, $getShared = false)
251
    {
252
        if ($getShared === true) {
7✔
253
            return static::getSharedInstance('encrypter', $config);
1✔
254
        }
255

256
        $config ??= config(EncryptionConfig::class);
7✔
257
        $encryption = new Encryption($config);
7✔
258

259
        return $encryption->initialize($config);
6✔
260
    }
261

262
    /**
263
     * The Exceptions class holds the methods that handle:
264
     *
265
     *  - set_exception_handler
266
     *  - set_error_handler
267
     *  - register_shutdown_function
268
     *
269
     * @return Exceptions
270
     */
271
    public static function exceptions(
272
        ?ExceptionsConfig $config = null,
273
        bool $getShared = true,
274
    ) {
275
        if ($getShared) {
4✔
276
            return static::getSharedInstance('exceptions', $config);
1✔
277
        }
278

279
        $config ??= config(ExceptionsConfig::class);
4✔
280

281
        return new Exceptions($config);
4✔
282
    }
283

284
    /**
285
     * Filters allow you to run tasks before and/or after a controller
286
     * is executed. During before filters, the request can be modified,
287
     * and actions taken based on the request, while after filters can
288
     * act on or modify the response itself before it is sent to the client.
289
     *
290
     * @return Filters
291
     */
292
    public static function filters(?FiltersConfig $config = null, bool $getShared = true)
293
    {
294
        if ($getShared) {
138✔
295
            return static::getSharedInstance('filters', $config);
136✔
296
        }
297

298
        $config ??= config(FiltersConfig::class);
138✔
299

300
        return new Filters($config, AppServices::get('request'), AppServices::get('response'));
138✔
301
    }
302

303
    /**
304
     * The Format class is a convenient place to create Formatters.
305
     *
306
     * @return Format
307
     */
308
    public static function format(?FormatConfig $config = null, bool $getShared = true)
309
    {
310
        if ($getShared) {
33✔
311
            return static::getSharedInstance('format', $config);
30✔
312
        }
313

314
        $config ??= config(FormatConfig::class);
33✔
315

316
        return new Format($config);
33✔
317
    }
318

319
    /**
320
     * The Honeypot provides a secret input on forms that bots should NOT
321
     * fill in, providing an additional safeguard when accepting user input.
322
     *
323
     * @return Honeypot
324
     */
325
    public static function honeypot(?HoneypotConfig $config = null, bool $getShared = true)
326
    {
327
        if ($getShared) {
7✔
328
            return static::getSharedInstance('honeypot', $config);
5✔
329
        }
330

331
        $config ??= config(HoneypotConfig::class);
7✔
332

333
        return new Honeypot($config);
7✔
334
    }
335

336
    /**
337
     * Acts as a factory for ImageHandler classes and returns an instance
338
     * of the handler. Used like service('image')->withFile($path)->rotate(90)->save();
339
     *
340
     * @return BaseHandler
341
     */
342
    public static function image(?string $handler = null, ?Images $config = null, bool $getShared = true)
343
    {
344
        if ($getShared) {
87✔
345
            return static::getSharedInstance('image', $handler, $config);
1✔
346
        }
347

348
        $config ??= config(Images::class);
87✔
349
        assert($config instanceof Images);
350

351
        $handler = in_array($handler, [null, '', '0'], true) ? $config->defaultHandler : $handler;
87✔
352
        $class   = $config->handlers[$handler];
87✔
353

354
        return new $class($config);
87✔
355
    }
356

357
    /**
358
     * The Iterator class provides a simple way of looping over a function
359
     * and timing the results and memory usage. Used when debugging and
360
     * optimizing applications.
361
     *
362
     * @return Iterator
363
     */
364
    public static function iterator(bool $getShared = true)
365
    {
366
        if ($getShared) {
3✔
367
            return static::getSharedInstance('iterator');
1✔
368
        }
369

370
        return new Iterator();
3✔
371
    }
372

373
    /**
374
     * Responsible for loading the language string translations.
375
     *
376
     * @return Language
377
     */
378
    public static function language(?string $locale = null, bool $getShared = true)
379
    {
380
        if ($getShared) {
503✔
381
            return static::getSharedInstance('language', $locale)->setLocale($locale);
492✔
382
        }
383

384
        if (AppServices::get('request') instanceof IncomingRequest) {
502✔
385
            $requestLocale = AppServices::get('request')->getLocale();
501✔
386
        } else {
387
            $requestLocale = Locale::getDefault();
1✔
388
        }
389

390
        // Use '?:' for empty string check
391
        $locale = in_array($locale, [null, '', '0'], true) ? $requestLocale : $locale;
502✔
392

393
        return new Language($locale);
502✔
394
    }
395

396
    /**
397
     * The Logger class is a PSR-3 compatible Logging class that supports
398
     * multiple handlers that process the actual logging.
399
     *
400
     * @return Logger
401
     */
402
    public static function logger(bool $getShared = true)
403
    {
404
        if ($getShared) {
333✔
405
            return static::getSharedInstance('logger');
331✔
406
        }
407

408
        return new Logger(config(LoggerConfig::class));
331✔
409
    }
410

411
    /**
412
     * Return the appropriate Migration runner.
413
     *
414
     * @return MigrationRunner
415
     */
416
    public static function migrations(?Migrations $config = null, ?ConnectionInterface $db = null, bool $getShared = true)
417
    {
418
        if ($getShared) {
823✔
419
            return static::getSharedInstance('migrations', $config, $db);
2✔
420
        }
421

422
        $config ??= config(Migrations::class);
823✔
423

424
        return new MigrationRunner($config, $db);
823✔
425
    }
426

427
    /**
428
     * The Negotiate class provides the content negotiation features for
429
     * working the request to determine correct language, encoding, charset,
430
     * and more.
431
     *
432
     * @return Negotiate
433
     */
434
    public static function negotiator(?RequestInterface $request = null, bool $getShared = true)
435
    {
436
        if ($getShared) {
11✔
437
            return static::getSharedInstance('negotiator', $request);
9✔
438
        }
439

440
        $request ??= AppServices::get('request');
5✔
441

442
        return new Negotiate($request);
5✔
443
    }
444

445
    /**
446
     * Return the ResponseCache.
447
     *
448
     * @return ResponseCache
449
     */
450
    public static function responsecache(?Cache $config = null, ?CacheInterface $cache = null, bool $getShared = true)
451
    {
452
        if ($getShared) {
7,356✔
453
            return static::getSharedInstance('responsecache', $config, $cache);
7,356✔
454
        }
455

456
        $config ??= config(Cache::class);
2,053✔
457
        $cache ??= AppServices::get('cache');
2,053✔
458

459
        return new ResponseCache($config, $cache);
2,053✔
460
    }
461

462
    /**
463
     * Return the appropriate pagination handler.
464
     *
465
     * @return Pager
466
     */
467
    public static function pager(?PagerConfig $config = null, ?RendererInterface $view = null, bool $getShared = true)
468
    {
469
        if ($getShared) {
12✔
470
            return static::getSharedInstance('pager', $config, $view);
10✔
471
        }
472

473
        $config ??= config(PagerConfig::class);
12✔
474
        $view ??= AppServices::renderer(null, null, false);
12✔
475

476
        return new Pager($config, $view);
12✔
477
    }
478

479
    /**
480
     * The Parser is a simple template parser.
481
     *
482
     * @return Parser
483
     */
484
    public static function parser(?string $viewPath = null, ?ViewConfig $config = null, bool $getShared = true)
485
    {
486
        if ($getShared) {
14✔
487
            return static::getSharedInstance('parser', $viewPath, $config);
12✔
488
        }
489

490
        $viewPath = in_array($viewPath, [null, '', '0'], true) ? (new Paths())->viewDirectory : $viewPath;
14✔
491
        $config ??= config(ViewConfig::class);
14✔
492

493
        return new Parser($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));
14✔
494
    }
495

496
    /**
497
     * The Renderer class is the class that actually displays a file to the user.
498
     * The default View class within CodeIgniter is intentionally simple, but this
499
     * service could easily be replaced by a template engine if the user needed to.
500
     *
501
     * @return View
502
     */
503
    public static function renderer(?string $viewPath = null, ?ViewConfig $config = null, bool $getShared = true)
504
    {
505
        if ($getShared) {
205✔
506
            return static::getSharedInstance('renderer', $viewPath, $config);
191✔
507
        }
508

509
        $viewPath = in_array($viewPath, [null, '', '0'], true) ? (new Paths())->viewDirectory : $viewPath;
205✔
510
        $config ??= config(ViewConfig::class);
205✔
511

512
        return new View($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));
205✔
513
    }
514

515
    /**
516
     * Returns the current Request object.
517
     *
518
     * createRequest() injects IncomingRequest or CLIRequest.
519
     *
520
     * @return CLIRequest|IncomingRequest
521
     */
522
    public static function request()
523
    {
524
        return static::$instances['request'] ?? static::incomingrequest(getShared: false);
2,861✔
525
    }
526

527
    /**
528
     * Create the current Request object, either IncomingRequest or CLIRequest.
529
     *
530
     * This method is called from CodeIgniter::getRequestObject().
531
     *
532
     * @internal
533
     */
534
    public static function createRequest(App $config, bool $isCli = false): void
535
    {
536
        if ($isCli) {
78✔
537
            $request = AppServices::clirequest($config);
12✔
538
        } else {
539
            $request = AppServices::incomingrequest($config);
66✔
540

541
            // guess at protocol if needed
542
            $request->setProtocolVersion(static::superglobals()->server('SERVER_PROTOCOL', 'HTTP/1.1'));
66✔
543
        }
544

545
        // Inject the request object into Services.
546
        static::$instances['request'] = $request;
78✔
547
    }
548

549
    /**
550
     * The IncomingRequest class models an HTTP request.
551
     *
552
     * @return IncomingRequest
553
     *
554
     * @internal
555
     */
556
    public static function incomingrequest(?App $config = null, bool $getShared = true)
557
    {
558
        if ($getShared) {
2,905✔
559
            return static::getSharedInstance('request', $config);
67✔
560
        }
561

562
        $config ??= config(App::class);
2,905✔
563

564
        return new IncomingRequest(
2,905✔
565
            $config,
2,905✔
566
            AppServices::get('uri'),
2,905✔
567
            'php://input',
2,905✔
568
            new UserAgent(),
2,905✔
569
        );
2,905✔
570
    }
571

572
    /**
573
     * The Response class models an HTTP response.
574
     *
575
     * @todo v4.8.0 Remove $config parameter since unused
576
     *
577
     * @return ResponseInterface
578
     */
579
    public static function response(?App $config = null, bool $getShared = true)
580
    {
581
        if ($getShared) {
348✔
582
            return static::getSharedInstance('response', $config);
304✔
583
        }
584

585
        return new Response();
341✔
586
    }
587

588
    /**
589
     * The Redirect class provides nice way of working with redirects.
590
     *
591
     * @todo v4.8.0 Remove $config parameter since unused
592
     *
593
     * @return RedirectResponse
594
     */
595
    public static function redirectresponse(?App $config = null, bool $getShared = true)
596
    {
597
        if ($getShared) {
15✔
598
            return static::getSharedInstance('redirectresponse', $config);
11✔
599
        }
600

601
        $response = new RedirectResponse();
15✔
602
        $response->setProtocolVersion(AppServices::get('request')->getProtocolVersion());
15✔
603

604
        return $response;
15✔
605
    }
606

607
    /**
608
     * The Routes service is a class that allows for easily building
609
     * a collection of routes.
610
     *
611
     * @return RouteCollection
612
     */
613
    public static function routes(bool $getShared = true)
614
    {
615
        if ($getShared) {
246✔
616
            return static::getSharedInstance('routes');
244✔
617
        }
618

619
        return new RouteCollection(AppServices::get('locator'), new Modules(), config(Routing::class));
246✔
620
    }
621

622
    /**
623
     * The Router class uses a RouteCollection's array of routes, and determines
624
     * the correct Controller and Method to execute.
625
     *
626
     * @return Router
627
     */
628
    public static function router(?RouteCollectionInterface $routes = null, ?Request $request = null, bool $getShared = true)
629
    {
630
        if ($getShared) {
104✔
631
            return static::getSharedInstance('router', $routes, $request);
102✔
632
        }
633

634
        $routes ??= AppServices::get('routes');
101✔
635
        $request ??= AppServices::get('request');
101✔
636

637
        return new Router($routes, $request);
101✔
638
    }
639

640
    /**
641
     * The Security class provides a few handy tools for keeping the site
642
     * secure, most notably the CSRF protection tools.
643
     *
644
     * @return Security
645
     */
646
    public static function security(?SecurityConfig $config = null, bool $getShared = true)
647
    {
648
        if ($getShared) {
13✔
649
            return static::getSharedInstance('security', $config);
11✔
650
        }
651

652
        $config ??= config(SecurityConfig::class);
12✔
653

654
        return new Security($config);
12✔
655
    }
656

657
    /**
658
     * Return the session manager.
659
     *
660
     * @return Session
661
     */
662
    public static function session(?SessionConfig $config = null, bool $getShared = true)
663
    {
664
        if ($getShared) {
53✔
665
            return static::getSharedInstance('session', $config);
46✔
666
        }
667

668
        $config ??= config(SessionConfig::class);
52✔
669

670
        $logger = AppServices::get('logger');
52✔
671

672
        $driverName = $config->driver;
52✔
673

674
        if ($driverName === DatabaseHandler::class) {
52✔
675
            $DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
1✔
676

677
            $driverPlatform = Database::connect($DBGroup)->getPlatform();
1✔
678

679
            if ($driverPlatform === 'MySQLi') {
1✔
UNCOV
680
                $driverName = MySQLiHandler::class;
×
681
            } elseif ($driverPlatform === 'Postgre') {
1✔
UNCOV
682
                $driverName = PostgreHandler::class;
×
683
            } else {
684
                throw new InvalidArgumentException(sprintf(
1✔
685
                    'Invalid session database handler "%s" provided. Only "MySQLi" and "Postgre" are supported.',
1✔
686
                    $driverPlatform,
1✔
687
                ));
1✔
688
            }
689
        }
690

691
        if (! class_exists($driverName) || ! is_a($driverName, SessionBaseHandler::class, true)) {
51✔
692
            throw new InvalidArgumentException(sprintf(
3✔
693
                'Invalid session handler "%s" provided.',
3✔
694
                $driverName,
3✔
695
            ));
3✔
696
        }
697

698
        /** @var SessionBaseHandler $driver */
699
        $driver = new $driverName($config, AppServices::get('request')->getIPAddress());
48✔
700
        $driver->setLogger($logger);
48✔
701

702
        $session = new Session($driver, $config);
48✔
703
        $session->setLogger($logger);
48✔
704

705
        if (session_status() === PHP_SESSION_NONE) {
48✔
706
            // PHP Session emits the headers according to `session.cache_limiter`.
707
            // See https://www.php.net/manual/en/function.session-cache-limiter.php.
708
            // The headers are not managed by CI's Response class.
709
            // So, we remove CI's default Cache-Control header.
710
            AppServices::get('response')->removeHeader('Cache-Control');
48✔
711

712
            $session->start();
48✔
713
        }
714

715
        return $session;
48✔
716
    }
717

718
    /**
719
     * The Factory for SiteURI.
720
     *
721
     * @return SiteURIFactory
722
     */
723
    public static function siteurifactory(
724
        ?App $config = null,
725
        ?Superglobals $superglobals = null,
726
        bool $getShared = true,
727
    ) {
728
        if ($getShared) {
22✔
729
            return static::getSharedInstance('siteurifactory', $config, $superglobals);
17✔
730
        }
731

732
        $config ??= config('App');
22✔
733
        $superglobals ??= AppServices::get('superglobals');
22✔
734

735
        return new SiteURIFactory($config, $superglobals);
22✔
736
    }
737

738
    /**
739
     * Superglobals.
740
     *
741
     * @return Superglobals
742
     */
743
    public static function superglobals(
744
        ?array $server = null,
745
        ?array $get = null,
746
        ?array $post = null,
747
        ?array $cookie = null,
748
        ?array $files = null,
749
        ?array $request = null,
750
        bool $getShared = true,
751
    ) {
752
        if ($getShared) {
1,272✔
753
            return static::getSharedInstance('superglobals', $server, $get, $post, $cookie, $files, $request);
1,270✔
754
        }
755

756
        return new Superglobals($server, $get, $post, $cookie, $files, $request);
768✔
757
    }
758

759
    /**
760
     * The Throttler class provides a simple method for implementing
761
     * rate limiting in your applications.
762
     *
763
     * @return Throttler
764
     */
765
    public static function throttler(bool $getShared = true)
766
    {
767
        if ($getShared) {
4✔
768
            return static::getSharedInstance('throttler');
1✔
769
        }
770

771
        return new Throttler(AppServices::get('cache'));
4✔
772
    }
773

774
    /**
775
     * The Timer class provides a simple way to Benchmark portions of your
776
     * application.
777
     *
778
     * @return Timer
779
     */
780
    public static function timer(bool $getShared = true)
781
    {
782
        if ($getShared) {
108✔
783
            return static::getSharedInstance('timer');
106✔
784
        }
785

786
        return new Timer();
106✔
787
    }
788

789
    /**
790
     * Return the debug toolbar.
791
     *
792
     * @return Toolbar
793
     */
794
    public static function toolbar(?ToolbarConfig $config = null, bool $getShared = true)
795
    {
796
        if ($getShared) {
96✔
797
            return static::getSharedInstance('toolbar', $config);
94✔
798
        }
799

800
        $config ??= config(ToolbarConfig::class);
96✔
801

802
        return new Toolbar($config);
96✔
803
    }
804

805
    /**
806
     * The URI class provides a way to model and manipulate URIs.
807
     *
808
     * @param string|null $uri The URI string
809
     *
810
     * @return URI The current URI if $uri is null.
811
     */
812
    public static function uri(?string $uri = null, bool $getShared = true)
813
    {
814
        if ($getShared) {
×
UNCOV
815
            return static::getSharedInstance('uri', $uri);
×
816
        }
817

818
        if ($uri === null) {
×
819
            $appConfig = config(App::class);
×
UNCOV
820
            $factory   = AppServices::siteurifactory($appConfig, AppServices::get('superglobals'));
×
821

UNCOV
822
            return $factory->createFromGlobals();
×
823
        }
824

UNCOV
825
        return new URI($uri);
×
826
    }
827

828
    /**
829
     * The Validation class provides tools for validating input data.
830
     *
831
     * @return ValidationInterface
832
     */
833
    public static function validation(?ValidationConfig $config = null, bool $getShared = true)
834
    {
835
        if ($getShared) {
120✔
836
            return static::getSharedInstance('validation', $config);
21✔
837
        }
838

839
        $config ??= config(ValidationConfig::class);
120✔
840

841
        return new Validation($config, AppServices::get('renderer'));
120✔
842
    }
843

844
    /**
845
     * View cells are intended to let you insert HTML into view
846
     * that has been generated by any callable in the system.
847
     *
848
     * @return Cell
849
     */
850
    public static function viewcell(bool $getShared = true)
851
    {
852
        if ($getShared) {
6✔
853
            return static::getSharedInstance('viewcell');
3✔
854
        }
855

856
        return new Cell(AppServices::get('cache'));
6✔
857
    }
858

859
    /**
860
     * The Typography class provides a way to format text in semantically relevant ways.
861
     *
862
     * @return Typography
863
     */
864
    public static function typography(bool $getShared = true)
865
    {
866
        if ($getShared) {
5✔
867
            return static::getSharedInstance('typography');
3✔
868
        }
869

870
        return new Typography();
5✔
871
    }
872

873
    /**
874
     * The Context class provides a way to store and retrieve static data throughout requests.
875
     */
876
    public static function context(bool $getShared = true): Context
877
    {
878
        if ($getShared) {
65✔
879
            return static::getSharedInstance('context');
2✔
880
        }
881

882
        return new Context();
65✔
883
    }
884
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc