ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NodeModule.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26class 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}
Some distributable file created by npm.
Definition: NodeModule.php:27
__construct(protected string $source)
Definition: NodeModule.php:34
getSource()
The path of asset relative to the ILIAS base directory.
Definition: NodeModule.php:44
getTarget()
The new path of relative to the ILIAS public directory.
Definition: NodeModule.php:49
An public asset is a file or folder that should be served via the web.
Definition: PublicAsset.php:27