Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Open Graph Bundle Laravel Package

novaway/open-graph-bundle

Novaway OpenGraphBundle is a Symfony bundle for adding Open Graph metadata to pages. It provides configuration and Twig helpers to define and render social sharing tags like title, description, image, and type, helping improve link previews on social platforms.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with composer require novaway/open-graph-bundle. Expect version friction: the last tagged release is 2019-10-22, so on Symfony 6/7 you will likely need --with-all-dependencies, a widened constraint, or a fork.
  • Register the bundle manually in config/bundles.php if Flex does not provide a recipe (it very likely does not):
return [
    // ...
    Novaway\OpenGraphBundle\NovawayOpenGraphBundle::class => ['all' => true],
];
  • The bundle's whole job is wiring the novaway/open-graph library into the container. Open these two files first — they are the source of truth, not the README:
    • vendor/novaway/open-graph-bundle/DependencyInjection/Configuration.php (actual config keys)
    • vendor/novaway/open-graph-bundle/Resources/config/services.xml (actual service IDs and aliases)
  • Minimal config in config/packages/novaway_open_graph.yaml — point it at a fetcher service (see Patterns). If the bundle requires a fetcher and none is set, the container will fail at compile time, so check the config tree first.
  • First use case: a controller/service that injects the library's OpenGraph (or its interface alias) and scrapes a URL:
use Novaway\OpenGraph\OpenGraphInterface;

public function preview(string $url, OpenGraphInterface $openGraph): JsonResponse
{
    $og = $openGraph->fetch($url); // method name: verify in vendor/novaway/open-graph/src

    return $this->json([
        'title'       => $og->getTitle(),
        'description' => $og->getDescription(),
        'image'       => $og->getImage(),
        'url'         => $og->getUrl(),
    ]);
}

Run bin/console debug:container novaway to confirm the exact service ID and whether autowiring is aliased before writing the first caller.

Implementation Patterns

Custom fetcher (recommended). The default cURL fetcher is thin. Implement the library's FetcherInterface with Guzzle/Symfony HttpClient so you get timeouts, redirect limits, and retries, then register it and reference it in config:

final class GuzzleFetcher implements FetcherInterface
{
    public function __construct(private HttpClientInterface $http) {}

    public function fetch(string $url): string
    {
        return $this->http->request('GET', $url, [
            'timeout' => 5,
            'max_redirects' => 3,
            'headers' => ['User-Agent' => 'MyApp/1.0 OpenGraph preview'],
        ])->getContent();
    }
}
# config/services.yaml
App\OpenGraph\GuzzleFetcher: ~
# config/packages/novaway_open_graph.yaml
novaway_open_graph:
    fetcher: App\OpenGraph\GuzzleFetcher

Caching decorator. Scraping is slow and remote; wrap the OpenGraph service with PSR-6 cache keyed by URL so repeated previews never leave the app:

final class CachedOpenGraph implements OpenGraphInterface
{
    public function __construct(
        private OpenGraphInterface $inner,
        private CacheItemPoolInterface $cache,
    ) {}
    // delegate fetch(), cache the returned value for e.g. 1 hour
}

Decorate instead of forking — the bundle exposes the interface, so services.yaml decoration works cleanly.

Async previews. For bulk imports (e.g. seeding a catalog from vendor URLs), dispatch a Messenger message per URL and do the fetch in a worker. A slow remote site should never block a form submit.

Form prefill pattern. The classic use case: a "paste product URL" field in an admin form, a small JSON endpoint that returns {title, image, description}, Alpine/Stimulus fills the fields, the user confirms and saves. Keep the fetch server-side to avoid CORS and to reuse your fetcher's SSRF guard.

Testing. In your app tests, mock OpenGraphInterface — never hit the network. For the library's own behavior, write a fake fetcher that returns fixture HTML containing <meta property="og:title" ...>.

Gotchas and Tips

  • Maintenance risk is the headline. 1 star, 0 dependents, last release 2019. Treat it as unmaintained glue code: pin the exact version, and budget for vendoring the ~200 lines of Bundle/DependencyInjection if you need Symfony 6+.
  • No Flex recipe (probably). Expect manual bundles.php registration and a hand-written config file. debug:config novaway_open_graph is the fastest way to learn the real schema.
  • SSRF is a real vulnerability here. The whole point is fetching arbitrary URLs server-side. Validate scheme is http/https, resolve the host and reject private/loopback/link-local ranges, cap redirects, and enforce a size limit on the response body.
  • OG tags are unreliable in the wild. Sites omit og:title, use name= instead of property=, or ship wrong values. Always fall back to <title>, <meta name="description">, and Twitter card tags before showing "no preview".
  • Encoding. Non-UTF-8 pages (legacy Windows-1252 sites) will produce mojibake or empty strings; wrap fetched HTML in mb_convert_encoding($html, 'UTF-8', $detected) before parsing.
  • Timeouts. The bundled cURL fetcher historically had no sane default timeout. If you keep it, a single dead URL hangs the request — another reason to supply your own fetcher.
  • Debugging. bin/console debug:container --show-private novaway lists the services; debug:autowiring OpenGraph tells you whether the interface alias exists. If autowiring fails, inject the concrete service ID explicitly.
  • Extension points. In order of usefulness: (1) custom fetcher service, (2) service decoration of the OpenGraph interface, (3) overriding the parser class in config if the bundle exposes it — check Configuration.php for a parser/class key.
  • Don't trust the README examples verbatim. Config key names and the fetch() vs parse() method differ across the library's history; always confirm against vendor/novaway/open-graph/src/.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core