ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
NodeModule.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Component\Resource;
22 
26 class NodeModule implements PublicAsset
27 {
28  public const REGEXP_SOURCE = '%^(((\w|.)+(/(\w|.)+)*\.\w{2,4}))$%';
29 
34  public function __construct(
35  protected string $source
36  ) {
37  if (!preg_match(self::REGEXP_SOURCE, $this->source)) {
38  throw new \InvalidArgumentException(
39  "'{$this->source}' is not a valid source path for a public asset."
40  );
41  }
42  }
43 
44  public function getSource(): string
45  {
46  return "node_modules/{$this->source}";
47  }
48 
49  public function getTarget(): string
50  {
51  $source = explode("/", $this->source);
52  if (str_ends_with($this->source, ".js")) {
53  return ComponentJS::TARGET . "/" . array_pop($source);
54  }
55  if (str_ends_with($this->source, ".css")) {
56  return ComponentCSS::TARGET . "/" . array_pop($source);
57  }
58  throw new \LogicException("Don't know where to put {$this->source}");
59  }
60 }
getTarget()
The new path of relative to the ILIAS public directory.
Definition: NodeModule.php:49
getSource()
The path of asset relative to the ILIAS base directory.
Definition: NodeModule.php:44
An public asset is a file or folder that should be served via the web.
Definition: PublicAsset.php:26
__construct(protected string $source)
Definition: NodeModule.php:34
Some distributable file created by npm.
Definition: NodeModule.php:26