snordian/h5p-extractor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

snordian/h5p-extractor

Composer 安装命令:

composer require snordian/h5p-extractor

包简介

Allows to create H5P content HTML server-side

关键字:

README 文档

README

Tool that is supposed to be be usable for rendering H5P content server-side.

Quick start (to be done properly (!))

  1. Copy the library to your ow project. You can also use composer, but you will need to fetch the library from github, because it is not available via packagist (yet).

    Your composer.json file should contain

    "repositories": [
         {
             "type": "vcs",
             "url": "https://github.com/otacke/H5PExtractor"
         }
     ],
     "require": {
         "snordian/h5p-extractor": "dev-master"
    }
    

    and any other of your dependencies, of course.

  2. Use require_once <path_to_h5p-extractor> . '/app/H5PExtractor.php'; to load code. It does autload everything it needs, but it is not instantiated by any autoload itself, because it it seems appropriate to only load H5PExtractor once actually needed.

  3. Use $h5pExtractor = new H5PExtractor\H5PExtractor($config); to create an instance, where $config is supposed to be an optional an associative array containing configuration items, e.g.:

    $config = [
      'uploadsPath' => <path to be used for uploads relative to h5p-extractor : string>
      'renderWidth' => <the assumed viewport width : number, default: 1024>
      'renderWidths' => [
       '<machineName: string>' => <the assumed viewport width : number>,
      ]
      'target' => <specific target as option : ['print|screen'], default: 'print'>
      'scope' => <specific scope as option : ['all|initial'], default: 'all'>
      'customCssPre' => <custom CSS to be applied before H5P core/content CSS is set : string>
      'customCssPost' => <custom CSS to be applied after H5P core/content CSS is set : string>
      'h5pCoreUrl' => <full URL to `h5p-php-library/` folder to use as core asset source : string>
      'h5pLibrariesUrl' => <full URL to `libraries/` folder to use as content type asset source : string>
      'h5pContentUrl' => <full URL to `content/<id>/` folder to use author defined content as source>
      'solutionStyle' => <how to format the solution : ['reversed'], default: null>
    ]
    

    By default, if that value is not set or no $config argument is passed, H5PExtractor will

    • try to create/use a directory named uploads inside its main h5p-extractor directory,
    • use a default render width of 1024 pixels,
    • use the default or set render width if no machineName specific render width was set for a particular content type,
    • not apply and custom CSS,
    • return base64 encoded representations of files inside the file if no Url to core, libraries or the content is set,
    • return solutions unmodified if no solutionStyle is set.

    Please ensure that the respective uploads directory can be read and written by your server process.

  4. Use something like

    $extract = $h5pExtractor->extract(
        [
            'file' => $file['tmp_name'],
            'format' => $_POST['format']
        ]
    );
    

    where

    • file is supposed to be the H5P file that contains the H5P content that is supposed to be rendered - here a standard temporary file generated by a form upload.
    • format specifies the desired output format (currently html (default) or text) - here the format key of the form upload.

    The return value is an associative array with the key result or error.

    • result contains the requested output format
    • error contains an error message if something went wrong.

Creating/changing generators

A generator is what creates a distinct output format from an H5P content. It will commonly be HTML or some plain text variant, but could be something different, too.

The generation process resembles how the H5P core composes H5P content from different content types, and methods such as newRunnable or attach were called that way because they have direct counterparts in H5P core/a content type. They also use the same arguments, even though they're not all required here. If you know newRunnable or attach, then you already know what they do here. And if you don't and learn what they do here, you learn something about H5P core and H5P content types as a side product :-)

TODO: Explain Structure

TODO: Explain Generator

TODO: Explain GeneratorInterface

Open issues:

  • Implement handling of target and scope where needed
  • Add option to display answers for questions
  • Support H5P theming scheduled to be released late in 2025.

snordian/h5p-extractor 适用场景与选型建议

snordian/h5p-extractor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.34k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 snordian/h5p-extractor 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-26