Package.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @package Grav\Common\GPM
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 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. /**
  11. * @property string $name
  12. */
  13. class Package
  14. {
  15. /** @var Data */
  16. protected $data;
  17. /**
  18. * Package constructor.
  19. * @param Data $package
  20. * @param string|null $type
  21. */
  22. public function __construct(Data $package, $type = null)
  23. {
  24. $this->data = $package;
  25. if ($type) {
  26. $this->data->set('package_type', $type);
  27. }
  28. }
  29. /**
  30. * @return Data
  31. */
  32. public function getData()
  33. {
  34. return $this->data;
  35. }
  36. /**
  37. * @param string $key
  38. * @return mixed
  39. */
  40. #[\ReturnTypeWillChange]
  41. public function __get($key)
  42. {
  43. return $this->data->get($key);
  44. }
  45. /**
  46. * @param string $key
  47. * @param mixed $value
  48. * @return void
  49. */
  50. #[\ReturnTypeWillChange]
  51. public function __set($key, $value)
  52. {
  53. $this->data->set($key, $value);
  54. }
  55. /**
  56. * @param string $key
  57. * @return bool
  58. */
  59. #[\ReturnTypeWillChange]
  60. public function __isset($key)
  61. {
  62. return isset($this->data->{$key});
  63. }
  64. /**
  65. * @return string
  66. */
  67. #[\ReturnTypeWillChange]
  68. public function __toString()
  69. {
  70. return $this->toJson();
  71. }
  72. /**
  73. * @return string
  74. */
  75. public function toJson()
  76. {
  77. return $this->data->toJson();
  78. }
  79. /**
  80. * @return array
  81. */
  82. public function toArray()
  83. {
  84. return $this->data->toArray();
  85. }
  86. }