Skip to content

Commit 8c459cf

Browse files
authored
Merge pull request #8928 from ddevsr/docs-service
docs: replace `Services` class to `service()`
2 parents 4dd9a87 + 1c27fd4 commit 8c459cf

File tree

62 files changed

+96
-86
lines changed

Some content is hidden

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

62 files changed

+96
-86
lines changed

user_guide_src/source/concepts/services.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ come in handy.
3737
Instead of creating the instance ourself, we let a central class create an instance of the
3838
class for us. This class is kept very simple. It only contains a method for each class that we want
3939
to use as a service. The method typically returns a **shared instance** of that class, passing any dependencies
40-
it might have into it. Then, we would replace our timer creation code with code that calls this new class:
40+
it might have into it. Then, we would replace our timer creation code with code that calls this global function or Services class:
4141

4242
.. literalinclude:: services/002.php
4343

@@ -55,7 +55,7 @@ As many CodeIgniter classes are provided as services, you can get them like the
5555

5656
.. literalinclude:: services/013.php
5757

58-
The ``$typography`` is an instance of the Typography class, and if you call ``\Config\Services::typography()`` again, you will get the exactly same instance.
58+
The ``$timer`` is an instance of the Timer class, and if you call ``service('timer')`` again, you will get the exactly same instance.
5959

6060
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.
6161

@@ -66,7 +66,7 @@ Therefore, the parameter ``$options2`` for the ``$client2`` does not work. It is
6666
Getting a New Instance
6767
======================
6868

69-
If you want to get a new instance of the Typography class, you need to pass ``false`` to the argument ``$getShared``:
69+
If you want to get a new instance of the Timer class, you need to pass ``false`` to the argument ``$getShared``:
7070

7171
.. literalinclude:: services/014.php
7272

@@ -85,6 +85,8 @@ always return the same instance:
8585

8686
.. literalinclude:: services/003.php
8787

88+
.. note:: Since v4.5.0, when you don't pass parameters to the service, the global function ``service()`` is recommended due to performance improvements.
89+
8890
If the creation method requires additional parameters, they can be passed after the service name:
8991

9092
.. literalinclude:: services/004.php
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
22

3+
$timer = service('timer');
4+
5+
// The code above is the same as the code below.
36
$timer = \Config\Services::timer();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$postManager = \Config\Services::postManager();
3+
$postManager = service('postManager');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$typography = \Config\Services::typography();
3+
$timer = service('timer');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$typography = \Config\Services::typography(false);
3+
$timer = \Config\Services::timer(false);

user_guide_src/source/concepts/services/015.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
'baseURI' => 'http://example.com/api/v1/',
55
'timeout' => 3,
66
];
7-
$client1 = \Config\Services::curlrequest($options1);
7+
$client1 = service('curlrequest', $options1);
88

99
$options2 = [
1010
'baseURI' => 'http://another.example.com/api/v2/',
1111
'timeout' => 10,
1212
];
13-
$client2 = \Config\Services::curlrequest($options2);
13+
$client2 = service('curlrequest', $options2);
1414
// $options2 does not work.
1515
// $client2 is the exactly same instance as $client1.

user_guide_src/source/extending/basecontroller/003.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function initController(/* ... */)
1818
// Do Not Edit This Line
1919
parent::initController($request, $response, $logger);
2020

21-
$this->session = \Config\Services::session();
21+
$this->session = service('session');
2222
}
2323
}

user_guide_src/source/general/common_functions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Miscellaneous Functions
372372
:returns: The shared Request object.
373373
:rtype: IncomingRequest|CLIRequest
374374

375-
This function is a wrapper for ``Services::request()``.
375+
This function is a wrapper for ``Services::request()`` and ``service('request')``.
376376

377377
.. php:function:: response()
378378
@@ -381,7 +381,7 @@ Miscellaneous Functions
381381
:returns: The shared Response object.
382382
:rtype: Response
383383

384-
This function is a wrapper for ``Services::response()``.
384+
This function is a wrapper for ``Services::response()`` and ``service('response')``.
385385

386386
.. php:function:: route_to($method[, ...$params])
387387

user_guide_src/source/general/errors/018.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$response = \Config\Services::response()
3+
$response = service('response')
44
->redirect('https://example.com/path')
55
->setHeader('Some', 'header')
66
->setCookie('and', 'cookie');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$negotiate = \Config\Services::negotiator();
3+
$negotiate = service('negotiator');

0 commit comments

Comments
 (0)