Skip to content

Commit d86dfca

Browse files
committed
refactor: up performance service()
1 parent 65872e5 commit d86dfca

File tree

98 files changed

+325
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+325
-395
lines changed

admin/starter/tests/session/ExampleSessionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use CodeIgniter\Test\CIUnitTestCase;
4-
use Config\Services;
54

65
/**
76
* @internal
@@ -10,7 +9,7 @@ final class ExampleSessionTest extends CIUnitTestCase
109
{
1110
public function testSessionSimple(): void
1211
{
13-
$session = Services::session();
12+
$session = service('session');
1413

1514
$session->set('logged_in', 123);
1615
$this->assertSame(123, $session->get('logged_in'));

admin/starter/tests/unit/HealthTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use CodeIgniter\Test\CIUnitTestCase;
44
use Config\App;
5-
use Config\Services;
65
use Tests\Support\Libraries\ConfigReader;
76

87
/**
@@ -17,7 +16,7 @@ public function testIsDefinedAppPath(): void
1716

1817
public function testBaseUrlHasBeenSet(): void
1918
{
20-
$validation = Services::validation();
19+
$validation = service('validation');
2120

2221
$env = false;
2322

app/Config/Events.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
*/
4545
if (CI_DEBUG && ! is_cli()) {
4646
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
47-
Services::toolbar()->respond();
47+
service('toolbar')->respond();
4848
// Hot Reload route - for framework use on the hot reloader.
4949
if (ENVIRONMENT === 'development') {
50-
Services::routes()->get('__hot-reload', static function (): void {
50+
service('routes')->get('__hot-reload', static function (): void {
5151
(new HotReloader())->run();
5252
});
5353
}

app/Config/Format.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ class Format extends BaseConfig
7272
*/
7373
public function getFormatter(string $mime)
7474
{
75-
return Services::format()->getFormatter($mime);
75+
return service('format')->getFormatter($mime);
7676
}
7777
}

app/Controllers/BaseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ public function initController(RequestInterface $request, ResponseInterface $res
5353

5454
// Preload any models, libraries, etc, here.
5555

56-
// E.g.: $this->session = \Config\Services::session();
56+
// E.g.: $this->session = service('session');
5757
}
5858
}

app/Views/errors/html/error_exception.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225

226226
<!-- Request -->
227227
<div class="content" id="request">
228-
<?php $request = Services::request(); ?>
228+
<?php $request = service('request'); ?>
229229

230230
<table>
231231
<tbody>
@@ -343,7 +343,7 @@
343343

344344
<!-- Response -->
345345
<?php
346-
$response = Services::response();
346+
$response = service('response');
347347
$response->setStatusCode(http_response_code());
348348
?>
349349
<div class="content" id="response">

system/Autoloader/Autoloader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Config\Autoload;
2020
use Config\Kint as KintConfig;
2121
use Config\Modules;
22-
use Config\Services;
2322
use InvalidArgumentException;
2423
use Kint;
2524
use Kint\Renderer\CliRenderer;
@@ -537,7 +536,7 @@ private function configureKint(): void
537536
Kint::$plugins = $config->plugins;
538537
}
539538

540-
$csp = Services::csp();
539+
$csp = service('csp');
541540
if ($csp->enabled()) {
542541
RichRenderer::$js_nonce = $csp->getScriptNonce();
543542
RichRenderer::$css_nonce = $csp->getStyleNonce();

system/BaseModel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use CodeIgniter\Pager\Pager;
2727
use CodeIgniter\Validation\ValidationInterface;
2828
use Config\Feature;
29-
use Config\Services;
3029
use InvalidArgumentException;
3130
use ReflectionClass;
3231
use ReflectionException;
@@ -1609,7 +1608,7 @@ public function getValidationRules(array $options = []): array
16091608
protected function ensureValidation(): void
16101609
{
16111610
if ($this->validation === null) {
1612-
$this->validation = Services::validation(null, false);
1611+
$this->validation = service('validation', null, false);
16131612
}
16141613
}
16151614

system/Boot.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ protected static function loadAutoloader(): void
246246

247247
protected static function autoloadHelpers(): void
248248
{
249-
Services::autoloader()->loadHelpers();
249+
service('autoloader')->loadHelpers();
250250
}
251251

252252
protected static function setExceptionHandler(): void
253253
{
254-
Services::exceptions()->initialize();
254+
service('exceptions')->initialize();
255255
}
256256

257257
protected static function checkMissingExtensions(): void
@@ -290,7 +290,7 @@ protected static function checkMissingExtensions(): void
290290

291291
protected static function initializeKint(): void
292292
{
293-
Services::autoloader()->initializeKint(CI_DEBUG);
293+
service('autoloader')->initializeKint(CI_DEBUG);
294294
}
295295

296296
protected static function loadConfigCache(): FactoriesCache
@@ -308,7 +308,7 @@ protected static function loadConfigCache(): FactoriesCache
308308
*/
309309
protected static function initializeCodeIgniter(): CodeIgniter
310310
{
311-
$app = Config\Services::codeigniter();
311+
$app = service('codeigniter');
312312
$app->initialize();
313313
$context = is_cli() ? 'php-cli' : 'web';
314314
$app->setContext($context);

system/CLI/CLI.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace CodeIgniter\CLI;
1515

1616
use CodeIgniter\CLI\Exceptions\CLIException;
17-
use Config\Services;
1817
use InvalidArgumentException;
1918
use Throwable;
2019

@@ -416,7 +415,7 @@ protected static function validate(string $field, string $value, $rules): bool
416415
{
417416
$label = $field;
418417
$field = 'temp';
419-
$validation = Services::validation(null, false);
418+
$validation = service('validation', null, false);
420419
$validation->setRules([
421420
$field => [
422421
'label' => $label,

0 commit comments

Comments
 (0)