tenolo/open-graph-bundle
Composer 安装命令:
composer require tenolo/open-graph-bundle
包简介
A Symfony OpenGraph bundle
README 文档
README
OpenGraphBundle
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.
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, anNotSupportedexception will be thrown.
Another Note: Credits and inspiration goes to tgalopin
just saying ;)
tenolo/open-graph-bundle 适用场景与选型建议
tenolo/open-graph-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.12k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「graph」 「opengraph」 「og」 「open」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tenolo/open-graph-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tenolo/open-graph-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tenolo/open-graph-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Netgen Open Graph Bundle is an Ibexa Platform bundle that allows simple integration with Open Graph protocol.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
统计信息
- 总下载量: 6.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-16