1. Go to this page and download the library: Download secit-pl/json-ld-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
secit-pl / json-ld-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...
new SecIT\JsonLdBundle\JsonLdBundle(),
];
...
}
}
namespace Test\TestBundle\JsonLd;
use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\ThingType;
class TestTransformer implements TransformerInterface
{
public function transform($object)
{
return (new ThingType())
->setName(new NameProperty(
new TextType($object->getName())
));
}
}
$object = new \Test\TestBundle\Classes\ClassToBeTransformedToJsonLd();
$object->setName('Some name');
echo $this->getContainer()->get('secit.json_ld')->generate($object);
namespace Test\TestBundle\JsonLd;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareInterface;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareTrait;
use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\PersonType;
class PersonTransformer implements TransformerInterface
{
public function transform($person)
{
return (new PersonType())
->setName(new NameProperty(
new TextType($person->name)
));
}
}
namespace Test\TestBundle\JsonLd;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareInterface;
use SecIT\JsonLdBundle\DependencyInjection\JsonLdAwareTrait;
use SecIT\JsonLdBundle\Transformer\TransformerInterface;
use SecIT\SchemaOrg\Mapping\DataType\TextType;
use SecIT\SchemaOrg\Mapping\Property\AuthorProperty;
use SecIT\SchemaOrg\Mapping\Property\NameProperty;
use SecIT\SchemaOrg\Mapping\Type\ArticleType;
class ArticleTransformer implements TransformerInterface, JsonLdAwareInterface
{
use JsonLdAwareTrait;
public function transform($article)
{
return (new ArticleType())
->setName(new NameProperty(
new TextType($article->name)
))
->setAuthor(new AuthorProperty(
$this->getJsonLd()->transform($article->author)
));
}
}
$author = new Person();
$author->name = 'Jon Smith';
$article = new Article();
$article->name = 'Example article';
$article->author = $author;
namespace Test\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class TestController extends Controller
{
public function testAction()
{
return $this->render('TestBundle:Test:example.html.twig', [
'object' => new Foo(),
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.