Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::read
Gets post representing a push token.
Метод класса: PushTokensDataStore{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->read( $push_token ): void;
- $push_token(PushToken) (обязательный)
- An instance of PushToken.
Список изменений
| С версии 10.5.0 | Введена. |
Код PushTokensDataStore::read() PushTokensDataStore::read WC 10.5.2
public function read( PushToken &$push_token ): void {
if ( ! $push_token->can_be_read() ) {
throw new InvalidArgumentException(
'Can\'t read push token because the push token data provided is invalid.'
);
}
$post = get_post( $push_token->get_id() );
if ( ! $post || PushToken::POST_TYPE !== $post->post_type ) {
throw new PushTokenNotFoundException( 'Push token could not be found.' );
}
$meta = $this->build_meta_array_from_database( $push_token );
if (
empty( $meta['token'] )
|| empty( $meta['platform'] )
|| empty( $meta['origin'] )
|| (
empty( $meta['device_uuid'] )
&& PushToken::PLATFORM_BROWSER !== $meta['platform']
)
) {
throw new InvalidArgumentException(
'Can\'t read push token because the push token record is malformed.'
);
}
$push_token->set_user_id( (int) $post->post_author );
$push_token->set_token( $meta['token'] );
$push_token->set_platform( $meta['platform'] );
$push_token->set_device_uuid( $meta['device_uuid'] ?? null );
$push_token->set_origin( $meta['origin'] );
}