caponica/imap-bundle

PhpImap 的 Symfony2 服务包装器

安装量: 1,889

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2016-11-05 18:29 UTC

This package is auto-updated.

Last update: 2024-09-15 10:40:42 UTC


README

通过 Symfony 服务集成 PhpImap。

安装

使用 composer 安装,在您的 composer.json 文件的 require 部分添加以下内容

    "require": {
        ...
        "caponica/imap-bundle": "dev-master"
    },

在您的内核中注册该包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Caponica\ImapBundle\CaponicaImapBundle(),
    );
}

配置

默认情况下,该包不会向您的项目添加服务。要添加服务,您需要定义参数,然后定义服务本身。

# app/config/parameters.yml
your_imap_config:
    imapPath:           '{imap.gmail.com:993/imap/ssl}INBOX'
    username:           you@gmail.com
    password:           your_password
    directory:          /path/to/folder
# services.yml
    caponica_imap_box:
        class:          Caponica\ImapBundle\Service\CaponicaImap
        calls:
            - [ setConfig, [ %your_imap_config_box% ]]

用法

要访问服务,只需引用您上面定义的服务名称即可。例如,从一个控制器中

$caponicaImap = $this->container->get('caponica_imap_box');
$mailbox = $this->caponicaImap->getImapMailbox();
$mailsIds = $mailbox->sortMails(SORTDATE);