mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Block Metadata Registry | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
* @since 6.X.0 | ||
*/ | ||
|
||
/** | ||
* Class used for managing block metadata collections. | ||
* | ||
* @since 6.X.0 | ||
*/ | ||
class WP_Block_Metadata_Registry { | ||
|
||
/** | ||
* Container for storing block metadata collections. | ||
* | ||
* @since 6.X.0 | ||
* @var array | ||
*/ | ||
private static $collections = array(); | ||
|
||
/** | ||
* Registers a block metadata collection. | ||
* | ||
* @since 6.X.0 | ||
* | ||
* @param string $path The base path for the collection. | ||
* @param string $manifest The path to the manifest file for the collection. | ||
*/ | ||
public static function register_collection( $path, $manifest ) { | ||
$path = rtrim( $path, '/' ); | ||
self::$collections[ $path ] = array( | ||
'manifest' => $manifest, | ||
'metadata' => null, | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves block metadata for a given block name within a specific collection. | ||
* | ||
* @since 6.X.0 | ||
* | ||
* @param string $path The base path of the collection. | ||
* @param string $block_name The block name to look for. | ||
* @return array|null The block metadata for the block, or null if not found. | ||
*/ | ||
public static function get_metadata( $path, $block_name ) { | ||
$path = rtrim( $path, '/' ); | ||
if ( ! isset( self::$collections[ $path ] ) ) { | ||
return null; | ||
} | ||
|
||
$collection = &self::$collections[ $path ]; | ||
|
||
if ( null === $collection['metadata'] ) { | ||
// Load the manifest file if not already loaded | ||
$collection['metadata'] = require $collection['manifest']; | ||
} | ||
|
||
return isset( $collection['metadata'][ $block_name ] ) ? $collection['metadata'][ $block_name ] : null; | ||
} | ||
|
||
/** | ||
* Checks if metadata exists for a given block name in a specific collection. | ||
* | ||
* @since 6.X.0 | ||
* | ||
* @param string $path The base path of the collection. | ||
* @param string $block_name The block name to check for. | ||
* @return bool True if metadata exists for the block, false otherwise. | ||
*/ | ||
public static function has_metadata( $path, $block_name ) { | ||
return null !== self::get_metadata( $path, $block_name ); | ||
} | ||
|
||
/** | ||
* Private constructor to prevent instantiation. | ||
*/ | ||
private function __construct() { | ||
// Prevent instantiation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters