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