PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 19.0 All 129 releases
wordpress-seo / src / ai / authorization / infrastructure / access-token-user-meta-repository.php

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

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