WP_Token_Map::from_precomputed_table()public staticWP 6.6.0

Creates a token map from a pre-computed table. This skips the initialization cost of generating the table.

This function should only be used to load data created with WP_Token_Map::precomputed_php_source_tag().

Method of the class: WP_Token_Map{}

No Hooks.

Return

WP_Token_Map. Map with precomputed data loaded.

Usage

$result = WP_Token_Map::from_precomputed_table( $state ): ?WP_Token_Map;
$state(array) (required)

Stores pre-computed state for directly loading into a Token Map.

  • storage_version(string)
    Which version of the code produced this state.

  • key_length(int)
    Group key length.

  • groups(string)
    Group lookup index.

  • large_words(array)
    Large word groups and packed strings.

  • small_words(string)
    Small words packed string.

  • small_mappings(array)
    Small word mappings.

Changelog

Since 6.6.0 Introduced.

WP_Token_Map::from_precomputed_table() code WP 6.8

public static function from_precomputed_table( $state ): ?WP_Token_Map {
	$has_necessary_state = isset(
		$state['storage_version'],
		$state['key_length'],
		$state['groups'],
		$state['large_words'],
		$state['small_words'],
		$state['small_mappings']
	);

	if ( ! $has_necessary_state ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'Missing required inputs to pre-computed WP_Token_Map.' ),
			'6.6.0'
		);
		return null;
	}

	if ( self::STORAGE_VERSION !== $state['storage_version'] ) {
		_doing_it_wrong(
			__METHOD__,
			/* translators: 1: version string, 2: version string. */
			sprintf( __( 'Loaded version \'%1$s\' incompatible with expected version \'%2$s\'.' ), $state['storage_version'], self::STORAGE_VERSION ),
			'6.6.0'
		);
		return null;
	}

	$map = new WP_Token_Map();

	$map->key_length     = $state['key_length'];
	$map->groups         = $state['groups'];
	$map->large_words    = $state['large_words'];
	$map->small_words    = $state['small_words'];
	$map->small_mappings = $state['small_mappings'];

	return $map;
}