Handlers
2 weeks ago
Routes
2 weeks ago
Webhooks
8 months ago
ApiKeyManager.php
3 months ago
ResourceIdManager.php
5 months ago
ResourceIdManager.php
36 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Api; |
| 4 | |
| 5 | use Hostinger\Reach\Setup\Encrypt; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; |
| 9 | } |
| 10 | |
| 11 | class ResourceIdManager { |
| 12 | public const TRANSIENT_NAME = 'hostinger_reach_resource_id'; |
| 13 | public const TRANSIENT_EXPIRATION_TIME = HOUR_IN_SECONDS; |
| 14 | public const NON_EXISTENT_RESOURCE_ID = 'non_existent_resource_id'; |
| 15 | |
| 16 | public function store_resource_id( string $resource_id ): bool { |
| 17 | return set_transient( self::TRANSIENT_NAME, $this->encrypt_resource_id( $resource_id ), self::TRANSIENT_EXPIRATION_TIME ); |
| 18 | } |
| 19 | |
| 20 | public function clear_resource_id(): string { |
| 21 | return delete_transient( self::TRANSIENT_NAME ); |
| 22 | } |
| 23 | |
| 24 | public function get_resource_id(): string { |
| 25 | return $this->decrypt_resource_id( get_transient( self::TRANSIENT_NAME, '' ) ); |
| 26 | } |
| 27 | |
| 28 | public function encrypt_resource_id( string $resource_id ): string { |
| 29 | return Encrypt::encrypt( $resource_id ); |
| 30 | } |
| 31 | |
| 32 | public function decrypt_resource_id( string $resource_id ): string { |
| 33 | return Encrypt::decrypt( $resource_id ); |
| 34 | } |
| 35 | } |
| 36 |