Closed pine3ree closed 5 years ago
Thanks, @pine3ree! Cherry-picked to master for release with 1.2.1.
Just ot of curiosity...my usual silly question (@weierophinney ) why couldn't we just delegate hasChanged() call directly to the proxied session (if existing) instead of calling the proxy's isRegenerated() method as well? https://github.com/zendframework/zend-expressive-session/blob/695fe2e7528ae0d52ef2b5c8c58415ff1fa52798/src/LazySession.php#L101 The proxy method checks by itself the proxy's isRegenerated property. https://github.com/zendframework/zend-expressive-session/blob/695fe2e7528ae0d52ef2b5c8c58415ff1fa52798/src/Session.php#L122 From this test though https://github.com/zendframework/zend-expressive-session/blob/695fe2e7528ae0d52ef2b5c8c58415ff1fa52798/test/LazySessionTest.php#L151 it seems we don't want to call the proxy hasChanged() method. The proxy is encapsulated so the only way to get a regenerated clone it is to call the lazy wrapper regenerate() method.
In the current implementation, assuming that the proxied session has been instantiated
$lazySession->hasChanged()
>>calls
$proxy->isRegenerated()
>>which internally checks the
$proxy->isRegenerated property
>>if false, calls
$proxy->hasChanged()
>>which internally checks (again) the
$proxy->isRegenerated property
>>if false (again, if it was before it is now) finally
>>compares data with original data
kind regards
PS I didn't change that behaviour in the PR because of the test case, but I couldn't find a good reason for it
isRegenerated()
: if there is no proxiedSession then theregenerate()
method has not been called (because it would have created the proxy), so it should return false without triggering a proxy instantiation by itself. (the proxy instance is encapsulated, the only way to "regenerate" it is by calling the lazy wrapper/decorator's regenerate() method)hasChanged()
: replaced thegetProxiedSession()
calls with theproxiedSession
property as the preceding "if" condition ensures we have an instance at this point.