services:
app.event_listener.frank_martin_shipping_export:
class: App\EventListener\FrankMartinShippingExportEventListener
arguments:
- '@session.flash_bag'
- '@filesystem'
- '@bitbag.manager.shipping_export'
- '%bitbag.shipping_labels_path%'
tags:
- { name: kernel.event_listener, event: 'bitbag.shipping_export.export_shipment', method: exportShipment }
Then use dependencies inside a method named e.g public function __construct(
FlashBagInterface $flashBag,
Filesystem $filesystem,
ObjectManager $shippingExportManager,
string $shippingLabelsPath
) {
$this->flashBag = $flashBag;
$this->filesystem = $filesystem;
$this->shippingExportManager = $shippingExportManager;
$this->shippingLabelsPath = $shippingLabelsPath;
}
public function exportShipment(ResourceControllerEvent $event): void
{
/** @var ShippingExportInterface $shippingExport */
$shippingExport = $event->getSubject();
Assert::isInstanceOf($shippingExport, ShippingExportInterface::class);
$shippingGateway = $shippingExport->getShippingGateway();
Assert::notNull($shippingGateway);
if ('frank_martin_shipping_gateway' !== $shippingGateway->getCode()) {
return;
}
#bussines logic here
}