承接 issei-m/streamed-csv-response 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

issei-m/streamed-csv-response

最新稳定版本:v1.1

Composer 安装命令:

composer require issei-m/streamed-csv-response

包简介

Extends the Symfony\Component\HttpFoundation\StreamedResponse to send a CSV file to client.

README 文档

README

SensioLabsInsight

Build Status Scrutinizer Code Quality Code Coverage License

Extending the Symfony\Component\HttpFoundation\StreamedResponse to send a CSV file to client. It works with Symfony 2.7 and newer (including 3 and 4 of course) on PHP 7.x.

Usage

Very easy, just pass two arguments to the constructor. For instance in Symfony's controller:

public function exportCustomersAction(Request $request)
{
    return new StreamedCsvResponse(
        // 1st parameter: any iterable CSV rows
        (function () {
            yield ['Full Name', 'Email', 'Gender'];

            foreach ($this->get('user_repository')->getAllUsers() as $user) {
                yield [
                    $user->getFullName(),
                    $user->getEmail(),
                    $user->getGender(),
                ];
            }

            // Of course, you can also use any iterable for cell representation
            yield (function () {
                yield '村澤 逸生';
                yield 'issei.m7@gmail.com';
                yield '男性';
            })();
        })(),

        // 2nd parameter: the filename the browser uses in downloading 
        'customers.csv'
    ); 
}

auto encoding

If the response has been set any charset, every cell content will be encoded accordingly when sending:

$response = new StreamedCsvResponse($rows, 'customers.csv');
$response->setCharset('SJIS-win');

$response->send(); // Every cells are automatically encoded to SJIS-win.

Installation

Use Composer to install the package:

$ composer require issei-m/streamed-csv-response

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-12