v2.6 The Schema Generator

schema is a command line tool part of the API Platform framework that instantly generates a set of PHP classes from RDF vocabularies such as (but not limited to) Schema.org or ActivityStreams.

Find and browse (or create) a vocabulary that fits your needs, choose the types and properties you need, run our code generator and you’re done! You get a fully featured PHP data model including:

  • A set of PHP entities with properties, constants (enum values), getters, setters, adders and removers. The class hierarchy provided by the vocabulary will be translated to a PHP class hierarchy with parents as abstract classes. The generated code complies with PSR coding standards ;
  • Full, high-quality PHPDoc for classes, properties, constants and methods extracted from the vocabulary ;
  • Doctrine ORM annotation mapping including database columns with type guessing, relations with cardinality guessing, class inheritance (through the @AbstractSuperclass annotation) ;
  • Data validation through Symfony Validator annotations including data type validation, enum support (choices) and check for required properties ;
  • API Platform Core annotations ;
  • Interfaces and Doctrine ResolveTargetEntityListener support ;
  • Custom PHP namespace support ;
  • List of values provided the vocabulary with PHP Enum classes.

Bonus:

  • The code generator is fully configurable and extendable. All features can be deactivated (e.g., the Doctrine mapping generator) and a custom generator can be added (e.g., a Doctrine ODM mapping generator) ;
  • The generated code can be used as is in a Symfony app (but it will work too in a raw PHP project or any other framework including Laravel and Zend Framework).

# What Is Schema.org?

Schema.org is a vocabulary representing common data structures and their relations. Schema.org can be exposed as JSON-LD, microdata and RDFa. Extracting semantical data exposed in the Schema.org vocabulary is supported by a growing number of companies including Google (Search, Gmail), Yahoo!, Bing and Yandex.

# Why Use Schema.org Data to Generate a PHP Model?

# Don’t Reinvent the Wheel

Data models provided by Schema.org are popular and were proven efficient. They cover a broad spectrum of topics including creative works, e-commerce, events, medicine, social networking, people, postal addresses, organization data, places or reviews. Schema.org has its root in a ton of preexisting well designed vocabularies and is successfully used by more and more websites and applications.

Pick schemas applicable to your application, generate your PHP model, then customize and specialize it to fit your needs.

# Improve SEO and User Experience

Adding Schema.org markup to websites and apps increases their ranking in search engines results and enables awesome features such as Google Rich Snippets and Gmail markup.

Mapping your app data model to Schema.org structures can be tedious. When using the generator, your data model will be derived from Schema.org. Adding microdata markup to your templates or serializing your data as JSON-LD will not require specific mapping nor adaptation. It’s a matter of minutes.

# Be Ready for The Future

Schema.org improves the interoperability of your applications. Used with hypermedia technologies such as Hydra it’s a big step towards the semantic and machine readable web. It opens the way to generic web API clients able to extract and process data from any website or app using such technologies.

# Documentation

You can also help us improve the documentation of this page.

Made with love by

Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.

Learn more

Copyright © 2023 Kévin Dunglas

Sponsored by Les-Tilleuls.coop