t1st3 / php-json-minify
Requires
- php: >=5.6.0
Requires (Dev)
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: 5.*
- sebastian/phpcpd: 2.*
This package is not auto-updated.
Last update: 2024-09-14 16:50:17 UTC
README
关于
这个用PHP编写的JSON压缩器基于JSON.minify脚本的PHP部分,由Kyle Simspon编写。该项目完全依赖于Kyle的工作:该项目基本上是将Kyle的脚本封装成一个类,并添加了一些花哨的功能,例如在Packagist上发布,以便与Composer一起使用,并使用PhpDocumentor生成文档。如果您想了解更多信息,请参阅原作者的博客文章。
此压缩器还会从JSON中删除注释。虽然《php-json-minify》和《JSON.minify》的作者不鼓励在JSON中使用注释,但他们很高兴提供一种删除这些注释的方法!
用法
<?php
require_once(dirname(__FILE__) . '/src/t1st3/JSONMin/JSONMin.php');
use t1st3\JSONMin\JSONMin as jsonMin;
// Use static method
$a = jsonMin::minify('{"a": "b"}');
echo $a;
// get the minified JSON in a string
$b = new jsonMin('{"c": "d"}');
echo $b->getMin();
// prints the minifed JSON
$c = new jsonMin('{"e": "f"}');
$b->printMin();
?>
构建依赖关系
为了从源代码构建您的生成Composer项目,您需要在命令行上安装Grunt和PHP。
因此,您必须在系统上安装PHP 5.6。在命令行上测试它
php --help
请注意,扩展ext-dom
是开发依赖项所必需的。在Debian/Ubuntu上,此扩展随常规PHP安装默认提供。在Fedora/CentOS上,您必须单独安装此扩展(yum install php-xml
)。
要全局安装Grunt到命令行(并运行上述构建任务),请运行
npm install -g grunt-cli
然后,使用Grunt,您可以安装Composer。只需运行一次
grunt init
然后,您可以本地安装require-dev
依赖项(PhpDocumentor、PhpUnit和PhpCPD)。只需运行一次
php composer.phar install -v
最后,您还应该安装名为Xdebug的PHP扩展,该扩展将由PhpUnit用于代码覆盖率。
构建源代码
一旦安装了所有依赖项,您就可以使用Grunt构建项目
grunt build
构建过程将运行以下任务
- PhpLint:在“src”文件夹上运行php -l
- 使用PHPUnit在“tests”文件夹中运行测试
- 从“src”文件夹的文件中在“doc”文件夹中生成PhpDocumentor文档
- 使用PhpCPD检测“src”文件夹中的代码复制/粘贴
鸣谢
php-json-minify是用generator-composer启动的,这是一个Yeoman生成器,用于构建PHP Composer项目。
该项目基于JSON.minify,由Kyle Simspon编写,并按MIT许可证发布。
该项目使用以下作为开发依赖项