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.

61 lines
1.8 KiB

  1. <?php namespace Wpstudio\Assetsmanifest\Components;
  2. use Cms\Classes\ComponentBase;
  3. use Cms\Classes\Theme;
  4. use Wpstudio\AssetsManifest\Classes\ManifestReader;
  5. class Manifest extends ComponentBase
  6. {
  7. const LANG_PREFIX = 'wpstudio.assetsmanifest::lang.components.manifest.';
  8. private ?ManifestReader $manifestReader;
  9. public function componentDetails(): array
  10. {
  11. return [
  12. 'name' => self::LANG_PREFIX . 'name',
  13. 'description' => self::LANG_PREFIX . 'description',
  14. ];
  15. }
  16. public function defineProperties(): array
  17. {
  18. return [
  19. 'path' => [
  20. 'title' => self::LANG_PREFIX . 'properties.path.title',
  21. 'description' => self::LANG_PREFIX . 'properties.path.description',
  22. 'validationPattern' => '^[^/].*/manifest.json',
  23. 'validationMessage' => self::LANG_PREFIX . 'properties.path.validationMessage',
  24. 'placeholder' => 'assets/build/manifest.json',
  25. 'default' => 'assets/build/manifest.json',
  26. 'showExternalParam' => false,
  27. 'required' => true,
  28. ]
  29. ];
  30. }
  31. /**
  32. * @return void
  33. * @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
  34. */
  35. public function init(): void
  36. {
  37. app()->instance(Manifest::class, $this);
  38. $this->prepareVars();
  39. }
  40. /**
  41. * @return void
  42. * @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
  43. */
  44. private function prepareVars(): void
  45. {
  46. $this->manifestReader = new ManifestReader(Theme::getActiveTheme()->getPath() . '/' . $this->property('path'));
  47. }
  48. public function getManifestReader(): ManifestReader
  49. {
  50. return $this->manifestReader;
  51. }
  52. }