ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
OfComponent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26class OfComponent implements PublicAsset
27{
28 public const REGEXP_SOURCE = '%^(((\w|.)+(/(\w|.)+)*(\.\w{2,4})?)|(\.htaccess))$%';
29 public const REGEXP_TARGET = '%^(((\w|.)+(/(\w|.)+)*)|[.])$%';
30
36 public function __construct(
37 protected \ILIAS\Component\Component $component,
38 protected string $source,
39 protected string $target,
40 ) {
41 if (!preg_match(self::REGEXP_SOURCE, $this->source)) {
42 throw new \InvalidArgumentException(
43 "'{$this->source}' is not a valid source path for a public asset."
44 );
45 }
46 if (!preg_match(self::REGEXP_TARGET, $this->target)) {
47 throw new \InvalidArgumentException(
48 "'{$this->target}' is not a valid target path for a public asset."
49 );
50 }
51 }
52
53 public function getSource(): string
54 {
55 list($vendor, $component) = explode("\\", get_class($this->component));
56
57 return "components/$vendor/$component/resources/{$this->source}";
58 }
59
60 public function getTarget(): string
61 {
62 $source = explode("/", $this->source);
63 if ($this->target === ".") {
64 return array_pop($source);
65 }
66 return $this->target . "/" . array_pop($source);
67 }
68}
An public asset that is a resource of some component.
Definition: OfComponent.php:27
getTarget()
The new path of relative to the ILIAS public directory.
Definition: OfComponent.php:60
getSource()
The path of asset relative to the ILIAS base directory.
Definition: OfComponent.php:53
__construct(protected \ILIAS\Component\Component $component, protected string $source, protected string $target,)
Definition: OfComponent.php:36
An public asset is a file or folder that should be served via the web.
Definition: PublicAsset.php:27
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.