emanueleminotto/gravatar-service-provider

Silex 的 Gravatar 服务提供商

1.0.0 2015-02-04 10:27 UTC

This package is auto-updated.

Last update: 2024-08-28 07:04:56 UTC


README

Build Status SensioLabs Insight Coverage Status Scrutinizer Code Quality Total Downloads

Gravatar 提供一个 Silex 服务。

API: emanueleminotto.github.io/GravatarServiceProvider

安装

使用 Composer 安装 Silex。

安装 GravatarServiceProvider,将 emanueleminotto/gravatar-service-provider 添加到您的 composer.json 或从 CLI 安装

$ composer require emanueleminotto/gravatar-service-provider

使用方法

使用 register 初始化

use EmanueleMinotto\GravatarServiceProvider\GravatarServiceProvider;

$app->register(new GravatarServiceProvider(), array(
    'gravatar.http_client' => new GuzzleHttp\Client(), // default null, optional
    'gravatar.twig' => false, // default true, optional
));

可以将 gravatar.http_client 替换为 Guzzle HTTP 客户端实例,默认提供一个新实例。

从 PHP

$app->get('/hello/{email}', function ($email) use ($app) {
    $profile = $app['gravatar']->getProfile($email);

    return 'Hello ' . $profile['preferredUsername'];
});

Twig

设置选项 gravatar.twig => true,如果存在 Twig 服务提供商,您将能够使用由 Gravatar 库 提供的 Twig 扩展