Outputs
5 months ago
data
5 months ago
FieldSettings.php
5 months ago
GEO.php
5 months ago
Schema.php
5 months ago
SchemaData.php
5 months ago
SchemaData.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package ACF |
| 4 | * @author WP Engine |
| 5 | * |
| 6 | * © 2026 Advanced Custom Fields (ACF®). All rights reserved. |
| 7 | * "ACF" is a trademark of WP Engine. |
| 8 | * Licensed under the GNU General Public License v2 or later. |
| 9 | * https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Schema.org type and property data with lazy loading |
| 14 | * |
| 15 | * Data files in the /data directory are auto-generated by tools/generate-schema.js |
| 16 | * To regenerate data files, run: npm run generate-schema |
| 17 | * |
| 18 | * @package ACF\AI\GEO |
| 19 | */ |
| 20 | |
| 21 | namespace ACF\AI\GEO; |
| 22 | |
| 23 | /** |
| 24 | * Class SchemaData |
| 25 | * |
| 26 | * Contains static schema.org vocabulary data for type and property validation. |
| 27 | * Data is lazy-loaded from separate files to reduce memory usage when not needed. |
| 28 | */ |
| 29 | class SchemaData { |
| 30 | |
| 31 | /** |
| 32 | * Type hierarchy mapping (lazy-loaded) |
| 33 | * |
| 34 | * @var array|null |
| 35 | */ |
| 36 | private static $type_hierarchy = null; |
| 37 | |
| 38 | /** |
| 39 | * Property domain mappings (lazy-loaded) |
| 40 | * |
| 41 | * @var array|null |
| 42 | */ |
| 43 | private static $property_domains = null; |
| 44 | |
| 45 | /** |
| 46 | * Property range mappings (lazy-loaded) |
| 47 | * |
| 48 | * @var array|null |
| 49 | */ |
| 50 | private static $property_ranges = null; |
| 51 | |
| 52 | /** |
| 53 | * Compatible properties by output type (lazy-loaded) |
| 54 | * |
| 55 | * @var array|null |
| 56 | */ |
| 57 | private static $compatible_properties = null; |
| 58 | |
| 59 | /** |
| 60 | * Get the type hierarchy mapping |
| 61 | * |
| 62 | * Maps each type to its parent type in the schema.org hierarchy. |
| 63 | * For example: 'Recipe' => 'HowTo' |
| 64 | * |
| 65 | * @since 6.8.0 |
| 66 | * |
| 67 | * @return array |
| 68 | */ |
| 69 | public static function get_type_hierarchy(): array { |
| 70 | if ( self::$type_hierarchy === null ) { |
| 71 | self::$type_hierarchy = require __DIR__ . '/data/type-hierarchy.php'; |
| 72 | } |
| 73 | return self::$type_hierarchy; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get the property domain mappings |
| 78 | * |
| 79 | * Maps each property to the types it can be used with. |
| 80 | * For example: 'prepTime' => ['HowTo', 'HowToDirection'] |
| 81 | * |
| 82 | * @since 6.8.0 |
| 83 | * |
| 84 | * @return array |
| 85 | */ |
| 86 | public static function get_property_domains(): array { |
| 87 | if ( self::$property_domains === null ) { |
| 88 | self::$property_domains = require __DIR__ . '/data/property-domains.php'; |
| 89 | } |
| 90 | return self::$property_domains; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the property range mappings |
| 95 | * |
| 96 | * Maps each property to the types it expects as values. |
| 97 | * For example: 'author' => ['Person', 'Organization'] |
| 98 | * |
| 99 | * @since 6.8.0 |
| 100 | * |
| 101 | * @return array |
| 102 | */ |
| 103 | public static function get_property_ranges(): array { |
| 104 | if ( self::$property_ranges === null ) { |
| 105 | self::$property_ranges = require __DIR__ . '/data/property-ranges.php'; |
| 106 | } |
| 107 | return self::$property_ranges; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get compatible properties by output type |
| 112 | * |
| 113 | * Pre-computed mapping of output types to compatible properties. |
| 114 | * For example: 'Text' => ['name', 'description', ...] |
| 115 | * |
| 116 | * @since 6.8.0 |
| 117 | * |
| 118 | * @return array |
| 119 | */ |
| 120 | public static function get_compatible_properties(): array { |
| 121 | if ( self::$compatible_properties === null ) { |
| 122 | self::$compatible_properties = require __DIR__ . '/data/compatible-properties.php'; |
| 123 | } |
| 124 | return self::$compatible_properties; |
| 125 | } |
| 126 | } |
| 127 |