mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-03 10:02:42 +00:00
Implementing __set_state for CakeRoute
It helps the applications to cache the routes using var_export when possible.
This commit is contained in:
parent
7930e680cb
commit
b2a92f9cd8
2 changed files with 29 additions and 0 deletions
|
@ -546,4 +546,22 @@ class CakeRoute {
|
|||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set state magic method to support var_export
|
||||
*
|
||||
* This method helps for applications that want to implement
|
||||
* router caching.
|
||||
*
|
||||
* @param array $fields
|
||||
* @return CakeRoute
|
||||
*/
|
||||
public static function __set_state($fields) {
|
||||
$class = function_exists('get_called_class') ? get_called_class() : __CLASS__;
|
||||
$obj = new $class('');
|
||||
foreach ($fields as $field => $value) {
|
||||
$obj->$field = $value;
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue