asimlqt/mailchimp-export 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

asimlqt/mailchimp-export

Composer 安装命令:

composer require asimlqt/mailchimp-export

包简介

A library to export Mailchimp lists

README 文档

README

A simple library to export Mailchimp lists

Requires PHP >= 7

Installation

Use the following composer command to install

composer require asimlqt/mailchimp-export

Example

The following is an example that exports a mailchimp list and saves it to a csv file.

<?php

require_once './vendor/autoload.php';

use Asimlqt\MailchimpExport\MailchimpException;
use Asimlqt\MailchimpExport\ListExport;
use Asimlqt\MailchimpExport\Writer\CsvWriter;

$writer = new CsvWriter(new SplFileObject("/my/path/list.csv", "w"));

try {
    $exp = new ListExport($apiKey, $listId, $writer);
    $exp->run();
} catch (MailchimpException $e) {
    echo $e->getMessage();    
}

Writers

There are currently 2 writers that are provided by default:

CSV Writer

See example above.

Database Writer

CAUTION: The table specified will be truncated before being written to!

This requires a little more configuration than the csv writer.

The constructor has the following definition:

public function __construct(PDO $pdo, string $table, array $mapping)

$pdo is just a standard php pdo connection object.

$table is the name of the table that you want to write to

$mapping is an array that maps mailchimp fields to database columns. The key of the array is the name of the mailchimp field and the value is the database column.

Example of using the database writer:

<?php

require_once './vendor/autoload.php';

use Asimlqt\MailchimpExport\MailchimpException;
use Asimlqt\MailchimpExport\ListExport;
use Asimlqt\MailchimpExport\Writer\DatabaseWriter;

$mapping = [
    'Email Address' => 'email',
    'First Name' => 'firstname',
    'Last Name' => 'lastname',
];

$pdo = new PDO('mysql:dbname=mailchimp;host=127.0.0.1', 'user', 'password');
$writer = new DatabaseWriter($pdo, 'subscribers', $mapping);

try {
    $exp = new ListExport($apiKey, $listId, $writer);
    $exp->run();
} catch (MailchimpException $e) {
    echo $e->getMessage();
}

In the above example 'Email Address', 'First Name' and 'Last Name' are names of mailchimp fields and 'email', 'firstname' and 'lastname' are database columns they will be written to. The CsvWriter just writes everything to a csv file as is hence it doesn't require a mapping.

The data is inserted into the database in batches. The default size is 100 rows. You can set that to a different value if you wish using setBatchSize() method of DatabaseWriter

Custom Writer

If you need to write the data elsewhere then simply extend the Writer interface which only has one method and pass it to the ListExport constructor.

interface Writer
{
    public function write(array $data);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-01-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固