Skip to main content

DPD Configuration Fix - Parameter Injection

Issue Fixed​

Error:

ParameterNotFoundException
The service "mz.dpd.api" has a dependency on a non-existent parameter "dpd.api_url".
You cannot access nested array items, do you want to inject "dpd" instead?

Root Cause​

Symfony does not allow accessing nested parameters directly like %dpd.api_url%. The parameters must be accessed as a complete array.

Solution Applied​

1. Updated Service Definition​

File: src/CoreBundle/Resources/config/services.yml

Before:

mz.dpd.api:
class: "%mz.dpd.api.class%"
arguments:
- "@logger"
- "%dpd.api_url%" # ❌ This doesn't work
- "%dpd.user_id%" # ❌ This doesn't work
- "%dpd.password%" # ❌ This doesn't work

After:

mz.dpd.api:
class: "%mz.dpd.api.class%"
arguments:
- "@logger"
- "%dpd%" # βœ… Pass entire array

2. Updated DpdApi Constructor​

File: src/CoreBundle/Api/DpdApi.php

Before:

public function __construct(
LoggerInterface $logger,
string $baseUrl,
string $userId,
string $password
) {
$this->logger = $logger;
$this->baseUrl = rtrim($baseUrl, '/');
$this->userId = $userId;
$this->password = $password;
// ...
}

After:

public function __construct(
LoggerInterface $logger,
array $config // βœ… Accept array parameter
) {
$this->logger = $logger;
$this->baseUrl = rtrim($config['api_url'], '/');
$this->userId = $config['user_id'];
$this->password = $config['password'];
// ...
}

Configuration Structure​

Your parameters.yml should have this structure:

dpd:
api_url: 'https://api.brt.it'
user_id: 'YOUR_ACTUAL_USER_ID'
password: 'YOUR_ACTUAL_PASSWORD'
customer_code: 123456
departure_depot: 123
operating_mode: 'auto'

How It Works Now​

  1. Service Registration:

    • The entire dpd configuration array is injected as %dpd%
  2. DpdApi Constructor:

    • Receives the complete array: ['api_url' => '...', 'user_id' => '...', ...]
    • Extracts individual values using array access: $config['api_url']
  3. DpdService:

    • Continues to use $this->container->getParameter('dpd') which works correctly

Steps to Apply Fix​

1. Clear Cache​

php bin/console cache:clear

2. Verify Service Registration​

php bin/console debug:container mz.dpd.api

Expected Output:

Information for Service "mz.dpd.api"
=====================================

Service ID mz.dpd.api
Class CoreBundle\Api\DpdApi
Tags monolog.logger
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no

3. Test Service Instantiation​

Create a test script or use Symfony console:

// In a controller or command
$dpdApi = $this->get('mz.dpd.api');
// Should work without errors now
  • βœ… src/CoreBundle/Resources/config/services.yml
  • βœ… src/CoreBundle/Api/DpdApi.php
  • ⚠️ app/config/parameters.yml (ensure structure is correct)

Common Pitfalls to Avoid​

❌ Don't Do This:​

# In services.yml
arguments:
- "%dpd.api_url%" # Won't work with nested arrays

βœ… Do This Instead:​

# In services.yml
arguments:
- "%dpd%" # Pass entire array

# Then in PHP constructor:
$config['api_url'] # Access array items

Pattern Used in Other Services​

This follows the same pattern as other transporter services in Logidav:

Geodis Example:​

# services.yml
mz.geodis.api:
class: "%mz.geodis.class%"
arguments: ["%geodis%"] # Entire array

Parameters:​

# parameters.yml
geodis:
Send:
url: 'https://...'
login: 'xxx'
api_key: 'xxx'

Verification Checklist​

After applying the fix, verify:

  • Cache cleared successfully
  • No errors when loading the application
  • mz.dpd.api service shows in debug:container
  • Can access /dpd/ dashboard without errors
  • Can create test shipment from /sale/processing-not-printed

If You Still See Errors​

Issue: Parameters not found​

Solution: Ensure parameters.yml has the dpd: section (copy from parameters.yml.dist)

# Check if dpd config exists
grep -A 6 "^dpd:" app/config/parameters.yml

Issue: Array key doesn't exist​

Solution: Check that all required keys exist in your dpd config:

  • api_url
  • user_id
  • password
  • customer_code
  • departure_depot

Issue: Still getting ParameterNotFoundException​

Solution:

  1. Clear cache again: php bin/console cache:clear
  2. Check for typos in services.yml
  3. Verify the parameter name matches exactly: %dpd% (not %dpd_config% or similar)

Summary​

βœ… Fixed: Service injection now uses array parameter %dpd% βœ… Updated: DpdApi constructor accepts configuration array βœ… Compatible: Follows same pattern as other transporters (Geodis, etc.) βœ… No Breaking Changes: DpdService continues to work as before

The integration is now properly configured and ready to use!