Created
January 17, 2018 21:29
-
-
Save tayfunerbilen/20a5e92e4f50b65fa056b1d542931301 to your computer and use it in GitHub Desktop.
https://youtu.be/xAuAJI2_5-8 dersi kaynak dosyası
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Hata extends Exception { | |
public function printJSON() | |
{ | |
$arr = [ | |
'mesaj' => $this->message, | |
'kod' => $this->code, | |
'satir' => $this->line, | |
'dosya' => $this->file | |
]; | |
return json_encode($arr); | |
} | |
public function printXML() | |
{ | |
header('Content-type: text/xml'); | |
$xml = new SimpleXMLElement('<hata/>'); | |
$xml->addChild('mesaj', $this->message); | |
$xml->addChild('kod', $this->code); | |
$xml->addChild('satir', $this->line); | |
$xml->addChild('dosya', $this->file); | |
return $xml->asXML(); | |
} | |
} | |
try { | |
if (!isset($_GET['id'])){ | |
throw new Hata('ıd parametresi eksik!'); | |
} elseif (empty($_GET['id'])){ | |
throw new Hata('id parametresi boş'); | |
} elseif (!is_numeric($_GET['id'])){ | |
throw new Hata('id değeri sayı değil!'); | |
} else { | |
echo $_GET['id']; | |
} | |
} catch(Hata $e){ | |
echo $e->printJSON(); | |
} finally { | |
//echo 'finally metodu calıstı'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment