knplabs/media-exposer
Composer 安装命令:
composer require knplabs/media-exposer
包简介
A media path/source resolution library in PHP
README 文档
README
The Media Exposer is a PHP (5.3+) library that helps you expose your media files to the clients of your web application.
Principle
When you develop a web application, you always need to set up a strategy to serve your medias to the clients. This is the problem this library tries to help you solve.
The Exposer is the main entry point of the library. It is responsible for returning the right source or the right path for the given media and options. To do that, it iterates over the registered resolvers to find the first one supporting the given media and options. The source or path generation is delegated to it. So the first thing to do when you want to set up an exposer is to register resolvers. When you register a resolver, you give it a priority.
All resolvers implement the Resolver interface. They indicate if they support a given media and options. But this only interface is not sufficient so a proper resolver must also implement either the SourceResolver interface or the PathResolver (or both).
Quick Exemple
Enough discussion, let's try it.
As an exemple, will take the following simple image model:
<?php class FooImage { private $filename; public function getFilename() { return $this->filename; } }
Then, we create an associated resolver:
<?php use MediaExposer\PathResolver, MediaExposer\SourceResolver; class FooImageResolver implements PathResolver, SourceResolver { /** * {@inheritDoc} */ public function supports($media, array $options) { return $media instanceof FooImage; } /** * {@inheritDoc} */ public function getPath($media, array $options) { return '/path/to/the/images/directory/' . $media->getFilename(); } /** * {@inheritDoc} */ public function getSource($media, array $options) { return '/media/foo/' . $media->getFilename(); } /** * {@inheritDoc} */ public function getSourceType($media, array $options) { return SourceResolver::TYPE_RELATIVE; // or SourceResolver::TYPE_ABSOLUTE } }
Finally, you can register it in your exposer:
<?php use MediaExposer\Exposer; $exposer = new Exposer('http://the-host'); $exposer->addResolver(new FooImageResolver(), 10);
The first Exposer's argument is called $baseUrl. It's only required
if you want to generate absolute URLs with relative SourceResolver instances.
If so, it will be prepended to the relative source returned by the resolver
to turn it absolute.
knplabs/media-exposer 适用场景与选型建议
knplabs/media-exposer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.12k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2011 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「media」 「image」 「file」 「path」 「source」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 knplabs/media-exposer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 knplabs/media-exposer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 knplabs/media-exposer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Laravel Media Popup to upload/view the files
统计信息
- 总下载量: 28.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2011-11-08