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:
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.
- $tinyurl = new Zend_Service_ShortUrl_TinyUrlCom();
- // Shorten a URL:
- $short = $tinyurl->shorten('http://framework.zend.com/'); // http://tinyurl.com/rxtuq
- // Inflate or unshorten a short URL:
- $long = $tinyurl->unshorten('http://tinyurl.com/rxtuq'); // http://framework.zend.com/
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.
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.
Use this method to set the HTTP client used for communicating with the service.
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.