Пример #1
0
 public function run()
 {
     if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["original_url"])) {
         $shorturl = new ShortUrl(new Environment(), new DataStore($this->dbconfig()));
         $vars = [];
         try {
             $vars["shorturl"] = $shorturl->getShortUrl($_POST["original_url"]);
         } catch (InvalidUrlException $e) {
             $vars["message"] = $e->getMessage();
         } catch (UrlInsertFailException $e) {
             $vars["message"] = $e->getMessage();
         } catch (\Exception $e) {
             $vars["message"] = "エラーが発生しました。";
         }
         $this->send_body(implode(DIRECTORY_SEPARATOR, ["..", "..", "view", "create_shorturl.php"]), $vars);
     } else {
         $this->send_body(implode(DIRECTORY_SEPARATOR, ["..", "..", "view", "create_shorturl.php"]));
     }
 }
Пример #2
0
 public function test_getShortUrl_fail_notfound()
 {
     $this->init_table();
     $shorturl = new ShortUrl(new Environment(), new DataStore(static::$dbconfig));
     $url = "http://yahoo.co.jp";
     $shortedurl = $shorturl->getShortUrl($url);
     list(, , , $token) = explode("/", $shortedurl);
     try {
         $shorturl->getOriginalUrl($token . "a");
         $this->fail();
     } catch (OriginalUrlNotFoundException $e) {
         $this->assertTrue(true);
     }
 }