public function withCookie($name, $data = '')
    {
        if ($name instanceof Cookie) {
            $cookie = $name;
        } else {
            deprecationWarning(
                get_called_class() . '::withCookie(string $name, array $data) is deprecated. ' .
                'Pass an instance of \Cake\Http\Cookie\Cookie instead.'
            );

            if (!is_array($data)) {
                $data = ['value' => $data];
            }
            $data += [
                'value' => '',
                'expire' => 0,
                'path' => '/',
                'domain' => '',
                'secure' => false,
                'httpOnly' => false
            ];
            $expires = $data['expire'] ? new DateTime('@' . $data['expire']) : null;
            $cookie = new Cookie(
                $name,
                $data['value'],
                $expires,
                $data['path'],
                $data['domain'],
                $data['secure'],
                $data['httpOnly']
            );
        }

        $new = clone $this;
        $new->_cookies = $new->_cookies->add($cookie);

        return $new;
    }