{"action":"created","issue":{"url":"https://api.github.com/repos/Kdyby/Events/issues/65","labels_url":"https://api.github.com/repos/Kdyby/Events/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/Kdyby/Events/issues/65/comments","events_url":"https://api.github.com/repos/Kdyby/Events/issues/65/events","html_url":"https://github.com/Kdyby/Events/issues/65","id":53431603,"number":65,"title":"Weird order of event listeners","user":{"login":"enumag","id":539462,"avatar_url":"https://avatars.githubusercontent.com/u/539462?v=3","gravatar_id":"","url":"https://api.github.com/users/enumag","html_url":"https://github.com/enumag","followers_url":"https://api.github.com/users/enumag/followers","following_url":"https://api.github.com/users/enumag/following{/other_user}","gists_url":"https://api.github.com/users/enumag/gists{/gist_id}","starred_url":"https://api.github.com/users/enumag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enumag/subscriptions","organizations_url":"https://api.github.com/users/enumag/orgs","repos_url":"https://api.github.com/users/enumag/repos","events_url":"https://api.github.com/users/enumag/events{/privacy}","received_events_url":"https://api.github.com/users/enumag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-01-05T19:15:50Z","updated_at":"2015-01-05T21:08:35Z","closed_at":null,"body":"I use Kdyby/Events dev-master, not stable.\r\n\r\nI've an event in one of my components:\r\n\r\n```php\r\nclass FooFormControl extends Control\r\n{\r\n\t/** @var callable[] */\r\n\tpublic $onSuccess;\r\n\t//...\r\n}\r\ninterface IFooFormFactory\r\n{\r\n\t/** @return FooFormControl */\r\n\tpublic function create();\r\n}\r\n```\r\n\r\nIn presenter I create the component using a generated factory and bind a callback function:\r\n\r\n```php\r\nclass FooPresenter extends BasePresenter\r\n{\r\n\tpublic function actionDefault($id)\r\n\t{\r\n\t\t//...\r\n\t\t$this->getComponent('form')->onSuccess[] = function () {\r\n\t\t\t$this->flashMessage('...');\r\n\t\t\t$this->redirect('Homepage:');\r\n\t\t};\r\n\t}\r\n\tprotected function createComponentForm(IFooFormFactory $factory)\r\n\t{\r\n\t\treturn $factory->create();\r\n\t}\r\n}\r\n```\r\n\r\nI also have a listener:\r\n\r\n```php\r\nclass FooListener extends Object implements Subscriber\r\n{\r\n\tpublic function getSubscribedEvents()\r\n\t{\r\n\t\treturn [\r\n\t\t\t'FooFormControl::onSuccess' => 'fooSuccess',\r\n\t\t];\r\n\t}\r\n\tpublic function fooSuccess()\r\n\t{\r\n\t\t//...\r\n\t}\r\n}\r\n```\r\n\r\nTurns out that the listener is never called because the callback from presenter is executed first and the redirect shut's down the application. I expected the listener to be executed first because it was added first (by the generated code in generated factory) and the callback from presenter was added later.\r\n\r\nWhen I remove the redirect, the listener is indeed executed, I checked that.\r\n\r\nIs this a bug or a feature? Or am I missing something?\r\n\r\nOr should I use a different approach? If so can you suggest? :-)"},"comment":{"url":"https://api.github.com/repos/Kdyby/Events/issues/comments/68781684","html_url":"https://github.com/Kdyby/Events/issues/65#issuecomment-68781684","issue_url":"https://api.github.com/repos/Kdyby/Events/issues/65","id":68781684,"user":{"login":"enumag","id":539462,"avatar_url":"https://avatars.githubusercontent.com/u/539462?v=3","gravatar_id":"","url":"https://api.github.com/users/enumag","html_url":"https://github.com/enumag","followers_url":"https://api.github.com/users/enumag/followers","following_url":"https://api.github.com/users/enumag/following{/other_user}","gists_url":"https://api.github.com/users/enumag/gists{/gist_id}","starred_url":"https://api.github.com/users/enumag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enumag/subscriptions","organizations_url":"https://api.github.com/users/enumag/orgs","repos_url":"https://api.github.com/users/enumag/repos","events_url":"https://api.github.com/users/enumag/events{/privacy}","received_events_url":"https://api.github.com/users/enumag/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T21:08:35Z","updated_at":"2015-01-05T21:08:35Z","body":"Another thing to consider is adding an option to DI extension to make this behaviour default."}}