GameData.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. require_once dirname(__FILE__).'/AbstractDataContent.php';
  3. /**
  4. * 玩家游戏数据对象定义
  5. * Date: 15-12-15
  6. * Time: 下午1:47
  7. */
  8. class GameData {
  9. public $category; //标示游戏类别数据
  10. public $content;//具体内容,可能为列表,也可能为单个对象
  11. function __construct($category, $content)
  12. {
  13. $this->category = $category;
  14. $this->content = $content;
  15. }
  16. /**
  17. * @return mixed
  18. */
  19. public function getContent()
  20. {
  21. return $this->content;
  22. }
  23. /**
  24. * @param mixed $content
  25. */
  26. public function setContent($content)
  27. {
  28. $this->content = $content;
  29. }
  30. /**
  31. * @return mixed
  32. */
  33. public function getCategory()
  34. {
  35. return $this->category;
  36. }
  37. /**
  38. * @param mixed $category
  39. */
  40. public function setCategory($category)
  41. {
  42. $this->category = $category;
  43. }
  44. /**
  45. * 对外的数据校验方法
  46. * @return
  47. */
  48. public function validate() {
  49. if(empty($this->category)){
  50. return false;
  51. }
  52. if($this->content == null){
  53. return false;
  54. }
  55. if(is_array($this->content)){
  56. //循环判断
  57. $checkResult = true;
  58. foreach ($this->content as $obj){
  59. if($obj instanceof AbstractDataContent){
  60. $checkResult &= $obj->validate();
  61. }
  62. else{
  63. return false;
  64. }
  65. //列表判断时,只要有一个出现false,无需判断后续的数据
  66. if(!$checkResult){
  67. return $checkResult;
  68. }
  69. }
  70. return $checkResult;
  71. }
  72. else if($this->content instanceof AbstractDataContent){
  73. if($this->content instanceof AbstractDataContent){
  74. return $this->content->validate();
  75. }
  76. else{
  77. return false;
  78. }
  79. }
  80. //数据类型不明确,一律返回校验不通过
  81. return false;
  82. }
  83. }