Skip to content

Commit a9fa3d0

Browse files
authored
Merge pull request #9248 from neznaika0/fix-call-as-service
perf: Improve call as `service()`
2 parents 3346b6f + ea38947 commit a9fa3d0

File tree

99 files changed

+336
-420
lines changed

Some content is hidden

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

99 files changed

+336
-420
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
use CodeIgniter\HTTP\Header;
3-
use Config\Services;
43
use CodeIgniter\CodeIgniter;
54

65
$errorId = uniqid('error', true);
@@ -225,7 +224,7 @@
225224

226225
<!-- Request -->
227226
<div class="content" id="request">
228-
<?php $request = Services::request(); ?>
227+
<?php $request = service('request'); ?>
229228

230229
<table>
231230
<tbody>
@@ -343,7 +342,7 @@
343342

344343
<!-- Response -->
345344
<?php
346-
$response = Services::response();
345+
$response = service('response');
347346
$response->setStatusCode(http_response_code());
348347
?>
349348
<div class="content" id="response">

phpstan-baseline.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18361,12 +18361,6 @@
1836118361
'count' => 1,
1836218362
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
1836318363
];
18364-
$ignoreErrors[] = [
18365-
// identifier: missingType.iterableValue
18366-
'message' => '#^Method class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#',
18367-
'count' => 1,
18368-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18369-
];
1837018364
$ignoreErrors[] = [
1837118365
// identifier: argument.type
1837218366
'message' => '#^Parameter \\#2 \\$context of method CodeIgniter\\\\View\\\\Parser\\:\\:setData\\(\\) expects \'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null, \'unknown\' given\\.$#',
@@ -18379,18 +18373,6 @@
1837918373
'count' => 1,
1838018374
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
1838118375
];
18382-
$ignoreErrors[] = [
18383-
// identifier: missingType.property
18384-
'message' => '#^Property class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:\\$bar has no type specified\\.$#',
18385-
'count' => 1,
18386-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18387-
];
18388-
$ignoreErrors[] = [
18389-
// identifier: missingType.property
18390-
'message' => '#^Property class@anonymous/tests/system/View/ParserTest\\.php\\:340\\:\\:\\$foo has no type specified\\.$#',
18391-
'count' => 1,
18392-
'path' => __DIR__ . '/tests/system/View/ParserTest.php',
18393-
];
1839418376
$ignoreErrors[] = [
1839518377
// identifier: method.notFound
1839618378
'message' => '#^Call to an undefined method CodeIgniter\\\\View\\\\Table\\:\\:compileTemplate\\(\\)\\.$#',

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);

0 commit comments

Comments
 (0)