|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service_ShortUrl |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Service_Abstract |
|
24 */ |
|
25 require_once 'Zend/Service/Abstract.php'; |
|
26 |
|
27 /** |
|
28 * @see Zend_Service_ShortUrl_Shortener |
|
29 */ |
|
30 require_once 'Zend/Service/ShortUrl/Shortener.php'; |
|
31 |
|
32 /** |
|
33 * @category Zend |
|
34 * @package Zend_Service_ShortUrl |
|
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
37 */ |
|
38 abstract class Zend_Service_ShortUrl_AbstractShortener |
|
39 extends Zend_Service_Abstract |
|
40 implements Zend_Service_ShortUrl_Shortener |
|
41 { |
|
42 /** |
|
43 * Base URI of the service |
|
44 * |
|
45 * @var string |
|
46 */ |
|
47 protected $_baseUri = null; |
|
48 |
|
49 |
|
50 /** |
|
51 * Checks whether URL to be shortened is valid |
|
52 * |
|
53 * @param string $url |
|
54 * @throws Zend_Service_ShortUrl_Exception When URL is not valid |
|
55 */ |
|
56 protected function _validateUri($url) |
|
57 { |
|
58 require_once 'Zend/Uri.php'; |
|
59 if (!Zend_Uri::check($url)) { |
|
60 require_once 'Zend/Service/ShortUrl/Exception.php'; |
|
61 throw new Zend_Service_ShortUrl_Exception(sprintf( |
|
62 'The url "%s" is not valid and cannot be shortened', $url |
|
63 )); |
|
64 } |
|
65 } |
|
66 |
|
67 /** |
|
68 * Verifies that the URL has been shortened by this service |
|
69 * |
|
70 * @throws Zend_Service_ShortUrl_Exception If the URL hasn't been shortened by this service |
|
71 * @param string $shortenedUrl |
|
72 */ |
|
73 protected function _verifyBaseUri($shortenedUrl) |
|
74 { |
|
75 if (strpos($shortenedUrl, $this->_baseUri) !== 0) { |
|
76 require_once 'Zend/Service/ShortUrl/Exception.php'; |
|
77 throw new Zend_Service_ShortUrl_Exception(sprintf( |
|
78 'The url "%s" is not valid for this service and the target cannot be resolved', |
|
79 $shortenedUrl |
|
80 )); |
|
81 } |
|
82 } |
|
83 } |