mslib/resource-proxy

通用 Ms 库,用于从远程源(例如邮箱)获取资源

dev-master 2014-05-28 15:43 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:58:10 UTC


README

这个库提供了一个简单的方法来从远程资源源(例如电子邮件、图像、文档等)获取资源。

它基于 ZendFramework2。以下是目前使用的 ZF2 模块(请参阅 composer.json 获取所有依赖的完整概述)

{
    "require": {
        "zendframework/zend-mail": "2.*"
    }
}

安装

安装是一个快速的三步过程

  1. 使用 composer 下载 ResourceProxy
  2. 配置您的源
  3. 生成您的 ResourceProxy 实现

第一步:使用 composer 下载 ResourceProxy

在您的 composer.json 中添加 RemoteHost

{
    "require": {
        "mslib/resource-proxy": "dev-master"
    }
}

现在运行以下命令告诉 composer 下载库

$ php composer.phar update mslib/resource-proxy

Composer 将将库安装到您的项目的 vendor/mslib/resource-proxy 目录。

第二步:配置您的源

现在 ResourceProxy 库已存在于您的项目中(例如通过 composer),您需要配置应用程序所需的所有必需源。

为了做到这一点,您必须创建一个包含给定配置键值的数组 PHP 文件。以下是一个此类文件的结构。

<?php

return array(
    'global' => array(
        'host'          => '', // (Not required)
        'port'          => '', // (Not required)
        'ssl'           => '', // (Not required) Possible values: 'SSL',
        'output_folder' => '',
    ),
    'sources' => array(
        'source-name' => array(
            'type'              => 'imap|sftp|ftp', // (REQUIRED) the resource type. Possible values: 'imap|sftp|ftp'
            'connection'           => array(
                'host'          => '', // (If not specified, we check the global.host variable)
                'port'          => '', // (If not specified, we check the global.port variable)
                'ssl'           => '', // (If not specified, we check the global.ssl variable) Possible values: 'SSL'
                'username'      => '', // (REQUIRED)
                'password'      => '', // (REQUIRED)
                'filter'        => array( // The filter list could be different for each source type
                    'message_status' => 'unread_only', // FOR IMAP TYPE ONLY
                    'folder'         => '', // FOR IMAP TYPE ONLY. If not specified, INBOX will be selected
                    'start_date'     => 'yesterday|last_week|last_month', // FOR FTP/SFTP TYPE ONLY
                )
            ),
        ),
    ),
);

资源将被包装在库接口 'Msl\ResourceProxy\Resource\ResourceInterface' 的适当实现中。例如,对于 'imap' 类型,每个资源都将包装成一个 'Msl\ResourceProxy\Resource\ImapMessage' 对象实例。

第三步:生成您的 ResourceProxy 实现

现在您已配置了所有必需的源,您需要在项目中创建一个类,它扩展库 RemoteHost 中定义的基本抽象类 'Msl\ResourceProxy\Proxy\AbstractProxy'

默认类构造函数需要两个参数

  • $proxyName:在日志、异常等中使用的代理名称(例如 'MY_PROXY');默认值在类常量 Msl 中定义;要覆盖此值,您可以将有效的字符串作为类构造函数的第一个参数传递,或在子类中重新定义常量 PROXY_NAME;
  • $config:包含第二步中定义的配置的数组;