PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / ai-authorization / infrastructure / refresh-token-user-meta-repository.php

refresh-token-user-meta-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/ai-authorization/infrastructure/refresh-token-user-meta-repository.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\AI_Authorization\Infrastructure;
4
5 use RuntimeException;
6 use Yoast\WP\SEO\Helpers\User_Helper;
7
8 /**
9 * Class Refresh_Token_Repository
10 * Handles the storage and retrieval of refresh tokens for users.
11 */
12 class Refresh_Token_User_Meta_Repository implements Refresh_Token_User_Meta_Repository_Interface {
13
14 /**
15 * The user helper.
16 *
17 * @var User_Helper
18 */
19 private $user_helper;
20
21 /**
22 * Refresh_Token_Repository constructor.
23 *
24 * @param User_Helper $user_helper The user helper.
25 */
26 public function __construct( User_Helper $user_helper ) {
27 $this->user_helper = $user_helper;
28 }
29
30 /**
31 * Get the token for a user.
32 *
33 * @param int $user_id The user ID.
34 *
35 * @return string The token data.
36 *
37 * @throws RuntimeException If the token is not found or invalid.
38 */
39 public function get_token( int $user_id ): string {
40 $refresh_jwt = $this->user_helper->get_meta( $user_id, self::META_KEY, true );
41 if ( ! \is_string( $refresh_jwt ) || $refresh_jwt === '' ) {
42 throw new RuntimeException( 'Unable to retrieve the refresh token.' );
43 }
44
45 return $refresh_jwt;
46 }
47
48 /**
49 * Store the token for a user.
50 *
51 * @param int $user_id The user ID.
52 * @param string $value The token value.
53 *
54 * @return void
55 */
56 public function store_token( int $user_id, string $value ): void {
57 $this->user_helper->update_meta(
58 $user_id,
59 self::META_KEY,
60 $value,
61 ); }
62
63 /**
64 * Delete the token for a user.
65 *
66 * @param int $user_id The user ID.
67 *
68 * @return void
69 */
70 public function delete_token( int $user_id ): void {
71 $this->user_helper->delete_meta( $user_id, self::META_KEY );
72 }
73 }
74