1. Go to this page and download the library: Download survos/schema-org-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/ */
survos / schema-org-bundle example snippets
use Spatie\SchemaOrg\Schema;
use Survos\SchemaOrgBundle\Graph\SchemaOrgGraph;
final class MovieController extends AbstractController
{
public function show(Movie $movie, SchemaOrgGraph $schemaOrg): Response
{
$schemaOrg->add(
Schema::movie()
->identifier($this->generateUrl('movie_show', ['id' => $movie->getId()], UrlGeneratorInterface::ABSOLUTE_URL) . '#movie')
->name($movie->getTitle())
->director(Schema::person()->identifier('https://example.com/people/kubrick#person')->name('Stanley Kubrick')),
);
return $this->render('movie/show.html.twig', ['movie' => $movie]);
}
}
use Survos\SchemaOrgBundle\Graph\SchemaOrgAwareTrait;
final class MovieController extends AbstractController
{
use SchemaOrgAwareTrait; // public SchemaOrgGraph $schemaOrg, via #[Required]
}
use Survos\SchemaOrgBundle\Attribute\SchemaOrg;
use Survos\SchemaOrgBundle\Attribute\SchemaProperty;
#[SchemaOrg('Movie')]
final class Movie
{
#[SchemaProperty('name')] public ?string $title = null;
#[SchemaProperty('description')] public ?string $overview = null;
#[SchemaProperty('dateCreated')] public ?int $year = null;
#[SchemaProperty('genre')] public ?array $genres = null;
// The column holds a name, not a Person — wrap it, and give the wrapped node
// an @id so the same person is one node however many times they appear.
#[SchemaProperty('director', as: 'Person', idPattern: '{base}/people/{value}')]
public ?string $director = null;
#[SchemaProperty('actor', as: 'Person', idPattern: '{base}/people/{value}')]
public ?array $actors = null;
}