Skip to content

Commit 3880337

Browse files
committed
refactor: use service() in framework code
1 parent 39bed21 commit 3880337

Some content is hidden

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

53 files changed

+131
-168
lines changed

system/API/ResponseTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CodeIgniter\Format\FormatterInterface;
1717
use CodeIgniter\HTTP\IncomingRequest;
1818
use CodeIgniter\HTTP\ResponseInterface;
19-
use Config\Services;
2019

2120
/**
2221
* Provides common, more readable, methods to provide
@@ -307,7 +306,7 @@ protected function failServerError(string $description = 'Internal Server Error'
307306
*/
308307
protected function format($data = null)
309308
{
310-
$format = Services::format();
309+
$format = service('format');
311310

312311
$mime = ($this->format === null) ? $format->getConfig()->supportedResponseFormats[0]
313312
: "application/{$this->format}";

system/BaseModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ public function errors(bool $forceDB = false)
12661266
public function paginate(?int $perPage = null, string $group = 'default', ?int $page = null, int $segment = 0)
12671267
{
12681268
// Since multiple models may use the Pager, the Pager must be shared.
1269-
$pager = Services::pager();
1269+
$pager = service('pager');
12701270

12711271
if ($segment !== 0) {
12721272
$pager->setSegment($segment, $group);

system/CLI/GeneratorTrait.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 Config\Generators;
17-
use Config\Services;
1817
use Throwable;
1918

2019
/**
@@ -417,7 +416,7 @@ protected function buildPath(string $class): string
417416
$namespace = $this->getNamespace();
418417

419418
// Check if the namespace is actually defined and we are not just typing gibberish.
420-
$base = Services::autoloader()->getNamespace($namespace);
419+
$base = service('autoloader')->getNamespace($namespace);
421420

422421
if (! $base = reset($base)) {
423422
CLI::error(

system/CodeIgniter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
462462
$uri = $this->request->getPath();
463463

464464
if ($this->enableFilters) {
465-
$filters = Services::filters();
465+
$filters = service('filters');
466466

467467
// If any filters were specified within the routes file,
468468
// we need to ensure it's active for the current request
@@ -518,7 +518,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
518518
$this->gatherOutput($cacheConfig, $returned);
519519

520520
if ($this->enableFilters) {
521-
$filters = Services::filters();
521+
$filters = service('filters');
522522
$filters->setResponse($this->response);
523523

524524
// Run "after" filters
@@ -649,7 +649,7 @@ protected function getRequestObject()
649649
Services::createRequest($this->config);
650650
}
651651

652-
$this->request = Services::request();
652+
$this->request = service('request');
653653

654654
$this->spoofRequestMethod();
655655
}
@@ -817,7 +817,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
817817
$this->benchmark->start('routing');
818818

819819
if ($routes === null) {
820-
$routes = Services::routes()->loadRoutes();
820+
$routes = service('routes')->loadRoutes();
821821
}
822822

823823
// $routes is defined in Config/Routes.php

system/Commands/Database/Migrate.php

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

1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
18-
use Config\Services;
1918
use Throwable;
2019

2120
/**
@@ -68,7 +67,7 @@ class Migrate extends BaseCommand
6867
*/
6968
public function run(array $params)
7069
{
71-
$runner = Services::migrations();
70+
$runner = service('migrations');
7271
$runner->clearCliMessages();
7372

7473
CLI::write(lang('Migrations.latest'), 'yellow');

system/Commands/Database/MigrateRollback.php

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

1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
18-
use Config\Services;
1918
use Throwable;
2019

2120
/**
@@ -79,7 +78,7 @@ public function run(array $params)
7978
// @codeCoverageIgnoreEnd
8079
}
8180

82-
$runner = Services::migrations();
81+
$runner = service('migrations');
8382

8483
try {
8584
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;

system/Commands/Database/MigrateStatus.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
18-
use Config\Services;
1918

2019
/**
2120
* Displays a list of all migrations and whether they've been run or not.
@@ -83,11 +82,11 @@ class MigrateStatus extends BaseCommand
8382
*/
8483
public function run(array $params)
8584
{
86-
$runner = Services::migrations();
85+
$runner = service('migrations');
8786
$paramGroup = $params['g'] ?? CLI::getOption('g');
8887

8988
// Get all namespaces
90-
$namespaces = Services::autoloader()->getNamespace();
89+
$namespaces = service('autoloader')->getNamespace();
9190

9291
// Collection of migration status
9392
$status = [];

system/Commands/Generators/TestGenerator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
1818
use CodeIgniter\CLI\GeneratorTrait;
19-
use Config\Services;
2019

2120
/**
2221
* Generates a skeleton command file.
@@ -82,7 +81,7 @@ public function run(array $params)
8281

8382
$this->classNameLang = 'CLI.generator.className.test';
8483

85-
$autoload = Services::autoloader();
84+
$autoload = service('autoloader');
8685
$autoload->addNamespace('CodeIgniter', TESTPATH . 'system');
8786
$autoload->addNamespace('Tests', ROOTPATH . 'tests');
8887

@@ -112,7 +111,7 @@ protected function getNamespace(): string
112111
$class = $this->normalizeInputClassName();
113112
$classPaths = explode('\\', $class);
114113

115-
$namespaces = Services::autoloader()->getNamespace();
114+
$namespaces = service('autoloader')->getNamespace();
116115

117116
while ($classPaths !== []) {
118117
array_pop($classPaths);
@@ -176,7 +175,7 @@ protected function buildPath(string $class): string
176175
*/
177176
private function searchTestFilePath(string $namespace): ?string
178177
{
179-
$bases = Services::autoloader()->getNamespace($namespace);
178+
$bases = service('autoloader')->getNamespace($namespace);
180179

181180
$base = null;
182181

system/Commands/Utilities/FilterCheck.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
1818
use CodeIgniter\Commands\Utilities\Routes\FilterCollector;
19-
use Config\Services;
2019

2120
/**
2221
* Check filters for a route.
@@ -88,7 +87,7 @@ public function run(array $params)
8887
$route = $params[1];
8988

9089
// Load Routes
91-
Services::routes()->loadRoutes();
90+
service('routes')->loadRoutes();
9291

9392
$filterCollector = new FilterCollector();
9493

system/Commands/Utilities/Namespaces.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
1818
use Config\Autoload;
19-
use Config\Services;
2019

2120
/**
2221
* Lists namespaces set in Config\Autoload with their
@@ -96,7 +95,7 @@ private function outputAllNamespaces(array $params): array
9695
{
9796
$maxLength = $params['m'];
9897

99-
$autoloader = Services::autoloader();
98+
$autoloader = service('autoloader');
10099

101100
$tbody = [];
102101

0 commit comments

Comments
 (0)