承接 ylly/open-graph-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ylly/open-graph-bundle

Composer 安装命令:

composer require ylly/open-graph-bundle

包简介

A Symfony OpenGraph bundle

README 文档

README

The TenoloOpenGraphBundle is a simple way to improve how you manage OpenGraph into your Symfony2 application.

Note: OpenGraph is a standard protocol used by many websites (Facebook, Twitter, Google, ...) to obtain more precise informations about your content.

Learn more about OpenGraph

The idea of this bundle it to associate each entity of your app with an OpenGraph map, a service able to create the OpenGraph document for your entity.

It also works with any other type of data.

Installation

Installation is very quick:

1. Download it with Composer

Add the bundle to your composer.json file by running:

composer require tenolo/open-graph-bundle

2. Enable it in your kernel

Enable the bundle in your app/AppKernel.php file;

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Tenolo\Bundle\OpenGraphBundle\TenoloOpenGraphBundle(),
    );
}

Usage

The TenoloOpenGraphBundle will associate:

  • Entities of your application with ...
  • ... or Other Data like an array of your application with ...
  • OpenGrap maps, definitions of these entities in an OpenGraph way

Let's take an example for a better understanding: a blog post.

Your entity

For a blog post, you could have an entity like this one:

<?php

namespace Acme\DemoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table()
 * @ORM\Entity
 */
class BlogPost
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $title;

    /**
     * @ORM\Column(type="text")
     */
    private $content;
}

Its OpenGraph map

The map associated with your entity will be a class implementing Tenolo\Bundle\OpenGraphBundle\Map\OpenGraphMapInterface and the two required methods of this interface : map(DocumentWriterInterface $document, $data) and supports($data).

For instance, our map could look like this :

<?php

namespace Acme\DemoBundle\OpenGraph;

use Acme\DemoBundle\Entity\BlogPost;
use Tenolo\Bundle\OpenGraphBundle\OpenGraph\DocumentWriterInterface;
use Tenolo\Bundle\OpenGraphBundle\Map\OpenGraphMapInterface;
use Opengraph\Opengraph;

class BlogPostMap implements OpenGraphMapInterface
{

    /**
     * @inheritdoc
     * @var BlogPost $data
     */
    public function map(DocumentWriterInterface $document, $data)
    {
        $document->append(OpenGraph::OG_SITE_NAME, 'MyBlog');
        $document->append(OpenGraph::OG_TYPE, OpenGraph::TYPE_ARTICLE);
        $document->append(OpenGraph::OG_TITLE, $data->getTitle());
    }

    /**
     * @inheritdoc
     */
    public function supports($data)
    {
        return $entity instanceof BlogPost;
    }
}

The supports method declares with what kind of entities this map is able to deal. The map method create an OpenGraph document representing the given entity.

Once created, we still have to register our class into the OpenGraph manager. To do so, we will have to use the tag tenolo_open_graph.map:

services:
    acme_demo.open_graph.blog_post_map:
        class: Acme\DemoBundle\OpenGraph\BlogPostMap
        tags:
            - { name: tenolo_open_graph.map }

Using the map

Our map is registered, so we can use it anywhere we want to render it. For instance, with Twig:

<html>
    <head>
        <title>Blog post</title>

        {{ opengraph_render(blogPost) }} <!-- blogPost should be an instance of BlogPost -->
    </head>
    <body>
        ...
    </body>
</html>

Note: if no map is able to deal with the entity given in opengraph_render, an NotSupported exception will be thrown.

Another Note: Credits and inspiration goes to tgalopin

just saying ;)

ylly/open-graph-bundle 适用场景与选型建议

ylly/open-graph-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 116 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「graph」 「opengraph」 「og」 「open」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ylly/open-graph-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ylly/open-graph-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 ylly/open-graph-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 116
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-07