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β
-
Service Registration:
- The entire
dpdconfiguration array is injected as%dpd%
- The entire
-
DpdApi Constructor:
- Receives the complete array:
['api_url' => '...', 'user_id' => '...', ...] - Extracts individual values using array access:
$config['api_url']
- Receives the complete array:
-
DpdService:
- Continues to use
$this->container->getParameter('dpd')which works correctly
- Continues to use
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
Related Files Modifiedβ
- β
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.apiservice shows indebug: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_urluser_idpasswordcustomer_codedeparture_depot
Issue: Still getting ParameterNotFoundExceptionβ
Solution:
- Clear cache again:
php bin/console cache:clear - Check for typos in services.yml
- 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!