PluginProbe
Metricool – Social media and site statistics / 2.0.2
Metricool – Social media and site statistics v2.0.2
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Http / Endpoints / LogoutEndpoint.php

LogoutEndpoint.php in Metricool – Social media and site statistics 2.0.2, at app/Http/Endpoints/LogoutEndpoint.php

70 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Metricool\Http\Endpoints;
6
7 use Metricool\Http\Metricool\MetricoolApi;
8 use Metricool\Interfaces\SingleEndpointInterface;
9 use Metricool\Services\DashboardService;
10 use Metricool\Traits\HasAllowlistControl;
11 use Metricool\Traits\HasRestAccess;
12
13 class LogoutEndpoint implements SingleEndpointInterface
14 {
15 use HasRestAccess;
16 use HasAllowlistControl;
17
18 public const ROUTE = 'logout';
19
20 private MetricoolApi $metricoolApi;
21 private DashboardService $dashboard;
22
23 public function __construct(MetricoolApi $metricoolApi, DashboardService $dashboard)
24 {
25 $this->metricoolApi = $metricoolApi;
26 $this->dashboard = $dashboard;
27 }
28
29 /**
30 * @inheritDoc
31 */
32 public function registerRoute(): string
33 {
34 return self::ROUTE;
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function enabled(): bool
41 {
42 return $this->adminAccessAllowed();
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function registerArguments(): array
49 {
50 return [
51 'methods' => \WP_REST_Server::EDITABLE,
52 'callback' => [$this, 'callback'],
53 'middleware' => ['metricool:auth'],
54 ];
55 }
56
57 /**
58 * Log the user out and redirect to the dashboard
59 */
60 public function callback(\WP_REST_Request $request): \WP_REST_Response
61 {
62 $this->metricoolApi->logout();
63
64 return $this->sendHttpResponse([
65 'state' => $this->dashboard->state(),
66 'mode' => $this->dashboard->mode(),
67 ]);
68 }
69 }
70