1010 */
1111
1212use CodeIgniter \Cache \CacheInterface ;
13+ use CodeIgniter \Config \BaseConfig ;
1314use CodeIgniter \Config \Factories ;
1415use CodeIgniter \Cookie \Cookie ;
1516use CodeIgniter \Cookie \CookieStore ;
3132use CodeIgniter \Test \TestLogger ;
3233use Config \App ;
3334use Config \Database ;
35+ use Config \DocTypes ;
3436use Config \Logger ;
3537use Config \Services ;
3638use Config \View ;
4749 */
4850 function app_timezone (): string
4951 {
50- /** @var App $config */
51- $ config = config ('App ' );
52+ $ config = config (App::class);
5253
5354 return $ config ->appTimezone ;
5455 }
@@ -90,7 +91,11 @@ function cache(?string $key = null)
9091 function clean_path (string $ path ): string
9192 {
9293 // Resolve relative paths
93- $ path = realpath ($ path ) ?: $ path ;
94+ try {
95+ $ path = realpath ($ path ) ?: $ path ;
96+ } catch (ErrorException |ValueError $ e ) {
97+ $ path = 'error file path: ' . urlencode ($ path );
98+ }
9499
95100 switch (true ) {
96101 case strpos ($ path , APPPATH ) === 0 :
@@ -199,7 +204,12 @@ function command(string $command)
199204 /**
200205 * More simple way of getting config instances from Factories
201206 *
202- * @return object|null
207+ * @template ConfigTemplate of BaseConfig
208+ *
209+ * @param class-string<ConfigTemplate>|string $name
210+ *
211+ * @return ConfigTemplate|null
212+ * @phpstan-return ($name is class-string<ConfigTemplate> ? ConfigTemplate : object|null)
203213 */
204214 function config (string $ name , bool $ getShared = true )
205215 {
@@ -491,7 +501,7 @@ function force_https(int $duration = 31_536_000, ?RequestInterface $request = nu
491501 Services::session (null , true )->regenerate (); // @codeCoverageIgnore
492502 }
493503
494- $ baseURL = config (' App ' )->baseURL ;
504+ $ baseURL = config (App::class )->baseURL ;
495505
496506 if (strpos ($ baseURL , 'https:// ' ) === 0 ) {
497507 $ authority = substr ($ baseURL , strlen ('https:// ' ));
@@ -807,11 +817,12 @@ function log_message(string $level, string $message, array $context = [])
807817 /**
808818 * More simple way of getting model instances from Factories
809819 *
810- * @template T of Model
820+ * @template ModelTemplate of Model
811821 *
812- * @param class-string<T> $name
822+ * @param class-string<ModelTemplate>|string $name
813823 *
814- * @return T
824+ * @return ModelTemplate|null
825+ * @phpstan-return ($name is class-string<ModelTemplate> ? ModelTemplate : object|null)
815826 */
816827 function model (string $ name , bool $ getShared = true , ?ConnectionInterface &$ conn = null )
817828 {
@@ -859,7 +870,7 @@ function old(string $key, $default = null, $escape = 'html')
859870 *
860871 * If more control is needed, you must use $response->redirect explicitly.
861872 *
862- * @param string $route
873+ * @param string|null $route Route name or Controller::method
863874 */
864875 function redirect (?string $ route = null ): RedirectResponse
865876 {
@@ -881,7 +892,7 @@ function redirect(?string $route = null): RedirectResponse
881892 */
882893 function _solidus (): string
883894 {
884- if (config (' DocTypes ' )->html5 ?? false ) {
895+ if (config (DocTypes::class )->html5 ?? false ) {
885896 return '' ;
886897 }
887898
@@ -941,18 +952,18 @@ function response(): ResponseInterface
941952
942953if (! function_exists ('route_to ' )) {
943954 /**
944- * Given a controller/method string and any params,
955+ * Given a route name or controller/method string and any params,
945956 * will attempt to build the relative URL to the
946957 * matching route.
947958 *
948959 * NOTE: This requires the controller/method to
949960 * have a route defined in the routes Config file.
950961 *
951- * @param string $method Named route or Controller::method
962+ * @param string $method Route name or Controller::method
952963 * @param int|string ...$params One or more parameters to be passed to the route.
953964 * The last parameter allows you to set the locale.
954965 *
955- * @return false|string
966+ * @return false|string The route (URI path relative to baseURL) or false if not found.
956967 */
957968 function route_to (string $ method , ...$ params )
958969 {
@@ -969,8 +980,6 @@ function route_to(string $method, ...$params)
969980 * session()->set('foo', 'bar');
970981 * $foo = session('bar');
971982 *
972- * @param string $val
973- *
974983 * @return array|bool|float|int|object|Session|string|null
975984 * @phpstan-return ($val is null ? Session : array|bool|float|int|object|string|null)
976985 */
@@ -1060,7 +1069,7 @@ function single_service(string $name, ...$params)
10601069 */
10611070 function slash_item (string $ item ): ?string
10621071 {
1063- $ config = config (' App ' );
1072+ $ config = config (App::class );
10641073
10651074 if (! property_exists ($ config , $ item )) {
10661075 return null ;
@@ -1162,10 +1171,8 @@ function timer(?string $name = null, ?callable $callable = null)
11621171 */
11631172 function view (string $ name , array $ data = [], array $ options = []): string
11641173 {
1165- /** @var CodeIgniter\View\View $renderer */
11661174 $ renderer = Services::renderer ();
11671175
1168- /** @var \CodeIgniter\Config\View $config */
11691176 $ config = config (View::class);
11701177 $ saveData = $ config ->saveData ;
11711178
0 commit comments