maxikg/github-api-bundle

knplabs/github-api 在 Symfony 2/3 中的桥梁。

dev-master 2016-06-22 11:35 UTC

This package is not auto-updated.

Last update: 2024-09-26 00:47:15 UTC


README

KnpLabs/php-github-api 和 Symfony 2/3 之间建立一个简单的桥梁。

安装

使用 composer 安装包

composer require maxikg/github-api-bundle

现在注册包

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Maxikg\GithubApiBundle\GithubApiBundle(),
    );
    // ...
}

配置

默认配置如下

# app/config/config.yml
github_api:
    cache:
        enabled: false
        service: github.http.cache
    client: null
    enterprise_url: null
    authentication:
        type: none
        token: null
        client_id: null
        client_secret: null
        username: null
        password: null
  • cache 配置缓存客户端。
    • enabled (布尔值) 允许开启或关闭缓存。
    • service (字符串) 允许指定自定义缓存服务。缓存必须实现 Github\HttpClient\Cache\CacheInterface
  • client 配置客户端选项。允许的设置可能因实现而异。但是,默认值是
    • base_url (字符串) 指定基本 API URL(如果您使用 GitHub Enterprise,应使用下面描述的 enterprise_url 配置)。
    • user_agent (字符串) 指定 User-Agent 头的值。 GitHub 喜欢在这里看到您的或您的应用程序的名称
    • timeout (整数) 指定连接超时时间(以秒为单位)。
    • api_limit (整数) 未知用途。
    • api_version (字符串) 请求的 API 版本。
    • cache_dir (字符串) 缓存目录。但我建议使用 cache 配置部分以避免问题。
  • enterprise_url (字符串) 配置 GitHub Enterprise 实例的 URL。
  • authentication 配置与 API 的身份验证。您可以在大多数情况下不进行身份验证而使用 GitHub.com API,但 GH Enterprise 几乎需要对所有内容进行身份验证。
    • type (字符串) 身份验证类型
      • none 为禁用身份验证。
      • url_token 通过设置 access_token 参数将 OAuth Token 添加到 URL。
      • url_client_id 通过设置 client_idclient_secret 参数将您的客户端 ID 和密钥添加到 URL。
      • http_password 通过设置您的用户名和密码通过 HTTP 头进行身份验证。如果启用了两步验证,则不会工作。
      • http_token 通过将 OAuth Token 添加到 HTTP 头进行身份验证。
    • token (字符串) 指定 OAuth Token。仅适用于 url_tokenhttp_token 类型。
    • client_id (字符串) 指定客户端 ID。仅适用于 url_client_id 类型。
    • client_secret (字符串) 指定客户端密钥。仅适用于 url_client_id 类型。
    • username (字符串) 指定您的用户名。仅适用于 http_password 类型。
    • password (字符串) 指定您的密码。仅适用于 http_password 类型。

但您不必配置此包。它也将使用默认值。

使用

您可以通过要求服务 github.client 来获取 Github\Client 的实例。

有关更详细的说明,请参阅此处: https://github.com/KnpLabs/php-github-api/tree/1.6.0/doc

可能即将推出的功能

  • 额外的缓存适配器
  • 多客户端配置
  • Resources/docs 文件夹中的更好的文档
  • 与 Symfony <2.8 的兼容性检查

许可证

请参阅 LICENSE.txt。不必担心,它是 MIT 许可证。