Zend_Service_ReCaptcha | Zend_Service Programmer's Reference Guide | Zend_Service_Simpy

# Zend_Service_ShortUrl

# Overview

URL shorteners have exploded in popularity in the last several years, in large part due to the social nature of the web and the desire to share links. Zend_Service_ShortUrl provides an API for accessing a number of different URL shortener services, with the ability to both create short URLs as well as retrieve the original URL.

Adapters provided include:

- Zend_Service_ShortUrl_JdemCz, which accesses the » jdem.cz service.

- Zend_Service_ShortUrl_TinyUrlCom, which accesses the » tinyurl.com service.

- Zend_Service_ShortUrl_MetamarkNet, which accesses the » metamark.net service.

- Zend_Service_ShortUrl_IsGd, which accesses the » is.gd service.

# Quick Start

Using one of the URL shortener services is straightforward. Each URL shortener follows a simple interface that defines two methods: shorten() and unshorten(). Instantiate the class, and call the appropriate method.

1. $tinyurl = new Zend_Service_ShortUrl_TinyUrlCom();
3. // Shorten a URL:
4. $short = $tinyurl->shorten('http://framework.zend.com/'); // http://tinyurl.com/rxtuq
6. // Inflate or unshorten a short URL:
7. $long = $tinyurl->unshorten('http://tinyurl.com/rxtuq'); // http://framework.zend.com/

# Available Methods

shorten ( $url )

  Takes the given $url and passes it to the service in order to obtain a shortened URL.

  If the provided $url is invalid, an exception will be raised.

unshorten ( $shortenedUrl )

  Takes the provided $shortenedUrl and passes it to the service in order to obtain the original URL.

  If the provided $shortenedUrl is invalid, an exception will be raised.

setHttpClient ( Zend_Http_Client $httpClient )

  Use this method to set the HTTP client used for communicating with the service.

getHttpClient ( )

  Use this method to access the HTTP client attached to the service. By default, this will lazy-load an instance of Zend_Http_Client if no client is yet attached.

Zend_Service_ReCaptcha | Zend_Service Programmer's Reference Guide | Zend_Service_Simpy