Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: add Factories::get() #8598

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
'count' => 5,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in &&, string given on the left side\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/BaseHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function property_exists\\(\\) with Config\\\\Cache and \'file\' will always evaluate to true\\.$#',
'count' => 1,
Expand Down Expand Up @@ -221,11 +216,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Commands/Utilities/Routes.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, Config\\\\Routing given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Commands/Utilities/Routes.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#',
'count' => 3,
Expand Down Expand Up @@ -346,11 +336,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Config/Services.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/Services.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -1296,11 +1281,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Events/Events.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Events\\\\Events\\:\\:on\\(\\) has parameter \\$callback with no signature specified for callable\\.$#',
'count' => 1,
Expand Down Expand Up @@ -1336,11 +1316,6 @@
'count' => 3,
'path' => __DIR__ . '/system/Files/File.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Filters/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down
3 changes: 2 additions & 1 deletion system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\CLI;

use CodeIgniter\Config\Factories;
use Config\Exceptions;
use Psr\Log\LoggerInterface;
use ReflectionException;
Expand Down Expand Up @@ -126,7 +127,7 @@ protected function showError(Throwable $e)
{
$exception = $e;
$message = $e->getMessage();
$config = config(Exceptions::class);
$config = Factories::get('config', Exceptions::class);

require $config->errorViewPath . '/cli/error_exception.php';
}
Expand Down
3 changes: 2 additions & 1 deletion system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CodeIgniter\CLI;

use CodeIgniter\CodeIgniter;
use CodeIgniter\Config\Factories;
use Config\App;
use Config\Services;
use Exception;
Expand All @@ -35,7 +36,7 @@ class Console
public function run()
{
// Create CLIRequest
$appConfig = config(App::class);
$appConfig = Factories::get('config', App::class);
Services::createRequest($appConfig, true);
// Load Routes
Services::routes()->loadRoutes();
Expand Down
3 changes: 2 additions & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\CLI;

use CodeIgniter\Config\Factories;
use Config\Generators;
use Config\Services;
use Throwable;
Expand Down Expand Up @@ -336,7 +337,7 @@ private function normalizeInputClassName(): string
protected function renderTemplate(array $data = []): string
{
try {
$template = $this->templatePath ?? config(Generators::class)->views[$this->name];
$template = $this->templatePath ?? Factories::get('config', Generators::class)->views[$this->name];

return view($template, $data, ['debug' => false]);
} catch (Throwable $e) {
Expand Down
3 changes: 2 additions & 1 deletion system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Closure;
use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\Factories;
use Config\Cache;
use Exception;
use InvalidArgumentException;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static function validateKey($key, $prefix = ''): string
throw new InvalidArgumentException('Cache key cannot be empty.');
}

$reserved = config(Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
$reserved = Factories::get('config', Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
if ($reserved && strpbrk($key, $reserved) !== false) {
throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved);
}
Expand Down
7 changes: 4 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Closure;
use CodeIgniter\Cache\ResponseCache;
use CodeIgniter\Config\Factories;
use CodeIgniter\Debug\Timer;
use CodeIgniter\Events\Events;
use CodeIgniter\Exceptions\FrameworkException;
Expand Down Expand Up @@ -355,7 +356,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
$this->response = $possibleResponse;
} else {
try {
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
$this->response = $this->handleRequest($routes, Factories::get('config', Cache::class), $returnResponse);
} catch (ResponsableInterface|DeprecatedRedirectException $e) {
$this->outputBufferingEnd();
if ($e instanceof DeprecatedRedirectException) {
Expand Down Expand Up @@ -469,7 +470,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
if ($routeFilters !== null) {
$filters->enableFilters($routeFilters, 'before');

if (! config(Feature::class)->oldFilterOrder) {
if (! Factories::get('config', Feature::class)->oldFilterOrder) {
$routeFilters = array_reverse($routeFilters);
}

Expand Down Expand Up @@ -965,7 +966,7 @@ protected function display404errors(PageNotFoundException $e)

unset($override);

$cacheConfig = config(Cache::class);
$cacheConfig = Factories::get('config', Cache::class);
$this->gatherOutput($cacheConfig, $returned);

return $this->response;
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Cache/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\Cache\CacheFactory;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\Factories;
use Config\Cache;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ class ClearCache extends BaseCommand
*/
public function run(array $params)
{
$config = config(Cache::class);
$config = Factories::get('config', Cache::class);
$handler = $params[0] ?? $config->handler;

if (! array_key_exists($handler, $config->validHandlers)) {
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Cache/InfoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\Cache\CacheFactory;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\Factories;
use CodeIgniter\I18n\Time;
use Config\Cache;

Expand Down Expand Up @@ -57,7 +58,7 @@ class InfoCache extends BaseCommand
*/
public function run(array $params)
{
$config = config(Cache::class);
$config = Factories::get('config', Cache::class);
helper('number');

if ($config->handler !== 'file') {
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function run(array $params)
}

try {
$config = config(Database::class);
$config = Factories::get('config', Database::class);

// Set to an empty database to prevent connection errors.
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;
Expand Down
5 changes: 3 additions & 2 deletions system/Commands/Generators/CellGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\GeneratorTrait;
use CodeIgniter\Config\Factories;
use Config\Generators;

/**
Expand Down Expand Up @@ -81,13 +82,13 @@ public function run(array $params)

$params = array_merge($params, ['suffix' => null]);

$this->templatePath = config(Generators::class)->views[$this->name]['class'];
$this->templatePath = Factories::get('config', Generators::class)->views[$this->name]['class'];
$this->template = 'cell.tpl.php';
$this->classNameLang = 'CLI.generator.className.cell';

$this->generateClass($params);

$this->templatePath = config(Generators::class)->views[$this->name]['view'];
$this->templatePath = Factories::get('config', Generators::class)->views[$this->name]['view'];
$this->template = 'cell_view.tpl.php';
$this->classNameLang = 'CLI.generator.viewName.cell';

Expand Down
5 changes: 3 additions & 2 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use CodeIgniter\Config\Factories;
use Config\Database;
use Config\Migrations;
use Config\Session as SessionConfig;
Expand Down Expand Up @@ -110,10 +111,10 @@ protected function prepare(string $class): string
$data['session'] = true;
$data['table'] = is_string($table) ? $table : 'ci_sessions';
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
$data['DBDriver'] = config(Database::class)->{$data['DBGroup']}['DBDriver'];
$data['DBDriver'] = Factories::get('config', Database::class)->{$data['DBGroup']}['DBDriver'];

/** @var SessionConfig|null $session */
$session = config(SessionConfig::class);
$session = Factories::get('config', SessionConfig::class);

$data['matchIP'] = $session->matchIP;
}
Expand Down
5 changes: 3 additions & 2 deletions system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\Factories;
use CodeIgniter\Helpers\Array\ArrayHelper;
use Config\App;
use Locale;
Expand Down Expand Up @@ -67,10 +68,10 @@ public function run(array $params)
}

if (is_string($optionLocale)) {
if (! in_array($optionLocale, config(App::class)->supportedLocales, true)) {
if (! in_array($optionLocale, Factories::get('config', App::class)->supportedLocales, true)) {
CLI::error(
'Error: "' . $optionLocale . '" is not supported. Supported locales: '
. implode(', ', config(App::class)->supportedLocales)
. implode(', ', Factories::get('config', App::class)->supportedLocales)
);

return EXIT_USER_INPUT;
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/ConfigCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Config\Factories;
use Kint\Kint;

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ public function run(array $params)
/** @var class-string<BaseConfig> $class */
$class = $params[0];

$config = config($class);
$config = Factories::get('config', $class);

if ($config === null) {
CLI::error('No such Config class: ' . $class);
Expand Down
5 changes: 3 additions & 2 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved\AutoRouteCollector as AutoRouteCollectorImproved;
use CodeIgniter\Commands\Utilities\Routes\FilterCollector;
use CodeIgniter\Commands\Utilities\Routes\SampleURIGenerator;
use CodeIgniter\Config\Factories;
use CodeIgniter\Router\DefinedRouteCollector;
use CodeIgniter\Router\Router;
use Config\Feature;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function run(array $params)
}

if ($collection->shouldAutoRoute()) {
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false;
$autoRoutesImproved = Factories::get('config', Feature::class)->autoRoutesImproved ?? false;

if ($autoRoutesImproved) {
$autoRouteCollector = new AutoRouteCollectorImproved(
Expand All @@ -140,7 +141,7 @@ public function run(array $params)
$autoRoutes = $autoRouteCollector->get();

// Check for Module Routes.
if ($routingConfig = config(Routing::class)) {
if ($routingConfig = Factories::get('config', Routing::class)) {
foreach ($routingConfig->moduleRoutes as $uri => $namespace) {
$autoRouteCollector = new AutoRouteCollectorImproved(
$namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Commands\Utilities\Routes\AutoRouterImproved;

use CodeIgniter\Config\Factories;
use Config\Routing;
use ReflectionClass;
use ReflectionMethod;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function __construct(string $namespace, array $httpMethods)
$this->namespace = $namespace;
$this->httpMethods = $httpMethods;

$config = config(Routing::class);
$config = Factories::get('config', Routing::class);
$this->translateURIDashes = $config->translateURIDashes;
$this->translateUriToCamelCase = $config->translateUriToCamelCase;
}
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Commands\Utilities\Routes;

use CodeIgniter\Config\Factories;
use CodeIgniter\Config\Services;
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Method;
Expand Down Expand Up @@ -112,7 +113,7 @@ private function createRouter(Request $request): Router

private function createFilters(Request $request): Filters
{
$config = config(FiltersConfig::class);
$config = Factories::get('config', FiltersConfig::class);

return new Filters($config, $request, Services::response());
}
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Commands\Utilities\Routes;

use CodeIgniter\Config\Factories;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Exceptions\RedirectException;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function find(string $uri): array

$this->filters->enableFilters($routeFilters, 'before');

if (! config(Feature::class)->oldFilterOrder) {
if (! Factories::get('config', Feature::class)->oldFilterOrder) {
$routeFilters = array_reverse($routeFilters);
}

Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/SampleURIGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Commands\Utilities\Routes;

use CodeIgniter\Config\Factories;
use CodeIgniter\Config\Services;
use CodeIgniter\Router\RouteCollection;
use Config\App;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function get(string $routeKey): string
if (strpos($routeKey, '{locale}') !== false) {
$sampleUri = str_replace(
'{locale}',
config(App::class)->defaultLocale,
Factories::get('config', App::class)->defaultLocale,
$routeKey
);
}
Expand Down
Loading
Loading