Package.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Local;
  9. use Grav\Common\Data\Data;
  10. use Grav\Common\GPM\Common\Package as BasePackage;
  11. use Parsedown;
  12. /**
  13. * Class Package
  14. * @package Grav\Common\GPM\Local
  15. */
  16. class Package extends BasePackage
  17. {
  18. /** @var array */
  19. protected $settings;
  20. /**
  21. * Package constructor.
  22. * @param Data $package
  23. * @param string|null $package_type
  24. */
  25. public function __construct(Data $package, $package_type = null)
  26. {
  27. $data = new Data($package->blueprints()->toArray());
  28. parent::__construct($data, $package_type);
  29. $this->settings = $package->toArray();
  30. $html_description = Parsedown::instance()->line($this->__get('description'));
  31. $this->data->set('slug', $package->__get('slug'));
  32. $this->data->set('description_html', $html_description);
  33. $this->data->set('description_plain', strip_tags($html_description));
  34. $this->data->set('symlink', is_link(USER_DIR . $package_type . DS . $this->__get('slug')));
  35. }
  36. /**
  37. * @return bool
  38. */
  39. public function isEnabled()
  40. {
  41. return (bool)$this->settings['enabled'];
  42. }
  43. }