tohyo/open-graph-bundle

Symfony 扩展包,用于获取 open graph 数据

安装: 29

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2023-06-14 18:49 UTC

This package is auto-updated.

Last update: 2024-09-15 21:17:45 UTC


README

描述

此扩展包提供了一种简单服务,它接受一个 URL 并返回一个包含该 URL 的 open graph 数据的对象/

要求

此扩展包适用于 php 8.2

安装

请确保已全局安装 Composer,如 Composer 文档中的安装章节所述。

使用 Symfony Flex 的应用程序

打开命令行,进入您的项目目录,然后执行

$ composer require tohyo/open-graph-bundle

不使用 Symfony Flex 的应用程序

步骤 1:下载扩展包

打开命令行,进入您的项目目录,并执行以下命令以下载此扩展包的最新稳定版本

$ composer require tohyo/open-graph-bundle

步骤 2:启用扩展包

然后,通过将其添加到项目 config/bundles.php 文件中注册的扩展包列表中来启用扩展包

// config/bundles.php

return [
    Tohyo\OpenGraphBundle\TohyoOpenGraphBundle::class => ['all' => true],
];

用法

示例

以下是一个如何使用此服务的示例

public function index(OpenGraph $openGraph): Response
{
    dd($openGraph->getData('https://symfony.com.cn'));
}

此调用将返回此类对象

Tohyo\OpenGraphBundle\Dto\OpenGraphData {#12498 ▼
  +title: "Symfony, High Performance PHP Framework for Web Development"
  +url: null
  +type: "website"
  +image: Tohyo\OpenGraphBundle\Dto\OpenGraphImageData {#13207 ▶
    +url: "https://symfony.com.cn/images/opengraph/symfony.png"
    +secureUrl: null
    +type: null
    +width: ""
    +height: ""
    +alt: ""
  }
  +video: Tohyo\OpenGraphBundle\Dto\OpenGraphVideoData {#12615 ▶
    +url: null
    +secureUrl: null
    +type: null
    +width: ""
    +height: ""
    +alt: ""
  }
  +audio: Tohyo\OpenGraphBundle\Dto\OpenGraphAudioData {#12534 ▶
    +url: null
    +secureUrl: null
    +type: null
  }
  +description: "Symfony is a set of reusable PHP components and a PHP framework to build web applications, APIs, microservices and web services."
  +locale: null
  +determiner: null
  +siteName: null
}

选项

默认情况下返回的数据未进行验证,您可以通过配置参数来激活验证

tohyo_open_graph:
    validate_graph_data: true

当此参数激活时,未通过验证的属性将设置为 null