PHPackages                             mitopp/schema-org-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mitopp/schema-org-bundle

ActiveSymfony-bundle

mitopp/schema-org-bundle
========================

A Builder for Schema.org Graph Types

v0.1.0(today)01↑2900%MITPHPPHP &gt;=8.2CI passing

Since Jul 28Pushed todayCompare

[ Source](https://github.com/mitopp/schema-org-bundle)[ Packagist](https://packagist.org/packages/mitopp/schema-org-bundle)[ RSS](/packages/mitopp-schema-org-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (2)Used By (0)

Schema.org Bundle for Symfony
=============================

[](#schemaorg-bundle-for-symfony)

[![CI Status](https://github.com/mitopp/schema-org-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/mitopp/schema-org-bundle/actions/workflows/ci.yml)

Warning

This Bundle is experimental and subject to change in a future release.

This Symfony bundle allows for easy generation and management of Schema.org data in the form of a JSON-LD graph. It provides a central collector service to gather structured data across different parts of your application (controllers, listeners, services) and output it collectively.

Features
--------

[](#features)

- Central collector for Schema.org objects.
- Twig extension for easy rendering of the JSON-LD graph.
- Support for nested objects and references via `@id`.
- Configurable output (e.g., Pretty Print).

Installation
------------

[](#installation)

Install the bundle via Composer:

```
composer require mitopp/schema-org-bundle
```

The bundle should be automatically activated by Symfony Flex. If not, add it manually to your `config/bundles.php`:

```
return [
    // ...
    Mitopp\SchemaOrgBundle\MitoppSchemaOrgBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

You can customize the bundle's behavior in a configuration file (e.g., `config/packages/mitopp_schema_org.yaml`):

```
mitopp_schema_org:
    # Enables or disables formatted JSON output (default: true)
    pretty_print: true
    # Optional: Default locale for objects (default: 'de')
    default_locale: 'en'
    # Optional: Prefix for generated identifiers (default: null, falls back to base URL)
    id_prefix: 'https://example.com'
```

Usage
-----

[](#usage)

### In the Controller

[](#in-the-controller)

You can inject the `SchemaOrgGraphCollectorInterface` directly into your controller to add data:

```
namespace App\Controller;

use Mitopp\SchemaOrgBundle\Config\SchemaOrgConfigurationInterface;
use Mitopp\SchemaOrgBundle\Graph\SchemaOrgGraphCollectorInterface;
use Mitopp\SchemaOrgBundle\Type\Thing\Organization;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
    #[Route('/', name: 'app_home')]
    public function index(SchemaOrgGraphCollectorInterface $collector, SchemaOrgConfigurationInterface $configuration): Response
    {
        $org = new Organization(
            identifier: $configuration->createIdentifier('#org'),
            name: 'My Company',
            url: $configuration->getBaseUrl(),
            logo: $configuration->createIdentifier('/logo.png'),
        );

        $collector->add($org);

        return $this->render('home/index.html.twig');
    }
}
```

### Via Event Listener

[](#via-event-listener)

It is often useful to add global data (such as organization or website search) centrally via a listener:

```
namespace App\EventListener;

use Mitopp\SchemaOrgBundle\Config\SchemaOrgConfigurationInterface;
use Mitopp\SchemaOrgBundle\Graph\SchemaOrgGraphCollectorInterface;
use Mitopp\SchemaOrgBundle\Type\Thing\CreativeWork\WebSite;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

#[AsEventListener(event: KernelEvents::REQUEST, method: 'onKernelRequest')]
final class SchemaOrgListener
{
    public function __construct(
        private readonly SchemaOrgGraphCollectorInterface $collector,
        private readonly SchemaOrgConfigurationInterface $configuration,
    ) {
    }

    public function onKernelRequest(RequestEvent $event): void
    {
        if (!$event->isMainRequest()) {
            return;
        }

        $website = new WebSite(
            identifier: $this->configuration->createIdentifier('#website'),
            url: $this->configuration->getBaseUrl(),
            name: 'Example Website',
        );

        $this->collector->add($website);
    }
}
```

### Output in Twig

[](#output-in-twig)

To output the collected data in your HTML header, use the provided Twig function in your base template (e.g., `base.html.twig`):

```

        {% block title %}Welcome!{% endblock %}

        {# Renders the entire Schema.org graph as a JSON-LD script tag #}
        {{ render_schema_org() }}

        {% block stylesheets %}{% endblock %}

        {% block body %}{% endblock %}

```

Supported Types
---------------

[](#supported-types)

The bundle currently includes several common Schema.org types. For detailed examples and usage instructions, please refer to our [documentation](docs/index.md).

- `Organization`
- `Person`
- `WebSite`
- `WebPage` (including `CollectionPage` and `ContactPage`)
- `Article` &amp; `BlogPosting`
- `Recipe` (including `AggregateRating`, `Review`, `Comment`)
- `HowToStep`
- `ImageObject`
- `AggregateRating`
- `Review`
- `Comment`

Creating Custom Types
---------------------

[](#creating-custom-types)

The bundle already offers some common types. However, you can create your own types at any time by inheriting from `AbstractType`:

```
namespace App\Schema\Type;

use Mitopp\SchemaOrgBundle\Type\AbstractType;

class MyCustomType extends AbstractType
{
    public function __construct(string $identifier)
    {
        parent::__construct('MyCustomType', $identifier);
    }

    public function setCustomProperty(string $value): self
    {
        $this->data['customProperty'] = $value;
        return $this;
    }
}
```

License
-------

[](#license)

This bundle is licensed under the MIT License.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cbe4e1bd0cadd57bbc477b5339cf9ae196afe01467cdd17f78b6f3eaad41c6fb?d=identicon)[mitopp](/maintainers/mitopp)

---

Top Contributors

[![mitopp](https://avatars.githubusercontent.com/u/5371265?v=4)](https://github.com/mitopp "mitopp (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mitopp-schema-org-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/mitopp-schema-org-bundle/health.svg)](https://phpackages.com/packages/mitopp-schema-org-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M402](/packages/easycorp-easyadmin-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
