FU<pHUXnGx`RP,GUxppeJU`PBFU<pHUXnGxRP,GUp@IU`pFU <0HU P2@IU``pFU0<0HU0`2@IU` pFU@<0HU@p2FU<?FU>Lx*Ox@DADAAATPy GyHAA{A%ZyGxOxDAAATGxQGxOx@DADARGxOxDAhDAEUP%?@IUP&prFUp&MGUpP&tFU&< FU&/pHUg]B('RP,GU@'p0FUP'tFU'<PFU'pFU'4FU@'+?FU(> IUp}NxP+p0FUP+tFU+<wJU`+@IU``,p0FUP,tFUp,EpeJUPP,B FU,,HUp,GMGU`,tFU,<pHUhNx  x.RP,GU .p?FU0/GU0`/MGU0P2tFU.<?FU4>8TGxLxGxDDAFDAb(A87AAh7AAxfDAZ@AY@AGJx`?A?A IxȖIxIx%ApPAA(#AX#AEUP9?@IUP:prFUp:MGUpP:tFU:<FU@:+?FU;> IU(>p0FUP>tFU><wJU`>@IU`08?p0FU0P?tFU H?EpeJUPP?B FU?,HU?GMGU`?tFU?< IU`P@ppeJU`PABpHU `BRP,GUpxBp@IUPpBpFUB<0HUPB20FU0`Bt0FU pBtFUB<0HU`B2FU@<?FUD>(`LxLxhaLxDDAFDANxZ@AY@APwGx`?A?AHcLxIxxIx%ApPA-KA.KAeLxgGxPOxDADA } /** * Persists a value scoped to a user. * * @param string $key The key. * @param scalar|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * @param int $user_id The user ID. Defaults to the current user. * * @return void * @throws InvalidArgumentException When the value is not JSON-encodable. * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ public function persist_for_user( string $key, $value, int $ttl_in_seconds, int $user_id = 0 ): void { $this->do_persist( $this->prefix_for_user( $key, $user_id ), $value, $ttl_in_seconds ); } /** * Persists a value shared across the entire multisite network. * * @param string $key The key. * @param scalar|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * * @return void * @throws InvalidArgumentException When the value is not JSON-encodable. */ public function persist_for_multisite( string $key, $value, int $ttl_in_seconds ): void { $this->do_persist( $key, $value, $ttl_in_seconds ); } /** * Persists a value scoped to the current blog, only if the key does not already exist. * * @param string $key The key. * @param scalar|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * * @return bool True if the value was inserted, false if the key already exists. * @throws InvalidArgumentException When the value is not JSON-encodable. */ public function persist_if_absent( string $key, $value, int $ttl_in_seconds ): bool { return $this->do_persist_if_absent( $this->prefix_for_blog( $key ), $value, $ttl_in_seconds ); } /** * Persists a value scoped to a user, only if the key does not already exist. * * @param string $key The key. * @param scalar|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * @param int $user_id The user ID. Defaults to the current user. * * @return bool True if the value was inserted, false if the key already exists. * @throws InvalidArgumentException When the value is not JSON-encodable. * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ public function persist_if_absent_for_user( string $key, $value, int $ttl_in_seconds, int $user_id = 0 ): bool { return $this->do_persist_if_absent( $this->prefix_for_user( $key, $user_id ), $value, $ttl_in_seconds ); } /** * Persists a value shared across the entire multisite network, only if the key does not already exist. * * @param string $key The key. * @param scalar|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * * @return bool True if the value was inserted, false if the key already exists. * @throws InvalidArgumentException When the value is not JSON-encodable. */ public function persist_if_absent_for_multisite( string $key, $value, int $ttl_in_seconds ): bool { return $this->do_persist_if_absent( $key, $value, $ttl_in_seconds ); } /** * Gets a value scoped to the current blog. * * @param string $key The key. * * @return scalar|array The stored value. * @throws Key_Not_Found_Exception When the key is not found or has expired. * @throws Corrupted_Value_Exception When the stored value cannot be decoded from JSON. */ public function get( string $key ) { return $this->do_get( $this->prefix_for_blog( $key ) ); } /** * Gets a value scoped to a user. * * @param string $key The key. * @param int $user_id The user ID. Defaults to the current user. * * @return scalar|array The stored value. * @throws Key_Not_Found_Exception When the key is not found or has expired. * @throws Corrupted_Value_Exception When the stored value cannot be decoded from JSON. * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ public function get_for_user( string $key, int $user_id = 0 ) { return $this->do_get( $this->prefix_for_user( $key, $user_id ) ); } /** * Gets a value shared across the entire multisite network. * * @param string $key The key. * * @return scalar|array The stored value. * @throws Key_Not_Found_Exception When the key is not found or has expired. * @throws Corrupted_Value_Exception When the stored value cannot be decoded from JSON. */ public function get_for_multisite( string $key ) { return $this->do_get( $key ); } /** * Checks whether a non-expired value exists for a blog-scoped key. * * @param string $key The key. * * @return bool */ public function has( string $key ): bool { return $this->do_has( $this->prefix_for_blog( $key ) ); } /** * Checks whether a non-expired value exists for a user-scoped key. * * @param string $key The key. * @param int $user_id The user ID. Defaults to the current user. * * @return bool * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ public function has_for_user( string $key, int $user_id = 0 ): bool { return $this->do_has( $this->prefix_for_user( $key, $user_id ) ); } /** * Checks whether a non-expired value exists for a multisite-scoped key. * * @param string $key The key. * * @return bool */ public function has_for_multisite( string $key ): bool { return $this->do_has( $key ); } /** * Deletes a value scoped to the current blog. * * @param string $key The key. * * @return void */ public function delete( string $key ): void { $this->repository->delete( $this->prefix_for_blog( $key ) ); } /** * Deletes a value scoped to a user. * * @param string $key The key. * @param int $user_id The user ID. Defaults to the current user. * * @return void * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ public function delete_for_user( string $key, int $user_id = 0 ): void { $this->repository->delete( $this->prefix_for_user( $key, $user_id ) ); } /** * Deletes a value shared across the entire multisite network. * * @param string $key The key. * * @return void */ public function delete_for_multisite( string $key ): void { $this->repository->delete( $key ); } /** * Cleans up all expired entries. * * @return int The number of deleted entries. */ public function cleanup_expired(): int { return $this->repository->delete_expired( $this->current_datetime() ); } /** * Persists a value with the given prefixed key. * * @param string $prefixed_key The prefixed key. * @param string|int|float|bool|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * * @return void * @throws InvalidArgumentException When the value is not JSON-encodable. */ private function do_persist( string $prefixed_key, $value, int $ttl_in_seconds ): void { $json = $this->json_encode_value( $value ); $exp = \gmdate( 'Y-m-d H:i:s', ( $this->date_helper->current_time() + $ttl_in_seconds ) ); $this->repository->upsert( $prefixed_key, $json, $exp ); } /** * Persists a value only if the prefixed key does not already exist. * * @param string $prefixed_key The prefixed key. * @param string|int|float|bool|array|JsonSerializable $value The value to store. * @param int $ttl_in_seconds The time-to-live in seconds. * * @return bool True if the value was inserted, false if the key already exists. * @throws InvalidArgumentException When the value is not JSON-encodable. */ private function do_persist_if_absent( string $prefixed_key, $value, int $ttl_in_seconds ): bool { $json = $this->json_encode_value( $value ); $now = $this->date_helper->current_time(); $exp = \gmdate( 'Y-m-d H:i:s', ( $now + $ttl_in_seconds ) ); return $this->repository->insert_if_absent( $prefixed_key, $json, $exp, \gmdate( 'Y-m-d H:i:s', $now ) ); } /** * Gets and decodes a value by prefixed key. * * @param string $prefixed_key The prefixed key. * * @return string|int|float|bool|array The stored value. * @throws Key_Not_Found_Exception When the key is not found or has expired. * @throws Corrupted_Value_Exception When the stored value cannot be decoded from JSON. */ private function do_get( string $prefixed_key ) { $json = $this->repository->find( $prefixed_key, $this->current_datetime() ); if ( $json === null ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message. throw new Key_Not_Found_Exception( "Key '{$prefixed_key}' not found or expired." ); } try { return \json_decode( $json, true, 512, \JSON_THROW_ON_ERROR ); } catch ( JsonException $e ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- This is an exception message, not output. throw new Corrupted_Value_Exception( $prefixed_key, $e->getMessage() ); } } /** * Checks whether a non-expired value exists for the given prefixed key. * * @param string $prefixed_key The prefixed key. * * @return bool */ private function do_has( string $prefixed_key ): bool { return $this->repository->find( $prefixed_key, $this->current_datetime() ) !== null; } /** * JSON-encodes a value. * * @param string|int|float|bool|array|JsonSerializable $value The value to encode. * * @return string The JSON-encoded value. * @throws InvalidArgumentException When the value is not JSON-encodable. */ private function json_encode_value( $value ): string { // phpcs:ignore Yoast.Yoast.JsonEncodeAlternative.Found -- WPSEO_Utils::format_json_encode we don't intend to output this. $encoded = \wp_json_encode( $value ); if ( $encoded === false ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- This is an exception message, not output. throw new InvalidArgumentException( 'Expiring_Store: value must be JSON-encodable. ' . \json_last_error_msg() ); } return $encoded; } /** * Prefixes a key for blog scope. * * @param string $key The key. * * @return string The prefixed key. */ private function prefix_for_blog( string $key ): string { return 'blog_' . \get_current_blog_id() . ':' . $key; } /** * Prefixes a key for user scope. * * @param string $key The key. * @param int $user_id The user ID. When 0, falls back to the current user. * * @return string The prefixed key. * @throws No_Current_User_Exception When no user ID is given and no user is logged in. */ private function prefix_for_user( string $key, int $user_id = 0 ): string { if ( $user_id <= 0 ) { $user_id = \get_current_user_id(); } if ( $user_id === 0 ) { throw new No_Current_User_Exception( 'Cannot use user-scoped expiring store methods without a logged-in user.' ); } return 'user_' . $user_id . ':' . $key; } /** * Returns the current datetime in 'Y-m-d H:i:s' format. * * @return string The current datetime. */ private function current_datetime(): string { return \gmdate( 'Y-m-d H:i:s', $this->date_helper->current_time() ); } } https://www.bim-cad-office.de/page-sitemap.xml 2026-03-03T08:56:58+00:00