File indexing completed on 2025-01-26 05:29:54
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_ShortUrl 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id: $ 0020 */ 0021 0022 /** 0023 * @see Zend_Service_Abstract 0024 */ 0025 // require_once 'Zend/Service/Abstract.php'; 0026 0027 /** 0028 * @see Zend_Service_ShortUrl_Shortener 0029 */ 0030 // require_once 'Zend/Service/ShortUrl/Shortener.php'; 0031 0032 /** 0033 * @category Zend 0034 * @package Zend_Service_ShortUrl 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 abstract class Zend_Service_ShortUrl_AbstractShortener 0039 extends Zend_Service_Abstract 0040 implements Zend_Service_ShortUrl_Shortener 0041 { 0042 /** 0043 * Base URI of the service 0044 * 0045 * @var string 0046 */ 0047 protected $_baseUri = null; 0048 0049 0050 /** 0051 * Checks whether URL to be shortened is valid 0052 * 0053 * @param string $url 0054 * @throws Zend_Service_ShortUrl_Exception When URL is not valid 0055 */ 0056 protected function _validateUri($url) 0057 { 0058 // require_once 'Zend/Uri.php'; 0059 if (!Zend_Uri::check($url)) { 0060 // require_once 'Zend/Service/ShortUrl/Exception.php'; 0061 throw new Zend_Service_ShortUrl_Exception(sprintf( 0062 'The url "%s" is not valid and cannot be shortened', $url 0063 )); 0064 } 0065 } 0066 0067 /** 0068 * Verifies that the URL has been shortened by this service 0069 * 0070 * @throws Zend_Service_ShortUrl_Exception If the URL hasn't been shortened by this service 0071 * @param string $shortenedUrl 0072 */ 0073 protected function _verifyBaseUri($shortenedUrl) 0074 { 0075 if (strpos($shortenedUrl, $this->_baseUri) !== 0) { 0076 // require_once 'Zend/Service/ShortUrl/Exception.php'; 0077 throw new Zend_Service_ShortUrl_Exception(sprintf( 0078 'The url "%s" is not valid for this service and the target cannot be resolved', 0079 $shortenedUrl 0080 )); 0081 } 0082 } 0083 }