定制 jehoshua02/json-files 二次开发

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

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

jehoshua02/json-files

最新稳定版本:1.0.0

Composer 安装命令:

composer require jehoshua02/json-files

包简介

Helper classes for loading and iterating json files.

README 文档

README

Helper classes for loading and iterating json files.

Install

Use composer:

composer require jehoshua02/json-files

Usage

Given the following directory structure:

+ SomeClass.php
+ SomeClass.test.php
+ SomeClass.test.data/
|--+ someMethod/
|----+ simple.json
|----+ complex.json

Iterator

In SomeClass.test.php:

  1. Bring in the iterator with use.
  2. Return the iterator from data provider.
<?php

use \Stoutie\JsonFiles; /* [1] */

class SomeClassTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider someMethodDataProvider
     */
    public function testSomeMethod(/* ... args ... */)
    {
        /* ... test ... */
    }

    public function someMethodDataProvider()
    {
        return new JsonFiles\Iterator(__FILE__); /* [2] */
    }
}

The loader and iterator will replace .php on the end of the path with .data. This allows a very concise syntax of passing in __FILE__ and enables the convention of placing test data in SomeClass.test.data, which matches the name of the test file.

Although the primary use case the iterator was designed for was as a data provider in unit tests, other than the path replacement and data directory convention, it is otherwise generic and can be used to iterate on json files in any context.

Loader

<?php

$jsonLoader = new JsonFiles\Loader(__FILE__);
$data = $jsonLoader->load('someMethod/simple');

Again, by convention, .php at the end of path will be replaced with .data, but any path can be passed in and the loader is rather generic.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固