Automattic\WooCommerce\Api\Infrastructure
ResolverHelpers::harvest_class_metadata
Mirror of ApiBuilder::harvest_metadata() for the runtime path. Walks Metadata{}-subclass attributes on a class reflector and returns name => value. Duplicate names are resolved last-wins — the build-time validator already errors on duplicates, so this is only relevant for in-process classes that never went through a build.
The per-target _apiMetadata opt-out (shows_in_metadata_query()) is not applied here: the $_metadata slot threaded into a class- level attribute's authorize() is for policy input, not discovery, so attribute authors see every entry regardless of how it surfaces through _apiMetadata.
Method of the class: ResolverHelpers{}
No Hooks.
Returns
Array
Usage
$result = ResolverHelpers::harvest_class_metadata( $ref ): array;
- $ref(ReflectionClass) (required)
- The class to read metadata from.
ResolverHelpers::harvest_class_metadata() ResolverHelpers::harvest class metadata code WC 10.9.1
private static function harvest_class_metadata( \ReflectionClass $ref ): array {
$entries = array();
foreach ( $ref->getAttributes( \Automattic\WooCommerce\Api\Attributes\Metadata::class, \ReflectionAttribute::IS_INSTANCEOF ) as $attribute ) {
$instance = $attribute->newInstance();
$entries[ $instance->get_name() ] = $instance->get_value();
}
return $entries;
}