You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuDateTimeDboArray.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 2/22/16
  6. * Time: 9:40 PM
  7. */
  8. namespace Luticate\Utils\Dbo;
  9. use Carbon\Carbon;
  10. class LuDateTimeDboArray extends LuDboArray
  11. {
  12. /**
  13. * @var Carbon[]
  14. */
  15. protected $_array;
  16. public function getArray()
  17. {
  18. return $this->_array;
  19. }
  20. public function setArray($value)
  21. {
  22. $this->_array = $value;
  23. }
  24. public function jsonSerialize()
  25. {
  26. $array = [];
  27. foreach ($this->_array as $date) {
  28. $array[] = is_null($date) ? null : $date->__toString();
  29. }
  30. return $array;
  31. }
  32. public static function jsonDeserialize($json)
  33. {
  34. if (!is_array($json)) {
  35. throw new LuDboDeserializeException("Invalid array value");
  36. }
  37. $dbo = new self();
  38. $array = [];
  39. foreach ($json as $data) {
  40. $array[] = LuDateTimeDbo::jsonDeserialize($data)->getDateTime();
  41. }
  42. $dbo->setArray($array);
  43. return $dbo;
  44. }
  45. public static function generateSample()
  46. {
  47. return [
  48. LuDateTimeDbo::generateSample(),
  49. LuDateTimeDbo::generateSample()
  50. ];
  51. }
  52. }