定制 knplabs/media-exposer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 28.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 25
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 34
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2011-11-08