answear/econt-pickup-point-bundle
Install the package:
composer require answear/econt-pickup-point-bundle
Symfony Flex will auto-register the bundle in config/bundles.php.
Configure credentials in config/packages/answear_econt.yaml:
answear_econt:
user: 'your_econt_username'
password: 'your_econt_password'
First use case: Fetch pickup offices
Inject the GetOffices command via dependency injection (DI) and call it with a request:
use Answear\EcontBundle\Command\GetOffices;
use Answear\EcontBundle\Request\GetOfficesRequest;
// In a service/controller
$getOffices = $this->container->get(GetOffices::class);
$response = $getOffices->getOffices(new GetOfficesRequest());
Request Creation
Use dedicated request classes (e.g., GetOfficesRequest, GetCitiesRequest) to structure API calls. Example:
$request = new GetOfficesRequest();
$request->setCityId('WAR'); // Warsaw city code
Command Execution Inject commands via DI and execute them:
$cities = $this->get(GetCities::class)->getCities(new GetCitiesRequest());
Response Handling
Responses are typically objects with methods like getData() or getOffices(). Validate responses:
if ($response->isSuccess()) {
$offices = $response->getData();
}
Caching Responses Cache API responses (e.g., cities/offices) to reduce calls:
$cacheKey = 'econt_offices_' . $cityId;
$offices = Cache::remember($cacheKey, now()->addHours(1), function () use ($cityId) {
return $this->get(GetOffices::class)->getOffices(new GetOfficesRequest($cityId))->getData();
});
Error Handling
Wrap API calls in try-catch blocks to handle exceptions (e.g., EcontException):
try {
$response = $getOffices->getOffices($request);
} catch (EcontException $e) {
$this->logger->error('Econt API error: ' . $e->getMessage());
throw new \RuntimeException('Failed to fetch offices', 0, $e);
}
Dependency Injection
Register commands as services in services.yaml for easier testing:
services:
Answear\EcontBundle\Command\GetOffices:
arguments:
$configProvider: '@answear_econt.config_provider'
Testing
Mock the ConfigProvider or use a test double for the EcontClient to isolate tests:
$this->mock(EcontClient::class)
->shouldReceive('getOffices')
->andReturn(new GetOfficesResponse([...]));
Authentication Failures
user/password in answear_econt.yaml are correct. Test credentials via the Econt API docs.$configProvider = $this->app->get(ConfigProvider::class);
$this->logger->debug('Econt Config:', ['user' => $configProvider->getUser()]);
Rate Limiting
sleep(1); // 1-second delay
Deprecated Methods
cityId as strings (e.g., 'WAR'). Use constants or enums for maintainability:
final class CityCodes {
public const WARSAW = 'WAR';
}
Response Validation
getData(). Check for methods dynamically:
if (method_exists($response, 'getData')) {
$data = $response->getData();
}
Enable Guzzle Debugging
Configure Guzzle to log requests/responses in config/packages/answear_econt.yaml:
answear_econt:
debug: true
This will output raw API calls to var/log/dev.log.
Timeout Issues
answear_econt:
timeout: 30 # seconds
PHP 8.4+ Compatibility
$request = new GetOfficesRequest(cityId: 'WAR');
Custom Requests
Extend the base Request class to add custom parameters:
class CustomOfficesRequest extends GetOfficesRequest {
public function __construct(
string $cityId,
private ?string $customParam = null
) {
parent::__construct($cityId);
}
}
Response Transformers Create a decorator for responses to normalize data:
class OfficeResponseDecorator {
public function __construct(private GetOfficesResponse $response) {}
public function getFormattedOffices(): array {
return array_map(function ($office) {
return [
'id' => $office->getId(),
'name' => $office->getName(),
'address' => $office->getAddress(),
];
}, $this->response->getData());
}
}
Event Listeners Trigger events on API responses (e.g., log successful calls):
// In a service
$dispatcher->dispatch(new EcontResponseEvent($response));
Symfony Messenger Integrate with Symfony’s Messenger component to process responses asynchronously:
$message = new ProcessEcontOfficesMessage($response->getData());
$this->messageBus->dispatch($message);
How can I help you explore Laravel packages today?