PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/models/Category.class.php

https://github.com/HarrickZeke/PHPForum
PHP | 81 lines | 64 code | 14 blank | 3 comment | 4 complexity | 27053959124f9d1679775cae5a22d2ee MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. */
  5. class Category
  6. {
  7. private $_id;
  8. private $_name;
  9. private $_orderId;
  10. public function __construct(array $data)
  11. {
  12. $this->hydrate($data);
  13. }
  14. public function hydrate(array $data)
  15. {
  16. foreach ($data as $key => $value)
  17. {
  18. $method = 'set'.ucfirst($key);
  19. if (method_exists($this, $method))
  20. {
  21. $this->$method($value);
  22. }
  23. }
  24. }
  25. public function setId($id)
  26. {
  27. $id = (int) $id;
  28. if(!is_int($id))
  29. {
  30. trigger_error("Id must be an integer");
  31. return;
  32. }
  33. $this->_id = $id;
  34. }
  35. public function setName($name)
  36. {
  37. if(!is_string($name))
  38. {
  39. trigger_error("Name must be a string");
  40. return;
  41. }
  42. $this->_name = $name;
  43. }
  44. public function setOrderId($orderId)
  45. {
  46. $orderId = (int) $orderId;
  47. if(!is_int($orderId))
  48. {
  49. trigger_error("Order id must be an integer");
  50. return;
  51. }
  52. $this->_orderId = $orderId;
  53. }
  54. public function id()
  55. {
  56. return $this->_id;
  57. }
  58. public function name()
  59. {
  60. return $this->_name;
  61. }
  62. public function orderId()
  63. {
  64. return $this->_orderId;
  65. }
  66. }
  67. ?>