-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implement support for var_export(new Map()) allowing full class reconstruction #21
Conversation
Implement support for `var_export($map)` to allow for proper code generation
* | ||
* This logger extends the PSR Compliant NullLogger to implement __set_state() | ||
* This allows default support for var_export() compatable code generation. | ||
* Any logger you implement will n |
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.
@mglinski Incomplete doc?
* @return string Implementaiton of logger class to be passed to the Map class | ||
*/ | ||
public static function __set_state($mapData) { | ||
$map = new Map($mapData['map'], $mapData['logger']); |
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.
@mglinski This should be changed to:
public static function __set_state(array $mapData) {
return new static($mapData['map'], $mapData['logger']);
}
Otherwise extended classes will be converted to the parent class: http://codepad.viper-7.com/9dmDCy
Fixed. |
* @return string Implementaiton of logger class to be passed to the Map class | ||
*/ | ||
public static function __set_state($objData = array()) { | ||
return null; |
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.
@mglinski This can't return you should add a test for null
, it must return a valid \Psr\Log\LoggerInterface
or the Map
class will break. In fact,\Zumba\Swivel\Map
that calls \Zumba\Swivel\Map::enabled
after the object has been recreated from a var_export (enabled
calls the logger).
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.
@mglinski correction: the class won't break. But it should still return a NullLogger
so that swivel doesn't have to create another one.
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.
Yea, fixing it now.
…d always return an instance of the parent class, never a scalar/null.
Implement support for var_export(new Map()) allowing full class reconstruction
Implement New NullLogger class to support __set_state() by default