Skip to content

Commit e6a23c0

Browse files
committed
chore: import FQCNs in PHP samples of the user guide
1 parent ec86761 commit e6a23c0

46 files changed

Lines changed: 382 additions & 164 deletions

Some content is hidden

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

‎.php-cs-fixer.user-guide.php‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
$config = require __DIR__ . '/.php-cs-fixer.dist.php';
1818

1919
$overrides = [
20-
'echo_tag_syntax' => false,
21-
'header_comment' => false,
22-
'php_unit_internal_class' => false,
23-
'no_unused_imports' => false,
24-
'class_attributes_separation' => false,
25-
'fully_qualified_strict_types' => [
26-
'import_symbols' => false,
27-
'leading_backslash_in_global_namespace' => true,
28-
],
20+
'echo_tag_syntax' => false,
21+
'header_comment' => false,
22+
'php_unit_internal_class' => false,
23+
'no_unused_imports' => false,
24+
'class_attributes_separation' => false,
2925
];
3026

3127
return $config

‎docs/cli/cli_commands.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace App\Commands;
8282

8383
use CodeIgniter\CLI\BaseCommand;
8484
use CodeIgniter\CLI\CLI;
85+
use CodeIgniter\CodeIgniter;
8586

8687
class AppInfo extends BaseCommand
8788
{
@@ -90,7 +91,7 @@ class AppInfo extends BaseCommand
9091
public function run(array $params)
9192
{
9293
CLI::write('PHP Version: ' . CLI::color(PHP_VERSION, 'yellow'));
93-
CLI::write('CI Version: ' . CLI::color(\CodeIgniter\CodeIgniter::CI_VERSION, 'yellow'));
94+
CLI::write('CI Version: ' . CLI::color(CodeIgniter::CI_VERSION, 'yellow'));
9495
CLI::write('APPPATH: ' . CLI::color(APPPATH, 'yellow'));
9596
CLI::write('SYSTEMPATH: ' . CLI::color(SYSTEMPATH, 'yellow'));
9697
CLI::write('ROOTPATH: ' . CLI::color(ROOTPATH, 'yellow'));
@@ -146,7 +147,7 @@ A convenience method to maintain a consistent and clear error output to the CLI:
146147

147148
try {
148149
// ...
149-
} catch (\Exception $e) {
150+
} catch (Exception $e) {
150151
$this->showError($e);
151152
}
152153
```

‎docs/cli/cli_signals.md‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ Some operations should never be interrupted (database transactions, file operati
201201
```php
202202
<?php
203203

204+
namespace App\Commands;
205+
206+
use CodeIgniter\CLI\BaseCommand;
204207
use CodeIgniter\CLI\CLI;
208+
use Exception;
205209

206-
class SampleCommand extends \BaseCommand
210+
class SampleCommand extends BaseCommand
207211
{
208212
// ...
209213
private function processOrder(array $orderData): void
@@ -231,7 +235,7 @@ class SampleCommand extends \BaseCommand
231235
CLI::write('Transaction completed successfully', 'green');
232236

233237
return $orderId;
234-
} catch (\Exception $e) {
238+
} catch (Exception $e) {
235239
// Rollback on error
236240
$this->db->transRollback();
237241

@@ -342,11 +346,11 @@ kill -CONT $PID # Resume - may lose terminal control
342346

343347
When you manually send `kill -CONT` from a different terminal:
344348

345-
**Expected behavior:**
349+
**Expected behavior:**
346350

347351
- Process resumes and custom handlers execute
348352

349-
**Side effects:**
353+
**Side effects:**
350354

351355
- Process loses foreground terminal control
352356
- Ctrl+C and Ctrl+Z may stop working
@@ -463,7 +467,7 @@ This returns comprehensive information including:
463467

464468
#### registerSignals($signals = [SIGTERM, SIGINT, SIGHUP, SIGQUIT], $methodMap = [])
465469

466-
- **Parameters**
470+
- **Parameters**
467471
- **$signals** `array` List of signals to handle
468472
- **$methodMap** `array` Optional signal-to-method mapping
469473

@@ -576,7 +580,7 @@ Reset all states - useful for testing or restart scenarios.
576580

577581
#### withSignalsBlocked($operation)
578582

579-
- **Parameters**
583+
- **Parameters**
580584
- **$operation** `callable` The critical operation to execute without interruption
581585

582586
- **Returns**: The result of the operation
@@ -597,7 +601,7 @@ Check if signals are currently blocked.
597601

598602
#### mapSignal($signal, $method)
599603

600-
- **Parameters**
604+
- **Parameters**
601605
- **$signal** `int` Signal constant
602606
- **$method** `string` Method name to call for this signal
603607

@@ -642,7 +646,7 @@ class SampleCommand extends BaseCommand
642646

643647
#### getSignalName($signal)
644648

645-
- **Parameters**
649+
- **Parameters**
646650
- **$signal** `int` Signal constant
647651

648652
- **Returns**: Human-readable signal name

‎docs/concepts/factories.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ The first is `config()`, which returns an instance of a Config class. The only r
113113
```php
114114
<?php
115115

116+
use CodeIgniter\Config\Factories;
117+
116118
$appConfig = config('App');
117119

118120
// The code above is the same as the code below.
119-
$appConfig = \CodeIgniter\Config\Factories::config('App');
121+
$appConfig = Factories::config('App');
120122
```
121123

122124
### model()
@@ -126,10 +128,12 @@ The second function, `model()`, returns an instance of a Model class. The only r
126128
```php
127129
<?php
128130

131+
use CodeIgniter\Config\Factories;
132+
129133
$user = model('UserModel');
130134

131135
// The code above is the same as the code below.
132-
$user = \CodeIgniter\Config\Factories::models('UserModel');
136+
$user = Factories::models('UserModel');
133137
```
134138

135139
## Defining Classname to be Loaded

‎docs/concepts/services.md‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ A quick example will probably make things clearer, so imagine that you need to p
1515
```php
1616
<?php
1717

18-
$timer = new \CodeIgniter\Debug\Timer();
18+
use CodeIgniter\Debug\Timer;
19+
20+
$timer = new Timer();
1921
```
2022

2123
And this works great, until you decide that you want to use a different timer class in its place. Maybe this one has some advanced reporting that the default timer does not provide. In order to do this, you now have to locate all of the places in your application where you have used the timer class. Since you might have left them in place to keep a performance log of your application constantly running, this might be a time-consuming and error-prone way to handle this. That's where services come in handy.
@@ -25,10 +27,12 @@ Instead of creating the instance ourselves, we let a central class create an ins
2527
```php
2628
<?php
2729

30+
use Config\Services;
31+
2832
$timer = service('timer');
2933

3034
// The code above is the same as the code below.
31-
$timer = \Config\Services::timer();
35+
$timer = Services::timer();
3236
```
3337

3438
When you need to change the implementation used, you can modify the services configuration file, and the change happens automatically throughout your application without you having to do anything. Now you just need to take advantage of any new functionality and you're good to go. Very simple and error-resistant.
@@ -77,7 +81,9 @@ If you want to get a new instance of the Timer class, you need to pass `false` t
7781
```php
7882
<?php
7983

80-
$timer = \Config\Services::timer(false);
84+
use Config\Services;
85+
86+
$timer = Services::timer(false);
8187
```
8288

8389
### Convenience Functions
@@ -91,10 +97,12 @@ The first is `service()`, which provides access to the requested service. The on
9197
```php
9298
<?php
9399

100+
use Config\Services;
101+
94102
$logger = service('logger');
95103

96104
// The code above is the same as the code below.
97-
$logger = \Config\Services::logger();
105+
$logger = Services::logger();
98106
```
99107

100108
!!! note "Note"
@@ -107,10 +115,12 @@ If the creation method requires additional parameters, they can be passed after
107115
```php
108116
<?php
109117

118+
use Config\Services;
119+
110120
$renderer = service('renderer', APPPATH . 'views/');
111121

112122
// The code above is the same as the code below.
113-
$renderer = \Config\Services::renderer(APPPATH . 'views/');
123+
$renderer = Services::renderer(APPPATH . 'views/');
114124
```
115125

116126
#### single_service()
@@ -120,10 +130,12 @@ The second function, `single_service()`, works just like `service()` but returns
120130
```php
121131
<?php
122132

133+
use Config\Services;
134+
123135
$logger = single_service('logger');
124136

125137
// The code above is the same as the code below.
126-
$logger = \Config\Services::logger(false);
138+
$logger = Services::logger(false);
127139
```
128140

129141
## Defining Services
@@ -152,6 +164,7 @@ Finally, add the `routes()` method to **app/Config/Services.php** to create a ne
152164

153165
namespace Config;
154166

167+
use App\Router\MyRouteCollection;
155168
use CodeIgniter\Config\BaseService;
156169

157170
class Services extends BaseService
@@ -160,7 +173,7 @@ class Services extends BaseService
160173

161174
public static function routes()
162175
{
163-
return new \App\Router\MyRouteCollection(static::locator(), config('Modules'));
176+
return new MyRouteCollection(static::locator(), config('Modules'));
164177
}
165178
}
166179
```
@@ -177,14 +190,15 @@ A good example is the `renderer` service. By default, we want this class to be a
177190
namespace Config;
178191

179192
use CodeIgniter\Config\BaseService;
193+
use CodeIgniter\View\View;
180194

181195
class Services extends BaseService
182196
{
183197
// ...
184198

185199
public static function renderer($viewPath = APPPATH . 'views/')
186200
{
187-
return new \CodeIgniter\View\View($viewPath);
201+
return new View($viewPath);
188202
}
189203
}
190204
```
@@ -194,7 +208,9 @@ This sets the default path in the constructor method, but allows for easily chan
194208
```php
195209
<?php
196210

197-
$renderer = \Config\Services::renderer('/shared/views/');
211+
use Config\Services;
212+
213+
$renderer = Services::renderer('/shared/views/');
198214
```
199215

200216
### Shared Classes
@@ -206,6 +222,7 @@ There are occasions where you need to require that only a single instance of a s
206222

207223
namespace Config;
208224

225+
use App\Router\MyRouteCollection;
209226
use CodeIgniter\Config\BaseService;
210227

211228
class Services extends BaseService
@@ -218,7 +235,7 @@ class Services extends BaseService
218235
return static::getSharedInstance('routes');
219236
}
220237

221-
return new \App\Router\MyRouteCollection(static::locator(), config('Modules'));
238+
return new MyRouteCollection(static::locator(), config('Modules'));
222239
}
223240
}
224241
```

‎docs/database/events.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ An example to log all queries:
1919

2020
namespace Config;
2121

22+
use CodeIgniter\Database\Query;
2223
use CodeIgniter\Events\Events;
2324
use CodeIgniter\Exceptions\FrameworkException;
2425
use CodeIgniter\HotReloader\HotReloader;
@@ -27,7 +28,7 @@ use CodeIgniter\HotReloader\HotReloader;
2728

2829
Events::on(
2930
'DBQuery',
30-
static function (\CodeIgniter\Database\Query $query) {
31+
static function (Query $query) {
3132
log_message('info', (string) $query);
3233
},
3334
);

‎docs/database/examples.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ The following code loads and initializes the database class based on your [confi
1212
```php
1313
<?php
1414

15-
$db = \Config\Database::connect();
15+
use Config\Database;
16+
17+
$db = Database::connect();
1618
```
1719

1820
Once loaded, the class is ready to be used as described below.

‎docs/database/query_builder.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ The Query Builder is loaded through the `table()` method on the database connect
3030
```php
3131
<?php
3232

33-
$db = \Config\Database::connect();
33+
use Config\Database;
34+
35+
$db = Database::connect();
3436
$builder = $db->table('users');
3537
```
3638

0 commit comments

Comments
 (0)