joshuaadickerson / scene7
Adobe Scene7 PHP SDK
dev-master
2021-06-16 15:24 UTC
Requires
- php: >=5.6
Requires (Dev)
- apigen/apigen: 4.2.0.x-dev
- phpunit/phpunit: 5.5.*
This package is not auto-updated.
Last update: 2024-09-29 01:40:41 UTC
README
一个用于创建Adobe Scene7 HTTP协议请求字符串的库。
安装
安装此库的最简单方法是使用Composer composer require joshuaadickerson/scene7
由于我还未准备好将其称为稳定版本,因此尚无版本。
最低PHP版本是5.6。
工厂
应使用工厂来创建新的请求和图层。
// See "Factory Defaults Callback" $factory = new Scene7\Factory('https://www.example.com', $callback); $image = $factory->newImage('myProductImage'); echo $image->render(); // Output: // https://www.example.com/myProductImage?defaultImage=MyDefaultImage&id=42
所有请求和辅助函数也实现了 __toString(),因此您无需直接调用render()。
工厂默认值回调
我决定不尝试使用数组、对象或其他方式实现默认值设置器,而是使用回调。这允许您比其他方法做更多的事情。
$callback = function (AbstractRequest $request) { // Apply defaults based on the request type switch ($request->getRequestType()) { case 'img': $request ->setDefaultImage('MyDefaultImage') ->setId(rand(0, 100)); break; } }
您还可以像设置图层默认值一样设置。它们仅在你添加新图层时应用。
辅助函数
图片
您可以通过嵌套 <source>
和 <img>
标签快速创建图片标签。
创建图片标签的最简单方法是使用 Picture::addSourceListFromImage()
。
示例
$picture = new Scene7\Helpers\Html\Picture; $image = new Scene7\Requests\Image('https://example.com/', 'myProduct'); $queries = [ // The key is the media query // The value is an array of k/v pairs where the key is the HTML attribute you want to set '(min-width: 1000px)' => [ // Width and height get multiplied based on $multipliers (see below) 'width' => 500, 'height' => 500, ], '(min-width: 500px)' => [ 'width' => 250, 'height' => 250, ], ]; $picture->addSourceListFromImage($queries, $image, [2, 1])->setImage($image); echo $picture->render(); // Output: // <picture><source media="(min-width: 1000px)" srcset="https://example.com/myProduct?wid=1000&hei=1000 2x,https://example.com/myProduct?wid=500&hei=500 1x,"><source media="(min-width: 500px)" srcset="https://example.com/myProduct?wid=500&hei=500 2x,https://example.com/myProduct?wid=250&hei=250 1x,"><img src="https://example.com/myProduct?" alt=""></picture>
贡献
这个库是维护的。我不想给人留下它不被维护的印象。我计划对它做一些事情,并且我在工作中使用它。我开源这个库的一个主要原因是我不需要做所有的工作。
请随意提交pull请求。请在PR中添加测试,以便我可以更快地合并。
如果您有功能请求或问题,我将其视为贡献并欢迎。
待办事项
- 实现所有请求类型
- 测试所有内容
- 确定“src”命令文档
- 实现遮罩
- 添加更多如音频和视频等辅助函数
- 文档
- 示例
- 修复模糊查询
- 添加Travis CI配置
- 在此README中添加一些酷炫的功能,以展示其是否成功构建以及测试覆盖率
许可证
此作品根据BSD-3条款许可证授权
与Adobe的关系
Adobe和Scene7是Adobe Systems Incorporated的商标。此软件包与它们没有关联。我希望能有Adobe承担起维护此软件包并作为官方版本分发的责任,但目前并非如此。这不是官方包。