Package.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @package Grav\Common\GPM
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\GPM\Common;
  9. use Grav\Common\Data\Data;
  10. class Package
  11. {
  12. /**
  13. * @var Data
  14. */
  15. protected $data;
  16. public function __construct(Data $package, $type = null)
  17. {
  18. $this->data = $package;
  19. if ($type) {
  20. $this->data->set('package_type', $type);
  21. }
  22. }
  23. /**
  24. * @return Data
  25. */
  26. public function getData()
  27. {
  28. return $this->data;
  29. }
  30. public function __get($key)
  31. {
  32. return $this->data->get($key);
  33. }
  34. public function __set($key, $value)
  35. {
  36. return $this->data->set($key, $value);
  37. }
  38. public function __isset($key)
  39. {
  40. return isset($this->data->{$key});
  41. }
  42. public function __toString()
  43. {
  44. return $this->toJson();
  45. }
  46. public function toJson()
  47. {
  48. return $this->data->toJson();
  49. }
  50. /**
  51. * @return array
  52. */
  53. public function toArray()
  54. {
  55. return $this->data->toArray();
  56. }
  57. }