Skip to content

Commit b570c94

Browse files
committed
address copilot reviews
1 parent 2bef676 commit b570c94

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

docs/en/development/dependency-injection.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ class EmailService
126126
->setSubject('Welcome to our platform!')
127127
->setViewVars(['name' => $user->name])
128128
->viewBuilder()
129-
->setTemplate('welcome')
130-
->deliver();
129+
->setTemplate('welcome');
130+
131+
$this->mailer->deliver();
131132
}
132133

133134
public function sendPasswordReset(User $user, string $token): void
@@ -139,8 +140,9 @@ class EmailService
139140
->setSubject('Password Reset Request')
140141
->setViewVars(['resetUrl' => $resetUrl, 'name' => $user->name])
141142
->viewBuilder()
142-
->setTemplate('password_reset')
143-
->deliver();
143+
->setTemplate('password_reset');
144+
145+
$this->mailer->deliver();
144146
}
145147
}
146148

@@ -231,6 +233,7 @@ class PaymentService
231233
return [
232234
'success' => true,
233235
'client_secret' => $intent->client_secret,
236+
'intent_id' => $intent->id,
234237
];
235238
} catch (\Exception $e) {
236239
$this->logger->error('Payment failed', [
@@ -257,7 +260,7 @@ class OrdersController extends AppController
257260
{
258261
public function checkout(PaymentService $payments)
259262
{
260-
$order = $this->Orders->getOrFail($this->request->getQuery('order_id'));
263+
$order = $this->Orders->get($this->request->getQuery('order_id'));
261264

262265
$result = $payments->processOrder($order);
263266

@@ -278,7 +281,7 @@ public function services(ContainerInterface $container): void
278281

279282
// Configure Stripe with API key from config
280283
$container->add(StripeClient::class, function () {
281-
return new StripeClient(Configure::read('Stripe.secretKey'));
284+
return new StripeClient(Configure::readOrFail('Stripe.secretKey'));
282285
});
283286
}
284287
```
@@ -311,6 +314,8 @@ class LocalStorageService implements StorageServiceInterface
311314

312315
public function put(string $path, $contents): bool
313316
{
317+
// Normalize path to prevent directory traversal
318+
$path = str_replace(['..', '\\'], ['', '/'], $path);
314319
$fullPath = $this->basePath . DS . $path;
315320
$dir = dirname($fullPath);
316321

@@ -567,7 +572,7 @@ $container->addShared(BillingService::class);
567572
### Using ORM Tables as Services
568573

569574
If you want to have ORM Tables injected as a dependency to a service, you can
570-
add `TableContainer` to your applications's service container:
575+
add `TableContainer` to your application's service container:
571576

572577
``` php
573578
use Cake\ORM\Locator\TableContainer;
@@ -1222,10 +1227,12 @@ Auto Wiring is turned off by default. To enable it:
12221227

12231228
``` php
12241229
// In src/Application.php
1230+
use League\Container\ReflectionContainer;
1231+
12251232
public function services(ContainerInterface $container): void
12261233
{
12271234
$container->delegate(
1228-
new League\Container\ReflectionContainer(),
1235+
new ReflectionContainer(),
12291236
);
12301237
}
12311238
```
@@ -1235,9 +1242,11 @@ not cache resolutions which can be detrimental to performance. To enable
12351242
caching:
12361243

12371244
``` php
1245+
use League\Container\ReflectionContainer;
1246+
12381247
$container->delegate(
12391248
// or consider using the value of Configure::read('debug')
1240-
new League\Container\ReflectionContainer(true),
1249+
new ReflectionContainer(true),
12411250
);
12421251
```
12431252

0 commit comments

Comments
 (0)