fork download
  1. <?php
  2.  
  3.  
  4. class Resource
  5. {
  6. private $ja_msg = array(
  7. "goodmoring" => "おはようございます",
  8. "goodafternoon" => "こんにちは",
  9. "goodevening" => "こんばんは"
  10. );
  11. private $en_msg = array(
  12. "goodmoring" => "Good Morning",
  13. "goodafternoon" => "Good Afternoon",
  14. "goodevening" => "Good Evening"
  15. );
  16. private static $instance = null;
  17. public static function Get()
  18. {
  19. if(is_null(self::$instance))
  20. {
  21. self::$instance = new Resource();
  22. }
  23. return self::$instance;
  24. }
  25. public function GetText($msg)
  26. {
  27. $locale = Locale::getDefault();
  28. if($locale == "ja")
  29. return $this->ja_msg[$msg];
  30. if($locale == "en")
  31. return $this->en_msg[$msg];
  32. return $this->ja_msg[$msg];
  33. }
  34. }
  35.  
  36. Class Greet
  37. {
  38. public function __construct()
  39. {
  40. }
  41. public function greet($timestamp)
  42. {
  43. $this->greet(getdate());
  44. }
  45. public function greet2($date)
  46. {
  47. $res = Resource::Get();
  48. $hour = $date["hour"];
  49. if($hour >= 5 && $hour < 12)
  50. return $res->GetText("goodmoring");
  51. if($hour >= 12 && $hour < 18)
  52. return $res->GetText("goodafternoon");
  53. if($hour >= 18 && $hour <= 23)
  54. return $res->GetText("goodevening");
  55. if($hour >= 0 && $hour < 5)
  56. return $res->GetText("goodevening");
  57. }
  58. }
  59.  
  60. TestMessage();
  61. Locale::setDefault('en');
  62. TestMessage();
  63. Locale::setDefault('ja');
  64. TestMessage();
  65.  
  66. function TestMessage()
  67. {
  68. $res = Resource::Get();
  69. $greeter = new Greet();
  70. $result = $greeter->greet2(date_parse("2013/12/01 5:00:00"));
  71. if($result != $res->GetText("goodmoring"))
  72. {
  73. die("テスト失敗");
  74. }
  75. $result = $greeter->greet2(date_parse("2013/12/01 12:00:00"));
  76. if($result != $res->GetText("goodafternoon"))
  77. {
  78. die("テスト失敗");
  79. }
  80. $result = $greeter->greet2(date_parse("2013/12/01 18:00:00"));
  81. if($result != $res->GetText("goodevening"))
  82. {
  83. die("テスト失敗");
  84. }
  85. }
  86.  
Runtime error #stdin #stdout #stderr 0.01s 20592KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected 'TestMessage' (T_STRING) in /home/jyAxFc/prog.php on line 61