Cake\Routing\Route\Route::__set_state PHP Method

__set_state() public static method

This method helps for applications that want to implement router caching.
public static __set_state ( array $fields ) : Route
$fields array Key/Value of object attributes
return Route A new instance of the route
    public static function __set_state($fields)
    {
        $class = get_called_class();
        $obj = new $class('');
        foreach ($fields as $field => $value) {
            $obj->{$field} = $value;
        }
        return $obj;
    }

Usage Example

 /**
  * Test for __set_state magic method on CakeRoute
  *
  * @return void
  */
 public function testSetState()
 {
     $route = Route::__set_state(['keys' => [], 'options' => [], 'defaults' => ['controller' => 'pages', 'action' => 'display', 'home'], 'template' => '/', '_greedy' => false, '_compiledRoute' => null]);
     $this->assertInstanceOf('Cake\\Routing\\Route\\Route', $route);
     $this->assertSame('/', $route->match(['controller' => 'pages', 'action' => 'display', 'home']));
     $this->assertFalse($route->match(['controller' => 'pages', 'action' => 'display', 'about']));
     $expected = ['controller' => 'pages', 'action' => 'display', 'pass' => ['home']];
     $this->assertEquals($expected, $route->parse('/'));
 }