From ca09944c251e0a398c1348ba9f23fe5b64248e96 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 31 May 2024 14:28:22 +0700 Subject: [PATCH 1/8] docs: replace Service class to service() --- user_guide_src/source/concepts/services.rst | 8 +++++--- user_guide_src/source/concepts/services/002.php | 3 +++ user_guide_src/source/concepts/services/012.php | 2 +- user_guide_src/source/concepts/services/013.php | 2 +- user_guide_src/source/concepts/services/014.php | 2 +- user_guide_src/source/concepts/services/015.php | 4 ++-- user_guide_src/source/extending/basecontroller/003.php | 2 +- user_guide_src/source/general/common_functions.rst | 4 ++-- user_guide_src/source/general/errors/018.php | 2 +- .../source/incoming/content_negotiation/001.php | 2 +- user_guide_src/source/incoming/incomingrequest/002.php | 2 +- user_guide_src/source/incoming/incomingrequest/003.php | 2 +- user_guide_src/source/libraries/caching.rst | 2 +- user_guide_src/source/libraries/caching/002.php | 2 +- user_guide_src/source/libraries/cookies/002.php | 2 +- user_guide_src/source/libraries/cookies/003.php | 2 +- user_guide_src/source/libraries/cookies/007.php | 4 +--- user_guide_src/source/libraries/cookies/009.php | 3 +-- user_guide_src/source/libraries/cookies/010.php | 2 +- user_guide_src/source/libraries/cookies/013.php | 4 +--- user_guide_src/source/libraries/cookies/014.php | 1 - user_guide_src/source/libraries/cookies/015.php | 6 ++---- user_guide_src/source/libraries/cookies/017.php | 3 +-- user_guide_src/source/libraries/curlrequest.rst | 2 +- user_guide_src/source/libraries/curlrequest/002.php | 3 +++ user_guide_src/source/libraries/curlrequest/003.php | 2 +- user_guide_src/source/libraries/curlrequest/004.php | 6 ++++-- user_guide_src/source/libraries/curlrequest/005.php | 2 +- user_guide_src/source/libraries/curlrequest/008.php | 2 +- user_guide_src/source/libraries/email/001.php | 2 +- user_guide_src/source/libraries/encryption/001.php | 2 +- user_guide_src/source/libraries/encryption/003.php | 6 ++++-- user_guide_src/source/libraries/encryption/013.php | 5 ++--- user_guide_src/source/libraries/images.rst | 6 +++--- user_guide_src/source/libraries/images/001.php | 2 +- user_guide_src/source/libraries/images/002.php | 2 +- user_guide_src/source/libraries/images/007.php | 2 +- user_guide_src/source/libraries/images/008.php | 4 ++-- user_guide_src/source/libraries/images/009.php | 2 +- user_guide_src/source/libraries/images/010.php | 2 +- user_guide_src/source/libraries/images/011.php | 4 ++-- user_guide_src/source/libraries/images/012.php | 2 +- user_guide_src/source/libraries/images/013.php | 2 +- user_guide_src/source/libraries/images/014.php | 2 +- user_guide_src/source/libraries/pagination/001.php | 2 +- user_guide_src/source/libraries/pagination/002.php | 4 +++- user_guide_src/source/libraries/pagination/003.php | 4 +++- user_guide_src/source/libraries/pagination/004.php | 7 +++++-- user_guide_src/source/libraries/pagination/005.php | 4 +++- user_guide_src/source/libraries/pagination/018.php | 4 +++- user_guide_src/source/libraries/security/001.php | 2 +- user_guide_src/source/libraries/sessions/001.php | 2 +- user_guide_src/source/libraries/throttler/001.php | 2 +- user_guide_src/source/libraries/throttler/002.php | 5 ++--- user_guide_src/source/libraries/typography/001.php | 2 +- user_guide_src/source/libraries/validation/004.php | 2 +- user_guide_src/source/libraries/validation/008.php | 4 ++-- user_guide_src/source/libraries/validation/044.php | 2 +- user_guide_src/source/libraries/validation/046.php | 6 +++--- user_guide_src/source/outgoing/view_parser/001.php | 2 +- user_guide_src/source/outgoing/view_renderer/001.php | 2 +- user_guide_src/source/testing/benchmark/001.php | 2 +- 62 files changed, 99 insertions(+), 87 deletions(-) diff --git a/user_guide_src/source/concepts/services.rst b/user_guide_src/source/concepts/services.rst index a3dc9fabb74d..24ee8ec5be65 100644 --- a/user_guide_src/source/concepts/services.rst +++ b/user_guide_src/source/concepts/services.rst @@ -37,7 +37,7 @@ come in handy. Instead of creating the instance ourself, we let a central class create an instance of the class for us. This class is kept very simple. It only contains a method for each class that we want to use as a service. The method typically returns a **shared instance** of that class, passing any dependencies -it might have into it. Then, we would replace our timer creation code with code that calls this new class: +it might have into it. Then, we would replace our timer creation code with code that calls this global function or Service class: .. literalinclude:: services/002.php @@ -55,7 +55,7 @@ As many CodeIgniter classes are provided as services, you can get them like the .. literalinclude:: services/013.php -The ``$typography`` is an instance of the Typography class, and if you call ``\Config\Services::typography()`` again, you will get the exactly same instance. +The ``$timer`` is an instance of the Timer class, and if you call ``service('timer')`` again, you will get the exactly same instance. The Services typically return a **shared instance** of the class. The following code creates a ``CURLRequest`` instance at the first call. And the second call returns the exactly same instance. @@ -66,7 +66,7 @@ Therefore, the parameter ``$options2`` for the ``$client2`` does not work. It is Getting a New Instance ====================== -If you want to get a new instance of the Typography class, you need to pass ``false`` to the argument ``$getShared``: +If you want to get a new instance of the Timer class, you need to pass ``false`` to the argument ``$getShared``: .. literalinclude:: services/014.php @@ -85,6 +85,8 @@ always return the same instance: .. literalinclude:: services/003.php +.. note:: Since `v4.5.0`, the global function ``service()`` is recommended due to performance improvements on without parameter + If the creation method requires additional parameters, they can be passed after the service name: .. literalinclude:: services/004.php diff --git a/user_guide_src/source/concepts/services/002.php b/user_guide_src/source/concepts/services/002.php index cb292ecaeb42..cedf5d19ed65 100644 --- a/user_guide_src/source/concepts/services/002.php +++ b/user_guide_src/source/concepts/services/002.php @@ -1,3 +1,6 @@ 'http://example.com/api/v1/', 'timeout' => 3, ]; -$client1 = \Config\Services::curlrequest($options1); +$client1 = service('curlrequest', $options1); $options2 = [ 'baseURI' => 'http://another.example.com/api/v2/', 'timeout' => 10, ]; -$client2 = \Config\Services::curlrequest($options2); +$client2 = service('curlrequest', $options2); // $options2 does not work. // $client2 is the exactly same instance as $client1. diff --git a/user_guide_src/source/extending/basecontroller/003.php b/user_guide_src/source/extending/basecontroller/003.php index 2f6fcb9d08cb..b7bcab22545d 100644 --- a/user_guide_src/source/extending/basecontroller/003.php +++ b/user_guide_src/source/extending/basecontroller/003.php @@ -18,6 +18,6 @@ public function initController(/* ... */) // Do Not Edit This Line parent::initController($request, $response, $logger); - $this->session = \Config\Services::session(); + $this->session = service('session'); } } diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 61b92a99df92..d0a23758e348 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -372,7 +372,7 @@ Miscellaneous Functions :returns: The shared Request object. :rtype: IncomingRequest|CLIRequest - This function is a wrapper for ``Services::request()``. + This function is a wrapper for ``Services::request()`` and ``service('request')``. .. php:function:: response() @@ -381,7 +381,7 @@ Miscellaneous Functions :returns: The shared Response object. :rtype: Response - This function is a wrapper for ``Services::response()``. + This function is a wrapper for ``Services::response()`` and ``service('response')``. .. php:function:: route_to($method[, ...$params]) diff --git a/user_guide_src/source/general/errors/018.php b/user_guide_src/source/general/errors/018.php index 3cba09951d8b..9546e4a606ae 100644 --- a/user_guide_src/source/general/errors/018.php +++ b/user_guide_src/source/general/errors/018.php @@ -1,6 +1,6 @@ redirect('https://example.com/path') ->setHeader('Some', 'header') ->setCookie('and', 'cookie'); diff --git a/user_guide_src/source/incoming/content_negotiation/001.php b/user_guide_src/source/incoming/content_negotiation/001.php index 3c55e788eff9..fbd07a975ee3 100644 --- a/user_guide_src/source/incoming/content_negotiation/001.php +++ b/user_guide_src/source/incoming/content_negotiation/001.php @@ -1,3 +1,3 @@ get('foo'); diff --git a/user_guide_src/source/libraries/cookies/002.php b/user_guide_src/source/libraries/cookies/002.php index 8c2fb03fea9d..ecbe37ed088b 100644 --- a/user_guide_src/source/libraries/cookies/002.php +++ b/user_guide_src/source/libraries/cookies/002.php @@ -4,7 +4,7 @@ use Config\Cookie as CookieConfig; // pass in a Config\Cookie instance before constructing a Cookie class -Cookie::setDefaults(new CookieConfig()); +Cookie::setDefaults(config(CookieConfig::class)); $cookie = new Cookie('login_token'); // pass in an array of defaults diff --git a/user_guide_src/source/libraries/cookies/003.php b/user_guide_src/source/libraries/cookies/003.php index f878ff8592d1..6e9094fe7b77 100644 --- a/user_guide_src/source/libraries/cookies/003.php +++ b/user_guide_src/source/libraries/cookies/003.php @@ -3,7 +3,7 @@ use CodeIgniter\Cookie\Cookie; use Config\Cookie as CookieConfig; -$oldDefaults = Cookie::setDefaults(new CookieConfig()); +$oldDefaults = Cookie::setDefaults(config(CookieConfig::class)); $cookie = new Cookie('my_token', 'muffins'); // return the old defaults diff --git a/user_guide_src/source/libraries/cookies/007.php b/user_guide_src/source/libraries/cookies/007.php index ff79582a5d07..ea4dcc97876f 100644 --- a/user_guide_src/source/libraries/cookies/007.php +++ b/user_guide_src/source/libraries/cookies/007.php @@ -1,5 +1,3 @@ getCookieStore(); +$cookieStore = service('response')->getCookieStore(); diff --git a/user_guide_src/source/libraries/cookies/009.php b/user_guide_src/source/libraries/cookies/009.php index 6db5a50bfc1e..3e73bb0cafaf 100644 --- a/user_guide_src/source/libraries/cookies/009.php +++ b/user_guide_src/source/libraries/cookies/009.php @@ -2,7 +2,6 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Cookie\CookieStore; -use Config\Services; // check if cookie is in the current cookie collection $store = new CookieStore([ @@ -13,7 +12,7 @@ // check if cookie is in the current Response's cookie collection cookies()->has('login_token'); -Services::response()->hasCookie('remember_token'); +service('response')->hasCookie('remember_token'); // using the cookie helper to check the current Response // not available to v4.1.1 and lower diff --git a/user_guide_src/source/libraries/cookies/010.php b/user_guide_src/source/libraries/cookies/010.php index 8211a4a2b23e..b2a18323cdac 100644 --- a/user_guide_src/source/libraries/cookies/010.php +++ b/user_guide_src/source/libraries/cookies/010.php @@ -13,7 +13,7 @@ // getting cookie in the current Response's cookie collection cookies()->get('login_token'); -Services::response()->getCookie('remember_token'); +service('response')->getCookie('remember_token'); // using the cookie helper to get cookie from the Response's cookie collection helper('cookie'); diff --git a/user_guide_src/source/libraries/cookies/013.php b/user_guide_src/source/libraries/cookies/013.php index 6dcb79807380..80052c7c9218 100644 --- a/user_guide_src/source/libraries/cookies/013.php +++ b/user_guide_src/source/libraries/cookies/013.php @@ -1,11 +1,9 @@ get(); // array of Cookie objects // alternatively, you can use the display method cookies()->display(); // or even from the Response -Services::response()->getCookies(); +service('response')->getCookies(); diff --git a/user_guide_src/source/libraries/cookies/014.php b/user_guide_src/source/libraries/cookies/014.php index 0e6ae6772146..9be64c5cf651 100644 --- a/user_guide_src/source/libraries/cookies/014.php +++ b/user_guide_src/source/libraries/cookies/014.php @@ -2,7 +2,6 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Cookie\CookieStore; -use Config\Services; $store = new CookieStore([ new Cookie('login_token'), diff --git a/user_guide_src/source/libraries/cookies/015.php b/user_guide_src/source/libraries/cookies/015.php index 040a2f8a9882..696e9c7c73d3 100644 --- a/user_guide_src/source/libraries/cookies/015.php +++ b/user_guide_src/source/libraries/cookies/015.php @@ -1,9 +1,7 @@ setCookie('admin_token', 'yes'); -Services::response()->deleteCookie('login_token'); +service('response')->setCookie('admin_token', 'yes'); +service('response')->deleteCookie('login_token'); // using the cookie helper helper('cookie'); diff --git a/user_guide_src/source/libraries/cookies/017.php b/user_guide_src/source/libraries/cookies/017.php index eadbc8083e98..4cc1fe4a67a6 100644 --- a/user_guide_src/source/libraries/cookies/017.php +++ b/user_guide_src/source/libraries/cookies/017.php @@ -1,9 +1,8 @@ `. -To load with the Services class call the ``curlrequest()`` method: +To load with the Services class call the ``curlrequest()`` method or global function ``service()``: .. literalinclude:: curlrequest/002.php diff --git a/user_guide_src/source/libraries/curlrequest/002.php b/user_guide_src/source/libraries/curlrequest/002.php index 5d84bfe442b5..ae7264ffdcdb 100644 --- a/user_guide_src/source/libraries/curlrequest/002.php +++ b/user_guide_src/source/libraries/curlrequest/002.php @@ -1,3 +1,6 @@ 'http://example.com/api/v1/', 'timeout' => 3, ]; -$client = \Config\Services::curlrequest($options); +$client = service('curlrequest', $options); diff --git a/user_guide_src/source/libraries/curlrequest/004.php b/user_guide_src/source/libraries/curlrequest/004.php index 4d6a14fadbb0..654d72d2687f 100644 --- a/user_guide_src/source/libraries/curlrequest/004.php +++ b/user_guide_src/source/libraries/curlrequest/004.php @@ -1,8 +1,10 @@ request('GET', 'https://api.github.com/user', [ 'auth' => ['user', 'pass'], diff --git a/user_guide_src/source/libraries/curlrequest/008.php b/user_guide_src/source/libraries/curlrequest/008.php index 611909c2df7d..2f14c6974cd0 100644 --- a/user_guide_src/source/libraries/curlrequest/008.php +++ b/user_guide_src/source/libraries/curlrequest/008.php @@ -1,6 +1,6 @@ 'https://example.com/api/v1/', ]); diff --git a/user_guide_src/source/libraries/email/001.php b/user_guide_src/source/libraries/email/001.php index 914193c15203..f7873714bab5 100644 --- a/user_guide_src/source/libraries/email/001.php +++ b/user_guide_src/source/libraries/email/001.php @@ -1,6 +1,6 @@ setFrom('your@example.com', 'Your Name'); $email->setTo('someone@example.com'); diff --git a/user_guide_src/source/libraries/encryption/001.php b/user_guide_src/source/libraries/encryption/001.php index 8f840be59245..1481d20c2758 100644 --- a/user_guide_src/source/libraries/encryption/001.php +++ b/user_guide_src/source/libraries/encryption/001.php @@ -1,3 +1,3 @@ key = 'aBigsecret_ofAtleast32Characters'; $config->driver = 'OpenSSL'; -$encrypter = \Config\Services::encrypter($config); +$encrypter = service('encrypter', $config); diff --git a/user_guide_src/source/libraries/encryption/013.php b/user_guide_src/source/libraries/encryption/013.php index c49d282f42da..06eb6b0de807 100644 --- a/user_guide_src/source/libraries/encryption/013.php +++ b/user_guide_src/source/libraries/encryption/013.php @@ -1,9 +1,8 @@ driver = 'OpenSSL'; // Your CI3's 'encryption_key' @@ -15,4 +14,4 @@ $config->encryptKeyInfo = 'encryption'; $config->authKeyInfo = 'authentication'; -$encrypter = Services::encrypter($config, false); +$encrypter = service('encrypter', $config); diff --git a/user_guide_src/source/libraries/images.rst b/user_guide_src/source/libraries/images.rst index 08efccfe92f9..cfb7dce8f628 100644 --- a/user_guide_src/source/libraries/images.rst +++ b/user_guide_src/source/libraries/images.rst @@ -22,12 +22,12 @@ Initializing the Class ********************** Like most other classes in CodeIgniter, the image class is initialized -in your controller by calling the Services class: +in your controller by calling the global function service: .. literalinclude:: images/001.php -You can pass the alias for the image library you wish to use into the -Service function: +You can pass the alias for the image library you wish to use into the global +function service: .. literalinclude:: images/002.php diff --git a/user_guide_src/source/libraries/images/001.php b/user_guide_src/source/libraries/images/001.php index 780bb37b3a4d..3001f4561029 100644 --- a/user_guide_src/source/libraries/images/001.php +++ b/user_guide_src/source/libraries/images/001.php @@ -1,3 +1,3 @@ withFile('/path/to/image/mypic.jpg') diff --git a/user_guide_src/source/libraries/images/008.php b/user_guide_src/source/libraries/images/008.php index 01406733d31b..a7963d420573 100644 --- a/user_guide_src/source/libraries/images/008.php +++ b/user_guide_src/source/libraries/images/008.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->getFile() ->getProperties(true); @@ -8,7 +8,7 @@ $xOffset = ($info['width'] / 2) - 25; $yOffset = ($info['height'] / 2) - 25; -\Config\Services::image('imagick') +service('image', 'imagick') ->withFile('/path/to/image/mypic.jpg') ->crop(50, 50, $xOffset, $yOffset) ->save('/path/to/new/image.jpg'); diff --git a/user_guide_src/source/libraries/images/009.php b/user_guide_src/source/libraries/images/009.php index 6314181ef435..e24cfcc40a4a 100644 --- a/user_guide_src/source/libraries/images/009.php +++ b/user_guide_src/source/libraries/images/009.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->convert(IMAGETYPE_PNG) ->save('/path/to/new/image.png'); diff --git a/user_guide_src/source/libraries/images/010.php b/user_guide_src/source/libraries/images/010.php index b70b179815cd..696eab880516 100644 --- a/user_guide_src/source/libraries/images/010.php +++ b/user_guide_src/source/libraries/images/010.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->fit(100, 150, 'left') ->save('/path/to/new/image.jpg'); diff --git a/user_guide_src/source/libraries/images/011.php b/user_guide_src/source/libraries/images/011.php index f18fb55545a1..e816af48c647 100644 --- a/user_guide_src/source/libraries/images/011.php +++ b/user_guide_src/source/libraries/images/011.php @@ -1,11 +1,11 @@ withFile('/path/to/image/mypic.png') ->flatten() ->save('/path/to/new/image.jpg'); -\Config\Services::image('imagick') +service('image', 'imagick') ->withFile('/path/to/image/mypic.png') ->flatten(25, 25, 112) ->save('/path/to/new/image.jpg'); diff --git a/user_guide_src/source/libraries/images/012.php b/user_guide_src/source/libraries/images/012.php index 581a984238bd..eb99b11ae3b1 100644 --- a/user_guide_src/source/libraries/images/012.php +++ b/user_guide_src/source/libraries/images/012.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->flip('horizontal') ->save('/path/to/new/image.jpg'); diff --git a/user_guide_src/source/libraries/images/013.php b/user_guide_src/source/libraries/images/013.php index c51a7126be8d..7c1780565a5d 100644 --- a/user_guide_src/source/libraries/images/013.php +++ b/user_guide_src/source/libraries/images/013.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->resize(200, 100, true, 'height') ->save('/path/to/new/image.jpg'); diff --git a/user_guide_src/source/libraries/images/014.php b/user_guide_src/source/libraries/images/014.php index 32943ed142c6..cfe551a4c411 100644 --- a/user_guide_src/source/libraries/images/014.php +++ b/user_guide_src/source/libraries/images/014.php @@ -1,6 +1,6 @@ withFile('/path/to/image/mypic.jpg') ->text('Copyright 2017 My Photo Co', [ 'color' => '#fff', diff --git a/user_guide_src/source/libraries/pagination/001.php b/user_guide_src/source/libraries/pagination/001.php index ec86f0e73490..4b67fd5511de 100644 --- a/user_guide_src/source/libraries/pagination/001.php +++ b/user_guide_src/source/libraries/pagination/001.php @@ -1,3 +1,3 @@ $model->paginate(10), diff --git a/user_guide_src/source/libraries/pagination/003.php b/user_guide_src/source/libraries/pagination/003.php index 6ea631c7a9bc..262385ea0eb8 100644 --- a/user_guide_src/source/libraries/pagination/003.php +++ b/user_guide_src/source/libraries/pagination/003.php @@ -1,7 +1,9 @@ $model->where('ban', 1)->paginate(10), diff --git a/user_guide_src/source/libraries/pagination/004.php b/user_guide_src/source/libraries/pagination/004.php index a8ef4d296125..b7af3ec83d2a 100644 --- a/user_guide_src/source/libraries/pagination/004.php +++ b/user_guide_src/source/libraries/pagination/004.php @@ -2,12 +2,15 @@ namespace App\Controllers; +use App\Models\PageModel; +use App\Models\UserModel; + class UserController extends BaseController { public function index() { - $userModel = new \App\Models\UserModel(); - $pageModel = new \App\Models\PageModel(); + $userModel = model(UserModel::class); + $pageModel = model(PageModel::class); $data = [ 'users' => $userModel->paginate(10, 'group1'), diff --git a/user_guide_src/source/libraries/pagination/005.php b/user_guide_src/source/libraries/pagination/005.php index dec2c3161e76..2dc3405b8a62 100644 --- a/user_guide_src/source/libraries/pagination/005.php +++ b/user_guide_src/source/libraries/pagination/005.php @@ -1,6 +1,8 @@ paginate(10, 'group1', $page); diff --git a/user_guide_src/source/libraries/pagination/018.php b/user_guide_src/source/libraries/pagination/018.php index 002d034a643c..afabd1c8c998 100644 --- a/user_guide_src/source/libraries/pagination/018.php +++ b/user_guide_src/source/libraries/pagination/018.php @@ -1,7 +1,9 @@ $model->banned()->paginate(10), diff --git a/user_guide_src/source/libraries/security/001.php b/user_guide_src/source/libraries/security/001.php index fe504ef35a8e..f81de1a9432c 100644 --- a/user_guide_src/source/libraries/security/001.php +++ b/user_guide_src/source/libraries/security/001.php @@ -1,3 +1,3 @@ check($name, 60, MINUTE); diff --git a/user_guide_src/source/libraries/throttler/002.php b/user_guide_src/source/libraries/throttler/002.php index 440ad582245b..9e3fec98c963 100644 --- a/user_guide_src/source/libraries/throttler/002.php +++ b/user_guide_src/source/libraries/throttler/002.php @@ -5,7 +5,6 @@ use CodeIgniter\Filters\FilterInterface; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; -use Config\Services; class Throttle implements FilterInterface { @@ -19,12 +18,12 @@ class Throttle implements FilterInterface */ public function before(RequestInterface $request, $arguments = null) { - $throttler = Services::throttler(); + $throttler = service('throttler'); // Restrict an IP address to no more than 1 request // per second across the entire site. if ($throttler->check(md5($request->getIPAddress()), 60, MINUTE) === false) { - return Services::response()->setStatusCode(429); + return service('response')->setStatusCode(429); } } diff --git a/user_guide_src/source/libraries/typography/001.php b/user_guide_src/source/libraries/typography/001.php index 0c82ed0e95fa..9685611c7691 100644 --- a/user_guide_src/source/libraries/typography/001.php +++ b/user_guide_src/source/libraries/typography/001.php @@ -1,3 +1,3 @@ withRequest($request)->run()) { // If you use the input data, you should get it from the getValidated() method. diff --git a/user_guide_src/source/libraries/validation/044.php b/user_guide_src/source/libraries/validation/044.php index 7f3a0e0e0902..df2598d1906c 100644 --- a/user_guide_src/source/libraries/validation/044.php +++ b/user_guide_src/source/libraries/validation/044.php @@ -1,6 +1,6 @@ setRules([ 'username' => 'required', 'password' => 'required|min_length[10]', diff --git a/user_guide_src/source/libraries/validation/046.php b/user_guide_src/source/libraries/validation/046.php index f37def009eba..34dea12ceeef 100644 --- a/user_guide_src/source/libraries/validation/046.php +++ b/user_guide_src/source/libraries/validation/046.php @@ -2,8 +2,6 @@ namespace App\Controllers; -use Config\Services; - class Form extends BaseController { // Define a custom validation rule. @@ -16,7 +14,9 @@ public function process() { // ... - $validation = Services::validation(); + $data = []; + + $validation = service('validation'); $validation->setRules( [ 'foo' => [ diff --git a/user_guide_src/source/outgoing/view_parser/001.php b/user_guide_src/source/outgoing/view_parser/001.php index 56f7f51e4a07..e9f733df13e4 100644 --- a/user_guide_src/source/outgoing/view_parser/001.php +++ b/user_guide_src/source/outgoing/view_parser/001.php @@ -1,3 +1,3 @@ start('render view'); From a1690e8656e9fabfa171e32946d06e64ae1290b5 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 31 May 2024 14:58:16 +0700 Subject: [PATCH 2/8] docs: typo Services --- user_guide_src/source/concepts/services.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/concepts/services.rst b/user_guide_src/source/concepts/services.rst index 24ee8ec5be65..39620f44bca6 100644 --- a/user_guide_src/source/concepts/services.rst +++ b/user_guide_src/source/concepts/services.rst @@ -37,7 +37,7 @@ come in handy. Instead of creating the instance ourself, we let a central class create an instance of the class for us. This class is kept very simple. It only contains a method for each class that we want to use as a service. The method typically returns a **shared instance** of that class, passing any dependencies -it might have into it. Then, we would replace our timer creation code with code that calls this global function or Service class: +it might have into it. Then, we would replace our timer creation code with code that calls this global function or Services class: .. literalinclude:: services/002.php From 6be5e3cbdba02661c87f312363f96f38f7a39a18 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 31 May 2024 15:54:06 +0700 Subject: [PATCH 3/8] Update user_guide_src/source/libraries/images.rst Co-authored-by: kenjis --- user_guide_src/source/libraries/images.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/images.rst b/user_guide_src/source/libraries/images.rst index cfb7dce8f628..232174765c91 100644 --- a/user_guide_src/source/libraries/images.rst +++ b/user_guide_src/source/libraries/images.rst @@ -27,7 +27,7 @@ in your controller by calling the global function service: .. literalinclude:: images/001.php You can pass the alias for the image library you wish to use into the global -function service: +function ``service()``: .. literalinclude:: images/002.php From c3323b441838cc0a5327806fc2842a070599b03f Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 31 May 2024 15:54:24 +0700 Subject: [PATCH 4/8] Update user_guide_src/source/libraries/images.rst Co-authored-by: kenjis --- user_guide_src/source/libraries/images.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/images.rst b/user_guide_src/source/libraries/images.rst index 232174765c91..a439c3321a0b 100644 --- a/user_guide_src/source/libraries/images.rst +++ b/user_guide_src/source/libraries/images.rst @@ -22,7 +22,7 @@ Initializing the Class ********************** Like most other classes in CodeIgniter, the image class is initialized -in your controller by calling the global function service: +in your controller by calling the global function ``service()``: .. literalinclude:: images/001.php From ef9c3e5a56d54dec355a7ced58bd19551d32f25d Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 31 May 2024 15:54:36 +0700 Subject: [PATCH 5/8] Update user_guide_src/source/libraries/caching.rst Co-authored-by: kenjis --- user_guide_src/source/libraries/caching.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index 5e1fa7368811..f4adc04a93df 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -19,7 +19,7 @@ The following example shows a common usage pattern within your controllers. .. literalinclude:: caching/001.php -You can grab an instance of the cache engine directly through the global function service: +You can grab an instance of the cache engine directly through the global function ``service()``: .. literalinclude:: caching/002.php From 107c99baede6e640586a1283d81cce3e641b4c27 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 31 May 2024 15:54:44 +0700 Subject: [PATCH 6/8] Update user_guide_src/source/concepts/services.rst Co-authored-by: kenjis --- user_guide_src/source/concepts/services.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/concepts/services.rst b/user_guide_src/source/concepts/services.rst index 39620f44bca6..92eec136e1c8 100644 --- a/user_guide_src/source/concepts/services.rst +++ b/user_guide_src/source/concepts/services.rst @@ -85,7 +85,7 @@ always return the same instance: .. literalinclude:: services/003.php -.. note:: Since `v4.5.0`, the global function ``service()`` is recommended due to performance improvements on without parameter +.. note:: Since v4.5.0, when you don't pass parameters to the service, the global function ``service()`` is recommended due to performance improvements. If the creation method requires additional parameters, they can be passed after the service name: From 2b0bbf55c60578b92b883b18729f563695838bd4 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 31 May 2024 15:56:11 +0700 Subject: [PATCH 7/8] docs: no use config() --- user_guide_src/source/libraries/encryption/013.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/encryption/013.php b/user_guide_src/source/libraries/encryption/013.php index 06eb6b0de807..f7ef52060b6b 100644 --- a/user_guide_src/source/libraries/encryption/013.php +++ b/user_guide_src/source/libraries/encryption/013.php @@ -2,7 +2,7 @@ use Config\Encryption; -$config = config(Encryption::class); +$config = new Encryption(); $config->driver = 'OpenSSL'; // Your CI3's 'encryption_key' From 1c27fd410916eaf84e35dfb236be1a8ac0718976 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sun, 2 Jun 2024 21:39:38 +0700 Subject: [PATCH 8/8] docs: remove variable --- user_guide_src/source/libraries/validation/046.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/user_guide_src/source/libraries/validation/046.php b/user_guide_src/source/libraries/validation/046.php index 34dea12ceeef..d9c244cdf31e 100644 --- a/user_guide_src/source/libraries/validation/046.php +++ b/user_guide_src/source/libraries/validation/046.php @@ -14,8 +14,6 @@ public function process() { // ... - $data = []; - $validation = service('validation'); $validation->setRules( [