定制 adeelnawaz/polr-api-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

adeelnawaz/polr-api-bundle

Composer 安装命令:

composer require adeelnawaz/polr-api-bundle

包简介

Integration of Polr API Client into Symfony

README 文档

README

(Note: This version is not compatible with Symfony 3. Please use version 0.1.1 for apps running on Symfony 3)

This bundle provides Polr API Client integration in Symfony (4|5). This bundle is simply a wrapper over PHP package adeelnawaz/polr-api-client. The bundle exposes a service PolrApiService that can be utilized to call API methods of the PolrApi class from API Client package.

Installation

Step 1: Configuration

Create a configuration file in your config directory named polr_api.yml containing the following configuration:

polr_api:
  api_url: '%env(POLR_API_URL)%'
  api_key: '%env(POLR_API_KEY)%'
  api_quota: '%env(int:POLR_API_QUOTA)%'

In .env[.*] file, add the following environment variables

POLR_API_URL=https://your-polr-app.com
POLR_API_KEY=your_polr_api_key
POLR_API_QUOTA=0 # Set to zero for unlimited

Note: The POLR_API_QUOTA value makes sure that your application separates the API calls with enough delay that you don't exceed your calls/minute quota. If you specify a smaller value than your API key's actual quota then you will get an error from your Polr API.

Step 2: Install via Composer

In your console, navigate to your Symfony project directory and execute the following command to download the latest stable version of this package:

$ composer require adeelnawaz/polr-api-bundle

Step 3: Enable the Bundle

For apps with Symfony Flex, this step is not needed. Otherwise add the bundle to the list of registered bundles in config/bundles.php:

<?php
// config/bundles.php

return [
    ...,
    Adeelnawaz\PolrApiBundle\PolrApiBundle::class => ['all' => true],
];

All done!

Usage

In order to consume the API, use the service PolrApiService. Create DTO object(s) (Adeelnawaz\PolrApiClient\DTO\Link, etc) for the method you intend to use and call the method. This will result in calling the respective REST API endpoint and returning the relative Adeelnawaz\PolrApiClient\DTO\Response object.
(See Docblocks of the PolrApiService methods for further information on input/output DTOs)

In case of a failed API call, the PolrApiService methods throw Adeelnawaz\PolrApiClient\Exception\ApiResponseException. The exception has getters for code, message, and a machine readable short string error_code returned by the Polr REST API.

Example controller:

<?php

namespace App\Controller;

use Adeelnawaz\PolrApiBundle\Service\PolrApiService;
use Adeelnawaz\PolrApiClient\DTO\Link;
use Adeelnawaz\PolrApiClient\Exception\ApiResponseException;

class DefaultController extends AbstractController
{
    public function indexAction(PolrApiService $api)
    {
        // Prepare DTO for API method input
        $link = new Link();
        $link->setUrl('https://www.google.com/search?tbm=isch&source=hp&biw=1863&bih=916&ei=IksNW5eLHqzisAfvgKKQBg&q=samurai+jack&oq=samurai+jack&gs_l=img.3..0l10.799.2671.0.2891.13.10.0.3.3.0.54.372.9.9.0....0...1ac.1.64.img..1.12.380.0...0.NlHgI6Y6mmY')
            ->setIsSecret(true);
            
        try {
            $responseLink = $api->shortenLink($link);
        
            print_r($responseLink);
        } catch (ApiResponseException $e) {
            echo "Error: ({$e->getCode()} - {$e->getErrorCode()}) \"{$e->getMessage()}\"\n";
        }
    }
}

See also

Polr API Client Documentation.

adeelnawaz/polr-api-bundle 适用场景与选型建议

adeelnawaz/polr-api-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.7k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 adeelnawaz/polr-api-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adeelnawaz/polr-api-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 adeelnawaz/polr-api-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-30