-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: make Session iterable #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thanks for including the test case. We have some test failures, I think it's from the missing guard statements.
We don't need Serializable, there's nothing in Session that would require special handling. It's only needed when serializing objects that contain things needing special handling like resources. We have a simple array, and so Session can be serialized just fine as-is. |
Co-authored-by: Jonathon Hill <[email protected]>
Reason is
I think
|
By using empty arrays instead of null, Should I keep the method, and use a property like: That way no changes to the Manager need to be done as it uses the method to determine whether or not to open the Session. I'm wondering if the Manager always opens the Session regardless of flow. If so, it would be better to remove the method. Another method would be to simply ignore the errors. |
Let's not do that, it's uninitialized for a reason.
The guard statement will prevent acting on a null $contents, but PHPStan doesn't know that, so in this case I think it's fine to just add |
Updated tests as well
|
* implement Iterator in Session class * make Session Iterator throw if not initialized Co-authored-by: Jonathon Hill <[email protected]> * phpstan: ignore iterator parameter errors in Session class * update iterator tests Co-authored-by: Yani <[email protected]> Co-authored-by: Jonathon Hill <[email protected]>
Implemented
\Iterator
interface intoSession
class.The
\Iterator
interface is what makesforeach()
work.Also added a testing scenario.
Closes my own issue: #10
Still wondering if
Serializable
is worth implementing.