{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zf2/issues/7381","labels_url":"https://api.github.com/repos/zendframework/zf2/issues/7381/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zf2/issues/7381/comments","events_url":"https://api.github.com/repos/zendframework/zf2/issues/7381/events","html_url":"https://github.com/zendframework/zf2/issues/7381","id":64945288,"number":7381,"title":"[Feature] Allow Session validators to be created using the service manager","user":{"login":"larsnystrom","id":1000370,"avatar_url":"https://avatars.githubusercontent.com/u/1000370?v=3","gravatar_id":"","url":"https://api.github.com/users/larsnystrom","html_url":"https://github.com/larsnystrom","followers_url":"https://api.github.com/users/larsnystrom/followers","following_url":"https://api.github.com/users/larsnystrom/following{/other_user}","gists_url":"https://api.github.com/users/larsnystrom/gists{/gist_id}","starred_url":"https://api.github.com/users/larsnystrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larsnystrom/subscriptions","organizations_url":"https://api.github.com/users/larsnystrom/orgs","repos_url":"https://api.github.com/users/larsnystrom/repos","events_url":"https://api.github.com/users/larsnystrom/events{/privacy}","received_events_url":"https://api.github.com/users/larsnystrom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-28T13:55:05Z","updated_at":"2015-03-28T14:22:01Z","closed_at":null,"body":"At the moment it is not possible to inject any dependencies into a session validator. There is simply no way to do that, since all session validators are created inside the `SessionManager` or the `ValidatorChain`.\r\n\r\nIn a perfect world, the word `new` would never have made it into any of the Session classes, but here we are.\r\n\r\nI think I can hack a way around this by extending `ValidatorInterface` and add a method called `setData()`, which could be used to inject the session value to validate, instead of using the constructor to do that. This would allow a factory to create the validator, and the `ValidatorChain` to inject the session value to validate.\r\n\r\nBy extending the `ValidatorInterface` there will be no BC breaks, but the code will get pretty ugly. I still think that would be better than the current situation.\r\n\r\nDo you have any thoughts on this?"},"comment":{"url":"https://api.github.com/repos/zendframework/zf2/issues/comments/87234713","html_url":"https://github.com/zendframework/zf2/issues/7381#issuecomment-87234713","issue_url":"https://api.github.com/repos/zendframework/zf2/issues/7381","id":87234713,"user":{"login":"Martin-P","id":1311879,"avatar_url":"https://avatars.githubusercontent.com/u/1311879?v=3","gravatar_id":"","url":"https://api.github.com/users/Martin-P","html_url":"https://github.com/Martin-P","followers_url":"https://api.github.com/users/Martin-P/followers","following_url":"https://api.github.com/users/Martin-P/following{/other_user}","gists_url":"https://api.github.com/users/Martin-P/gists{/gist_id}","starred_url":"https://api.github.com/users/Martin-P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Martin-P/subscriptions","organizations_url":"https://api.github.com/users/Martin-P/orgs","repos_url":"https://api.github.com/users/Martin-P/repos","events_url":"https://api.github.com/users/Martin-P/events{/privacy}","received_events_url":"https://api.github.com/users/Martin-P/received_events","type":"User","site_admin":false},"created_at":"2015-03-28T14:22:01Z","updated_at":"2015-03-28T14:22:01Z","body":"> I think I can hack a way around this by extending `ValidatorInterface` and add a method called `setData()`, which could be used to inject the session value to validate\r\n\r\nWhen the reference value exists in the current session it is automatically injected into the validator in [`Zend\\Session\\SessionManager::initializeValidatorChain()`](https://github.com/zendframework/zf2/blob/ce576affcc666f8ab830d519288743a5a425567e/library/Zend/Session/SessionManager.php#L153). You don't have to do this yourself.\r\n\r\nYou can also add validators to the `ValidatorChain` directly by using `SessionManager::getValidatorChain()`."}}