/** * shortens a valid url and returns a short url * * @param string $pUrl * @return string * @throws ModelException */ public static function shortenUrl($pUrl) { $lUrl = urldecode($pUrl); $lUrl = str_replace(" ", "+", $lUrl); if (!UrlUtils::isUrlValid($lUrl)) { throw new ModelException("invalid url"); } if ($lShortUrl = self::getByUrl($lUrl)) { return $lShortUrl->getShortedUrl(); } else { $lShortUrl = new ShortUrl(); $lShortUrl->setUrl($lUrl); $lShortUrl->save(); return $lShortUrl->getShortedUrl(); } }