Download the PHP package beastbytes/schema-dot-org-helper without Composer
On this page you can find all versions of the php package beastbytes/schema-dot-org-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beastbytes/schema-dot-org-helper
More information about beastbytes/schema-dot-org-helper
Files in beastbytes/schema-dot-org-helper
Package schema-dot-org-helper
Short Description A helper for generating Schema.org JSON-LD
License
Informations about the package schema-dot-org-helper
Schema.org Helper (schema-dot-org-helper)
A Helper for generating Schema.org schemas in JSON-LD.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Usage
To generate a schema:
The generated schema can be rendered directly
or registered with the view:
Defining a Schema Mapping
A schema mapping is an array that defines the mapping of model properties to Schema.org properties; it is of the form:
Where a Schema.org property is defined as a Schema.org type, the type is a nested array:
If a Schema.org property is to be a string literal, prepend with SchemaDotOrg::STRING_LITERAL :
If a Schema.org property is a SchemaDotOrg Enumeration value, prepend with SchemaDotOrg::ENUMERATION :
If a Schema.org property is an array of values - usually nested types - specify the mapping as an array. The key must be or start with SchemaDotOrg::ARRAY. If it is just SchemaDotOrg::ARRAY the mapping parent key is the model property, else the model property is the remainder of the key; both forms are shown below:
Example schema mapping definition:
Example JSON-LD generated using the above schema mapping:
Twig Templates
To use the helper in a Twig templates either include it in CommonViewInjection (in the examples it is assigned to the schemaDotOrg variable) or in the template
Then in the template either:
to echo the schema immediately:
or to register the schema with the view:
Defining the Mapping
- In Twig templates the mapping must define both the SchemaDotOrg property and the model property, even if they have the same name.
- To use the SchemaDotOrg class constants use Twig's constant() function and concatenate the string
For example:
Testing
All testing is carried out from the root directory.
Unit testing
The package is tested with PHPUnit. To run tests: composer test
Mutation testing
The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it: composer infection
Static analysis
The code is statically analyzed with Psalm. To run static analysis: composer psalm
License
The Schema.org Helper is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.
All versions of schema-dot-org-helper with dependencies
yiisoft/arrays Version ^3.0
yiisoft/event-dispatcher Version ^1.0
yiisoft/html Version ^3.0
yiisoft/json Version ^1.0
ext-json Version *