cohensive/oembed
Composer 安装命令:
composer require cohensive/oembed
包简介
Media embed generation using OEmbed protocol.
README 文档
README
OEmbed
PHP library to retreive and display embed media from various media providers that support OEmbed data format. Websites such as YouTube, Vimeo, Twitter, Imgur and others.
This library also comes with support for direct mp4/video sources and some of the media providers that don't use OEmbed.
Installation
Library is written in PHP 8 with various neat features it gives, so apologies to everybody who wanted to use it in previous versions of PHP. If you do need similar library, I could recommend checking my previous package in this field: cohensive/embed.
Add following require to your composer.json file:
"cohensive/oembed": "dev-master"
// or
"cohensive/oembed": "^0.16"
Then run composer install or composer update to download it and autoload.
Or run:
$ composer require cohensive/oembed
If you're installing this library and want to utilize it with Laravel, package should automatically load its Service Provider.
If you plan to use OEmbed facade with Laravel, add Facade to your app.php config file in aliases section:
'aliases' => array(
//...
'OEmbed' => 'Cohensive\OEmbed\Facades\OEmbed'
//...
)
Usage
Standalone use:
// Use of factory will automatically load list of providers.
$factory = new \Cohensive\OEmbed\Factory();
$embed = $factory->get('http://youtu.be/uifYHNyH-jA');
if ($embed) {
// Print default embed html code.
echo $embed->html();
// Print embed html code with custom width. Works for IFRAME and VIDEO html embed code.
echo $embed->html(['width' => 600]);
// Checks if embed data contains details on thumbnail.
$embed->hasThumbnail();
// Returns embed "src" - URL string / array of strings / null for current embed.
// Accepts same options as "html" method.
$embed->src();
// Returns an array containing thumbnail details: url, width and height.
$embed->thumbnail();
// Returns an array containing all available embed data including default HTML code.
$embed->data();
}
Laravel use:
// Either use Facade:
$embed = OEmbed::get('http://youtu.be/uifYHNyH-jA');
// Load via Dependency Injection:
public function method(OEmbed $oembed) {
$embed = OEmbed::get('http://youtu.be/uifYHNyH-jA');
}
if ($embed) {
// Print default embed html code.
echo $embed->html();
// Print embed html code with custom width. Works for IFRAME and VIDEO html embed code.
echo $embed->html(['width' => 600]);
// Checks if embed data contains details on thumbnail.
$embed->hasThumbnail();
// Returns an array containing thumbnail details: url, width and height.
$embed->thumbnail();
// Return thumbnail url if it exists or null.
$embed->thumbnailUrl();
// Returns an array containing all available embed data including default HTML code.
$embed->data();
}
Config
Library comes with a big config file located in resources/ folder. That file contains an array where you can specify few things on a global basis and will you to pick which media providers you want to be used and which not.
Config file will be automatically loaded if you're using library with Laravel, which you can also publish and edit:
$ php artisan vendor:publish
If you're using OEmbed in standalone mode, you can add your own config file into Factory or OEmbed classes.
Important Changes
Config format changed to use snake_case array keys instead of previously used camelCase.
cohensive/oembed 适用场景与选型建议
cohensive/oembed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78.85k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2021 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oembed」 「media」 「youtube」 「vimeo」 「laravel」 「embed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cohensive/oembed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cohensive/oembed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cohensive/oembed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bundle with a way of defining oEmbed providers, and rendering oEmbed in templates.
Get detailed info for any URL on the internet! Scraper for HTML, OpenGraph, Schema data
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Extracts information about medias on the web, like youtube videos, twitter statuses or blog articles.
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
统计信息
- 总下载量: 78.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-01-10