Download the PHP package secit-pl/json-ld-bundle without Composer
On this page you can find all versions of the php package secit-pl/json-ld-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download secit-pl/json-ld-bundle
More information about secit-pl/json-ld-bundle
Files in secit-pl/json-ld-bundle
Package json-ld-bundle
Short Description Schema.org JSON-LD generator Symfony Bundle.
License MIT
Homepage http://secit.pl
Informations about the package json-ld-bundle
Schema.org JSON-LD Symfony Bundle
Schema.org JSON-LD generator for the Symfony 2.8 and 3.0+.
PHP 7 support
As of release 3.3.2 of the https://github.com/secit-pl/schema-org all types and properties should be suffixed. This bundle allows using both class versions (the new suffixed classes and the deprecated non suffixed), but be aware that only suffixed classes will work properly on the PHP 7.
Another reason for moving to the new class naming schema is the fact that all non suffixed classes will be removed in the release 3.4 of the secit-pl/schema-org.
Installation
From the command line run
Update your AppKernel by adding the bundle declaration
Usage
Basic Usage
First of all you need to create a Transformer which will transform your object to schema.org data mapping.
As the basis for this of this bundle is the https://github.com/secit-pl/schema-org so the transformer should return the object accepted by the JSON-LD Generator.
Next you need to register the transformer as service using the secit.jsonld_transformer tag in your services.yml.
If you want to assign more than one class to the same transformer you can add multiple tags to the same service.
From now you can transform the specified in the tag class attribute object (in the following example the \Test\TestBundle\Classes\ClassToBeTransformedToJsonLd) to the JSON-LD as following:
The output should be something like this:
Advanced usage
In many situations it's required to have a nested transformers to not implement whole logic in the single class. To use nested transformers your Transformer should implement JsonLdAwareInterface. If you don't want to implement the interface methods by your own you can use the JsonLdAwareTrait.
Here is the simple example of how to use it:
PersonTransformer.php
ArticleTransformer.php
Example input object:
The output:
Twig Support
This bundle also provides the Twig extension which allows to render JSON-LD directly from the Twig templates.
TestController:
example.html.twig:
The output:
All versions of json-ld-bundle with dependencies
symfony/framework-bundle Version ~2.8|~3.0
symfony/dependency-injection Version ~2.8|~3.0
secit-pl/schema-org Version ^3.3.2