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.

59 lines
1.6 KiB

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