frankfoerster/cakephp-bitly 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

frankfoerster/cakephp-bitly

Composer 安装命令:

composer require frankfoerster/cakephp-bitly

包简介

CakePHP Bitly Plugin

README 文档

README

Software License Total Downloads Latest Stable Version

The cakephp-bitly plugin provides a wrapper for the bit.ly API to shorten long urls.

Installation

You can install this plugin into your CakePHP application using composer.

Run the following command

composer require frankfoerster/cakephp-bitly

Enable the Plugin

You can load the plugin using the shell command:

bin/cake plugin load FrankFoerster/Bitly

Or you can manually add the loading statement in the config/boostrap.php file of your application:

Plugin::load('FrankFoerster/Bitly');

Configure the Plugin

To use the UrlShortener you have to provide your bitly login name and your bitly API key as config entries within /config/app.php.

return [
    ...
    
    'Bitly' => [
        'login' => 'YOUR_LOGIN',
        'apiKey' => 'YOUR_API_KEY',

        /**
         * @link: http://book.cakephp.org/3.0/en/core-libraries/httpclient.html#proxy-authentication
         *
         * e.g.:
         * -----
         * 'proxy' => [
         *   'username' => 'foo', // optional username set in request header
         *   'password' => 'bar', // optional password set in request header
         *   'proxy' => 'tcp://localhost:9000'
         * ]
         */
        'proxy' => false
    ],
    
    ...
];

To obtain an api key sign up at https://bitly.com/a/sign_up .

Use the UrlShortener

To use the url shortener you have to instatiate a new UrlShortener instance. It will setup your instance with the configured parameters automatically.

You can wrap your calls in a try catch block (see below), because the cakephp-bitly plugin throws custom exceptions that represent all possible error responses from the bitly API. They all extend from the BitlyException and can be handled separately via multiple catch blocks.

use FrankFoerster\Bitly\Exception\BitlyException;
use FrankFoerster\Bitly\UrlShortener;

$urlShortener = new UrlShortener();

try {
    $shortUrl = $urlShortener->shorten($myLongUrl);
} catch (BitlyException $e) {
    // handle any of the exceptions
}

The result of the shorten($url) call is a response object containing the data returned from the bit.ly API call. It consists of the following properties:

  • new_hash - designates if this is the first time this long_url was shortened by this user. The return value will equal 1 the first time a long_url is shortened. It will also then be added to the user history.
  • url - the actual Bitlink that should be used, and is a unique value for the given Bitly account.
  • hash - a bitly hash for long_url which is unique to the given account.
  • global_hash - a bitly hash for long_url which can be used to track aggregate stats across all Bitlinks that point to the same long_url.
  • long_url - an echo back of the longUrl request parameter. This may not always be equal to the URL requested, as some URL normalization may occur (e.g., due to encoding differences, or case differences in the domain). This long_url will always be functionally identical the the request parameter.

frankfoerster/cakephp-bitly 适用场景与选型建议

frankfoerster/cakephp-bitly 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 106 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「library」 「url」 「cakephp」 「shortener」 「bitly」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 frankfoerster/cakephp-bitly 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 106
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-22