How can I see list of available events in Symfony2 - symfony

How can I see all available events in Symfony2?
I found a command on google
php app\console container:debug --show-private
But it does not show all available events. Like event named "security.interactive_login" is not listed in it.
Is there a way to see available events?

Console command
You can run:
app/console debug:event-dispatcher
This will show you a detailed summary of every subscriber, in order of priority per event. Unfortunately this won't show you all possible events, since it's infeasible to query the container for any events that could be registered due to the inherently dynamic nature of the events system.
To understand events you'll need to refer to docs and code of each component and bundle.
Documentation is the best place to start
Symfony standard ships with a multitude of events. Each Symfony component and bundle may or may not define events — your best bet is to look at each component or bundle's documentation for references to events.
Some very common events can be found in the docs:
HTTP Kernel Events
Console Events
Form Events
Code analysis
I used PhpStorm to look for all subclasses of Symfony's base Event class (Symfony\Component\EventDispatcher\Event).
I generated an inheritance tree each child is a subclass of it's parent.
* note: prepend Symfony\Component\ to find the FQN
EventDispatcher\Event
EventDispatcher\GenericEvent
Console\Event\ConsoleEvent
Console\Event\ConsoleCommandEvent
Console\Event\ConsoleExceptionEvent
Console\Event\ConsoleTerminateEvent
Form\FormEvent
HttpKernel\Event\KernelEvent
HttpKernel\Event\FilterResponseEvent
HttpKernel\Event\FilterControllerEvent
HttpKernel\Event\FinishRequestEvent
HttpKernel\Event\GetResponseEvent
HttpKernel\Event\GetResponseForControllerResultEvent
HttpKernel\Event\GetResponseForExceptionEvent
HttpKernel\Event\PostResponseEvent
Security\Http\Event\SwitchUserEvent
Security\Http\Event\InteractiveLoginEvent
I make no claim that these are all public events you can/should hook into — this is just one way to programmatic examine 3rd party code and get a sense for potential idioms.
For instance I noticed that both the HttpKernel, Security, and Console components use namespaced constants to expose their keys, see:
Symfony\Component\HttpKernel\KernelEvents
Symfony\Component\Security\Http\SecurityEvents
Symfony\Component\Console\ConsoleEvents

The container:debug command shows all services that are registered to the dependency injection container. With the parameter show-private it will also show services that are flagged with public=false.
So as the most events might not be services the command you are using will not give you a list of available events. But to give you a possibility to search for available events you could try the following command:
php app/console container:debug --show-private | grep -i "listener"
As the most event handlers might have the word listener in their definitions you will find many of them. If you then want to get a more detailed information about the events which are handled by those listeners just call the command with specifying the service ID. For example if you are working with the FOSUserBundle this will give you a description for the interactive login listener:
php app/console container:debug fos_user.security.interactive_login_listener

Related

Finding status if MDB is running

I want to use mbeans on startup of j2ee application to check if all the MDBs are running and jms specification has been activated.
Any pointers will be very helpful
The only way I know of to do this would be to use the ServerEndpointControl MBean. This is a Liberty specific MBean for controlling the input sources for work into the runtime. This can also be used to get status on http listeners.
The best place to find the Javadoc for the MBean is here. To find out if an MBean is running you call the isPaused method providing the MDB name which is defined as:
ApplicationName#ModuleName#BeanName
if the MDB is running it'll return false.

Symfony - background task from form setup

Would you know how to run a background task on Symfony 4, based on the setup of a form ? This would avoid that the user has to remain on the form until the task is finished.
The idea would be that when the form is validated, it starts an independant background task. Then the user can continue its navigation and come back once the task is finished to get the results.
Thanks for your help,
You need to use pattern Message Bus. Symfony has own implementation of this pattern since version 4.1 introducing Messenger Component.
You can see documentation here: https://symfony.com/doc/current/components/messenger.html
To get it work you need some external program that will implement AMQP protocol. Most popular in PHP world IMHO RabbitMQ.
A very simple solution for this could be the following procedure:
Form is valid.
A temporary file is created.
Cronjob gets executed every five minutes and starts a symfony command.
The command checks if the file exists and if it's empty.
If so, the command works of the background task. But before this, the command write it's process id in the file to prevent from beeing excuted a second time.
Remove the file when the command has finished.
As long as the file exists you can show a hint for the user that the task is running.

How to get the user who initiated the process in IBM BPM 8.5?

How to get the user who initiated the process in IBM BPM 8.5. I want to reassign my task to the user who actually initiated the process. How it can be achieved in IBM BPM?
There are several ways to get that who initiated a Task , But who initiated a process Instance is somewhat different.
You can perform one out of the following :
Add a private variable and assign it tw.system.user_loginName at the POST of start. you can access that variable for user who initiated the process.(It will be null or undefined for the scenario if task is initiated by some REST API or UCA.)
Place a Tracking group after Start event . Add a input variable to it as username , assign it a value same as tw.system.user_loginName. So whenever Process is started entry will be inserted to DB Table.You can retrieve this value from that view in PerformanceDB.
Also there might be some table ,logging the process Instances details , where you can find the user_id directly.
I suggest you to look in getStarter() method of ProcessInstanceData API.
Official Documentation on API
This link on IBM Developerworks should help you too: Process Starter
Unfortunately there's not an Out Of The Box way to do this - nothing is recorded in the Process Instance that indicates "who" started a process. I presume this is because there are many ways to launch a process instance - from the Portal, via a Message Event, from an API call, etc.
Perhaps the best way to handle this is to add a required Input parameter to your BPD, and supply "who" started the process when you launch it. Unfortunately you can't supply any inputs from the OOTB Portal "New", but you can easilty build your own "launcher".
If you want to route the first task in process to the user that started the process the easiest approach is to simply put the start point in the lane, and on the activity select routing to "Last User In Lane". This will take care of the use case for you without requiring that you do the book keeping to track the user.
Its been a while since I've implemented this, so I can't remember if it will work elegantly if you have system steps before the first task, but this can easily be handled by moving the system steps into the human service to be executed as part of that call, rather than as a separate step in the BPD.
Define variable as string type and using script task to define the login user that use this task and assign it to your defined variable to keep to you in all of the process as initiator of the task.
You can use this line of code to achieve the same:
tw.system.user_loginName

Symfony2 calling console command in controller from vendor

I want to use a console command from this bundle within my controller: http://knpbundles.com/dizda/CloudBackupBundle
The developer proposes cronjobs, however I want to use the command to backup my database from within my controller.
How would I do that?
I am getting this error message when i simply try to register this command as a service:
You have requested a non-existent service "backupcommandservice".
Thanks for the help!
commands don't quite work that way. Per the note on http://symfony.com/doc/current/cookbook/console/console_command.html#register-commands-in-the-service-container
registering a command as a service doesn't do much other than control location and dependency injection.
if you want to call a command: http://symfony.com/doc/current/components/console/introduction.html#calling-an-existing-command
that being said you shouldn't call commands from within a controller since you're basically asking to wait for this command to finish executing before you return a response. You'd be better off just sending a request to a queue box (for example beanstalk) and have a worker perform the job.

When or how would I use this.flush() in a Meteor application

I am trying to understand when I might use this.flush() in a Meteor application.
The docs state the following
Call inside publish function. Sends all the pending set, unset, and
complete messages to the client.
If my publish function is something like this
Meteor.publish('myCollection', function(myid){
return MyCollection.find({_id: myid});
});
would I use this.flush()?
What kind of case would one use this.flush() in?
Thanks
S
Not needed in that use case, because Meteor.publish automatically handles the details of how to turn Mongo cursors into the appropriate set and unset commands for each subscribed client.
If you write a custom publish that manages its own set and unset, you can use flush to push all pending changes down to the client. You'll find an example of that technique here: How does the messages-count example in Meteor docs work?

Resources