Skip to content

Commit 889de06

Browse files
authored
Merge pull request #4593 from element-code/fix-replace-core-services
Fix new service replacement service provider precedence on core factory implementations
2 parents bbfa5c7 + 4339db0 commit 889de06

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

system/Config/BaseService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
use Config\Migrations;
6666
use Config\Modules;
6767
use Config\Pager as ConfigPager;
68+
use Config\Services as AppServices;
6869
use Config\Toolbar as ConfigToolbar;
6970
use Config\Validation as ConfigValidation;
7071
use Config\View as ConfigView;
@@ -83,6 +84,9 @@
8384
* is that IDEs are able to determine what class you are calling
8485
* whereas with DI Containers there usually isn't a way for them to do this.
8586
*
87+
* Warning: To allow overrides by service providers do not use static calls,
88+
* instead call out to \Config\Services (imported as AppServices).
89+
*
8690
* @see http://blog.ircmaxell.com/2015/11/simple-easy-risk-and-change.html
8791
* @see http://www.infoq.com/presentations/Simple-Made-Easy
8892
*
@@ -185,7 +189,7 @@ protected static function getSharedInstance(string $key, ...$params)
185189
// Make sure $getShared is false
186190
$params[] = false;
187191

188-
static::$instances[$key] = static::$key(...$params);
192+
static::$instances[$key] = AppServices::$key(...$params);
189193
}
190194

191195
return static::$instances[$key];

system/Config/Services.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
use Config\Toolbar as ToolbarConfig;
6969
use Config\Validation as ValidationConfig;
7070
use Config\View as ViewConfig;
71+
use Config\Services as AppServices;
7172

7273
/**
7374
* Services Configuration file.
@@ -275,8 +276,8 @@ public static function exceptions(
275276
}
276277

277278
$config = $config ?? config('Exceptions');
278-
$request = $request ?? static::request();
279-
$response = $response ?? static::response();
279+
$request = $request ?? AppServices::request();
280+
$response = $response ?? AppServices::response();
280281

281282
return new Exceptions($config, $request, $response);
282283
}
@@ -303,7 +304,7 @@ public static function filters(FiltersConfig $config = null, bool $getShared = t
303304

304305
$config = $config ?? config('Filters');
305306

306-
return new Filters($config, static::request(), static::response());
307+
return new Filters($config, AppServices::request(), AppServices::response());
307308
}
308309

309310
//--------------------------------------------------------------------
@@ -416,7 +417,7 @@ public static function language(string $locale = null, bool $getShared = true)
416417
}
417418

418419
// Use '?:' for empty string check
419-
$locale = $locale ?: static::request()->getLocale();
420+
$locale = $locale ?: AppServices::request()->getLocale();
420421

421422
return new Language($locale);
422423
}
@@ -483,7 +484,7 @@ public static function negotiator(RequestInterface $request = null, bool $getSha
483484
return static::getSharedInstance('negotiator', $request);
484485
}
485486

486-
$request = $request ?? static::request();
487+
$request = $request ?? AppServices::request();
487488

488489
return new Negotiate($request);
489490
}
@@ -507,7 +508,7 @@ public static function pager(PagerConfig $config = null, RendererInterface $view
507508
}
508509

509510
$config = $config ?? config('Pager');
510-
$view = $view ?? static::renderer();
511+
$view = $view ?? AppServices::renderer();
511512

512513
return new Pager($config, $view);
513514
}
@@ -533,7 +534,7 @@ public static function parser(string $viewPath = null, ViewConfig $config = null
533534
$viewPath = $viewPath ?: config('Paths')->viewDirectory;
534535
$config = $config ?? config('View');
535536

536-
return new Parser($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
537+
return new Parser($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger());
537538
}
538539

539540
//--------------------------------------------------------------------
@@ -559,7 +560,7 @@ public static function renderer(string $viewPath = null, ViewConfig $config = nu
559560
$viewPath = $viewPath ?: config('Paths')->viewDirectory;
560561
$config = $config ?? config('View');
561562

562-
return new View($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
563+
return new View($config, $viewPath, AppServices::locator(), CI_DEBUG, AppServices::logger());
563564
}
564565

565566
//--------------------------------------------------------------------
@@ -583,7 +584,7 @@ public static function request(App $config = null, bool $getShared = true)
583584

584585
return new IncomingRequest(
585586
$config,
586-
static::uri(),
587+
AppServices::uri(),
587588
'php://input',
588589
new UserAgent()
589590
);
@@ -630,7 +631,7 @@ public static function redirectresponse(App $config = null, bool $getShared = tr
630631

631632
$config = $config ?? config('App');
632633
$response = new RedirectResponse($config);
633-
$response->setProtocolVersion(static::request()->getProtocolVersion());
634+
$response->setProtocolVersion(AppServices::request()->getProtocolVersion());
634635

635636
return $response;
636637
}
@@ -652,7 +653,7 @@ public static function routes(bool $getShared = true)
652653
return static::getSharedInstance('routes');
653654
}
654655

655-
return new RouteCollection(static::locator(), config('Modules'));
656+
return new RouteCollection(AppServices::locator(), config('Modules'));
656657
}
657658

658659
//--------------------------------------------------------------------
@@ -674,8 +675,8 @@ public static function router(RouteCollectionInterface $routes = null, Request $
674675
return static::getSharedInstance('router', $routes, $request);
675676
}
676677

677-
$routes = $routes ?? static::routes();
678-
$request = $request ?? static::request();
678+
$routes = $routes ?? AppServices::routes();
679+
$request = $request ?? AppServices::request();
679680

680681
return new Router($routes, $request);
681682
}
@@ -721,10 +722,10 @@ public static function session(App $config = null, bool $getShared = true)
721722
}
722723

723724
$config = $config ?? config('App');
724-
$logger = static::logger();
725+
$logger = AppServices::logger();
725726

726727
$driverName = $config->sessionDriver;
727-
$driver = new $driverName($config, static::request()->getIPAddress());
728+
$driver = new $driverName($config, AppServices::request()->getIPAddress());
728729
$driver->setLogger($logger);
729730

730731
$session = new Session($driver, $config);
@@ -755,7 +756,7 @@ public static function throttler(bool $getShared = true)
755756
return static::getSharedInstance('throttler');
756757
}
757758

758-
return new Throttler(static::cache());
759+
return new Throttler(AppServices::cache());
759760
}
760761

761762
//--------------------------------------------------------------------
@@ -839,7 +840,7 @@ public static function validation(ValidationConfig $config = null, bool $getShar
839840

840841
$config = $config ?? config('Validation');
841842

842-
return new Validation($config, static::renderer());
843+
return new Validation($config, AppServices::renderer());
843844
}
844845

845846
//--------------------------------------------------------------------
@@ -859,7 +860,7 @@ public static function viewcell(bool $getShared = true)
859860
return static::getSharedInstance('viewcell');
860861
}
861862

862-
return new Cell(static::cache());
863+
return new Cell(AppServices::cache());
863864
}
864865

865866
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)