1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Icybee\Modules\Users;
13
14 /**
15 * Log the user out of the system.
16 *
17 * @property-read User $record The active record representing the user that was logged out. This
18 * property is still available after the user was logged out, unlike the {@link $user} property of
19 * the `$core` object.
20 */
21 class LogoutOperation extends \ICanBoogie\Operation
22 {
23 /**
24 * Returns the record of the user to logout.
25 *
26 * The current user is returned.
27 */
28 protected function lazy_get_record()
29 {
30 global $core;
31
32 return $core->user;
33 }
34
35 /**
36 * Adds the {@link CONTROL_RECORD} control.
37 */
38 protected function get_controls()
39 {
40 return [
41
42 self::CONTROL_RECORD => true
43
44 ] + parent::get_controls();
45 }
46
47 /**
48 * Always returns `true`.
49 */
50 protected function validate(\ICanboogie\Errors $errors)
51 {
52 return true;
53 }
54
55 /**
56 * Logs out the user.
57 *
58 * The {@link logout()} method of the user is invoked to log the user out.
59 *
60 * The location of the response can be defined by the `continue` request parameter or the request referer, or '/'.
61 */
62 protected function process()
63 {
64 $this->record->logout();
65
66 $request = $this->request;
67 $this->response->location = ($request['redirect_to'] ?: $request['continue']) ?: ($request->referer ?: '/');
68
69 return true;
70 }
71 }