定制 sparkapi/feed-faker 二次开发

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

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

sparkapi/feed-faker

Composer 安装命令:

composer require sparkapi/feed-faker

包简介

A fake datasource using RESO standard fields

README 文档

README

Latest Version Software License Build Status Total Downloads

FeedFaker allows you to generate a ton of fake RESO-compliant feed data objects quickly and easily, in a way that will keep the IDs at least semi-referentially linked for imports into databases.

Docker Quick Start

$ docker run -d -p 8080:80 sparkapi/faker-wrapper

$ curl http://localhost:8080/property
[{"ListingKey":"20170428170051261516000000","ListingId":"201704281...

# Hooray!

List of Faker Endpoints in the Docker Image

Install via Composer

$ composer require sparkapi/feed-faker

(or)

{
    "require": {
        "sparkapi/feed-faker": "^0.8"
    }
}

Example Usage

First define your settings for keys and the number and type of objects to create.

If you are using the unsplash photo provider you will have to pass in a few additional settings. If you want to use a different image provider, pass in the class to that provider.

All other settings have defaults, so feel free to modify what you want and leave blank the rest.

$settings = [
    // required for photo providers
    'unsplash_app_id' => 'your_unsplash_app_id', // unsplash specific
    'interior_collection' => collection_id, // unsplash collection or filesystem path if using local photo provider
    'exterior_collection' => collection_id, // unsplash collection or filesystem path if using local photo provider
    'portrait_collection' => collection_id, // unsplash collection or filesystem path if using local photo provider
        
    // Optional photo provider, if not using unsplash (you can ignore the above, too).
    'photo_provider' => \FeedFaker\Helper\UnsplashPhotoProvider::class,

    // Basic settings, all with defaults.
    'mls_id' => 'my-awesome-mls',
    
    // the number of objects you want to create for each resource type.
    'office_count' => 50,
    'member_count' => 150,
    'property_count' => 500,
    'openhouse_count' => 1000,
    'history_count' => 1000,
    'media_count' => 5000,
];

You may provide a valid full path to a php settings file that returns an array, if you prefer. An example is in settings.php.dist.

Now that you're all setup, instantiate it and fire away:

$settings = [
    'unsplash_app_id' => 'my-app-id-from-unsplash'
    'interior_collection' => 10
    'exterior_collection' => 1010
    'portrait_collection' => 101010
    
    // optional
    'mls_id' => 'best-mls-in-the-universe',
    'history_count' => 500
];

$feedfake = new FeedFaker\FakeFeed();
$data = $feedfake->go($settings);

$properties = $data['property'];
$offices = $data['office'];
$members = $data['member'];
$media = $data['media'];
$history = $data['history'];
$openhouses = $data['openhouse'];

foreach ($properties as $property) {
    echo $property->getListingKey() . PHP_EOL;

    var_dump($property->toArray());
}

Yep, that's it. You're welcome.

Optional Logging

The Faker can also log information to any PSR-3 compatible logger. (Useful for Image provider errors, etc.)

You have two options to set one up: Give it your own logger, or provide a setup callable for MonoLog.

Setup Callable for Monolog

By default, Faker uses Monolog to handle any logging, which uses handlers to know where and what details to log. If you provide no setup or logger, Faker will default to a NullHandler and save no log information.

You may provide any callable as the second parameter for FakeFeed. This callable accepts a monolog Logger instance and doesn't need to return anything.

$logger_setup = function($monolog) {
    // Save all debug and above messages to a file
    $monolog->pushHandler(new StreamHandler('/path/to/logs.log', \Monolog\Logger::DEBUG));
    
    // Save more important messages to some other place
    $monolog->pushHandler(new SomeOtherHandler(\Monolog\Logger::WARNING));
};

$feedfake = new FeedFaker\FakeFeed([], $logger_setup);
$data = $feedfake->go()

Your own logger

You may also skip monolog altogether and provide any instance of a PSR-3 compatible logger as the second argument.

$feedfake = new FeedFaker\FakeFeed([], $my_psr_3_logger);
$data = $feedfake->go()

Interoperability

Feed Faker is PSR compliant and Container Interoperability compliant. Any oversights, please let us know.

Testing

We try for at least 80% test coverage.

$ phpunit

Note tht the UnsplashPhotoProviderTests are skipped. These require a valid credential. You may extend and run these tests with your own credentials. A better (environment-based) system is on the way.

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

Open an issue to join in!

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 10
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-04-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固