What are the Slack Archives?
Itβs a history of our time together in the Slack Community! Thereβs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonβt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
hello, how to pass arguments from subscriber to listener, my code ```Subscriber: $eventCollection-&g
hello,
how to pass arguments from subscriber to listener, my code
Subscriber: $eventCollection->addListenerQueued(ProductEvents::PRODUCT_ABSTRACT_AFTER_CREATE, new KacperListener('my argument')); Listener: public function __construct($URL_TO_API) { $this->URL_TO_API = $URL_TO_API; }
give me an error:Too few arguments to function Pyz\Zed\....\KacperListener::__construct(), 0 passed in
Comments
-
Hi Kacper,
your Listener should extend\Spryker\Zed\Kernel\Communication\AbstractPlugin
This will give you access to the modules Config. Facade, Factory and QueryContainer by calling e.g.getConfig()
0 -
@UKHR9UN00 i need example how to pass my custom argument from subscriber to listener
0 -
To answer your question: I guess there is no need to pass an argument from subscriber to listener. Can you give an example for when this is necessary
0 -
@UKHR9UN00 i created package, i install it from composer, and i want implement it in eventTransferProvider, i must pass one argument URL_API, to send specific data, i want that plugin will be univerasal
0 -
so my idea is pass argument in eventTrasfer -> subscriber -> listener -> senddata,
I think the best option is to add const and pass there url but i dont know how to implement it on client side0 -
@UKHR9UN00 maybe, i can set global const in spryker ?
0 -
~I think you can use any Transfer-Object for an event, so you can have your own KacperEventTransfer. Let me check if I can find an example~ Does not fit your example
0 -
But if the value can be configured once, you might better extend your Listener-Logic in your Project and set the URL by using the
getConfig()
-Method.0 -
but how i can pass an argument there, implementation my module will be only in EventDependencyProvider, ex.
//here i can set this url, but how $eventSubscriberCollection->add(new MySubscriber());
0 -
Sorry, I'm not sure if I got you right.
Is the URL something that will be different for every fired event or this this an environment setting?0 -
environment setting, look i explain, you set (but i dont know where
url = my custom url,
next copy paste$eventSubscriberCollection->add(new MySubscriber());
to EventDependencyProvider, and data goes to "my_custom_url"
0 -
Okay, for environment settings you should use the shared configuration files like config_default.php or config_default-ENVIRONMENT.php in
config/Shared
In
Pyz/Shared/MyModule/MyModuleConstants.php
you define a constantpublic const MY_SETTING = 'MY_MODULE:MY_SETTING
which you will use a array key in the config file.Then in your
Pyz/Zed/MyModule/MyModuleConfig.php
you create a new method likepublic function getMySetting(): string { return $this->get(MyModuleConstants::MY_SETTING); }
And finally in your Subscriber (e.g.
Pyz/Zed/MyModule/Communication/Plugin/Event/Subscriber/MySubscriber.php
) which extends the AbstractPlugin class you can your$this->getConfig()->getMySetting();
0 -
so i must add something to Pyz / Shared /, or only in config_default.php is enough ?, i want to make the implementation the easiest
0 -
I guess you could only add it to config_default.php and use
\Spryker\Shared\Config\Config::get('my-configuration-key', 'fallback-value);
in your subscriber. But that's not how you should write Spryker code0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 924 Developer Corner
- 783 Spryker Development
- 88 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random