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.

LuDboArray.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 6/16/16
  6. * Time: 1:48 PM
  7. */
  8. namespace Luticate\Utils\Dbo;
  9. class LuDboArray extends LuDbo
  10. {
  11. protected static $_dboClass = LuDbo::class;
  12. /**
  13. * @var mixed[]
  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 $dbo) {
  28. $array[] = is_null($dbo) ? null : $dbo->jsonSerialize();
  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[] = LuDbo::deserializeValue($data, static::$_dboClass);
  41. }
  42. $dbo->setArray($array);
  43. return $dbo;
  44. }
  45. public static function generateSample()
  46. {
  47. return [
  48. call_user_func([static::$_dboClass, "generateSample"]),
  49. call_user_func([static::$_dboClass, "generateSample"])
  50. ];
  51. }
  52. }