designcise / manifest-json
PHP 的 manifest.json 解析器/加载器
v3.1.0
2024-01-21 06:49 UTC
Requires
- php: >=8.0
- ext-json: *
Requires (Dev)
- phpmd/phpmd: @stable
- phpstan/phpstan: *
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-09-21 08:09:18 UTC
README
PHP manifest.json
解析器/加载器。
安装
composer require designcise/manifest-json
注意
需要 PHP 8.0 或更高版本。
示例
use Designcise\ManifestJson\ManifestJson; $manifest = new ManifestJson('path/to/manifest/'); // defaults to `manifest.json` // or $manifest = new ManifestJson('path/to/manifest/my-manifest.json'); $entry = $manifest->get('entry.js'); $metadata = $manifest->getAll(); $css = $manifest->getAllByType('css'); $images = $manifest->getAllByTypes(['jpg', 'png']); $js = $manifest->getAllByKey('*.js'); $criticalJs = $manifest->getAllByKeyBasename('critical-*.js');
API
静态方法 from(string $dirOrFile): self
静态方法,用于从指定的目录加载 manifest.json
文件。如果只指定了目录,则默认假设文件名为 manifest.json
,否则使用指定的名称。例如
ManifestJson::from('path/to/manifest/'); // defaults to `manifest.json` ManifestJson::from('path/to/manifest/my-manifest.json');
get(string $key): string
获取指定 $key
的 manifest.json
元数据。
getAll(): array
以数组形式获取 manifest.json
文件中的所有条目。
getAllByType(string $type): array
获取所有具有指定文件扩展名(例如 css
、js
等)的文件作为数组。
getAllByTypes(array $types): array
获取所有具有指定文件扩展名(例如 ['css', 'js']
等)的文件作为数组。
getAllByKey(string $key): array
获取所有匹配指定键的文件。它会在清单条目的键中查找完全匹配。它可以使用星号(例如 *.js
、*index*
等)作为可选通配符。
getAllByKeyBasename(string $key): array
获取所有匹配清单条目键中路径尾部名称组件的文件。它可以使用星号(例如 *.js
、index*
等)作为可选通配符。
测试
要运行测试,可以使用以下命令
贡献
- 在 https://github.com/designcise/manifest-json/issues 上提交问题
- 向 https://github.com/designcise/manifest-json/pulls 提交补丁
许可
有关许可信息,请参阅 许可文件。