ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Component\Resource\PublicAssetManager Class Reference

Will take care of the public assets, just like a good manager does. More...

+ Collaboration diagram for ILIAS\Component\Resource\PublicAssetManager:

Public Member Functions

 addAssets (PublicAsset ... $assets)
 
 buildPublicFolder (string $ilias_base, string $target)
 

Data Fields

const REGEXP = '%^(/\w+|\w+[\-.]\w+)+$%'
 
const DONT_PURGE = ["data", "Customizing"]
 

Protected Member Functions

 insertInto (array &$assets, array $path, PublicAsset $asset)
 
 buildPublicFolderRecursively (string $ilias_base, string $target, PublicAsset|array $asset)
 
 buildPublicFolderRecursivelyArray (string $ilias_base, string $target, array $assets)
 
 copy (string $source, string $target)
 
 purge (string $path, array $dont_purge)
 
 makeDir (string $path)
 

Protected Attributes

 $assets = []
 

Detailed Description

Will take care of the public assets, just like a good manager does.

Definition at line 26 of file PublicAssetManager.php.

Member Function Documentation

◆ addAssets()

ILIAS\Component\Resource\PublicAssetManager::addAssets ( PublicAsset ...  $assets)

Definition at line 35 of file PublicAssetManager.php.

35 : void
36 {
37 foreach ($assets as $asset) {
38 $this->insertInto($this->assets, explode("/", $asset->getTarget()), $asset);
39 }
40 }
insertInto(array &$assets, array $path, PublicAsset $asset)

References ILIAS\Component\Resource\PublicAssetManager\$assets, and ILIAS\Component\Resource\PublicAssetManager\insertInto().

+ Here is the call graph for this function:

◆ buildPublicFolder()

ILIAS\Component\Resource\PublicAssetManager::buildPublicFolder ( string  $ilias_base,
string  $target 
)
Parameters
string$ilias_basefull path to ILIAS base folder
string$targetfull path to public folder

Definition at line 76 of file PublicAssetManager.php.

76 : void
77 {
78 if (!preg_match(self::REGEXP, $ilias_base)) {
79 throw new \InvalidArgumentException(
80 "'{$ilias_base}' is not a valid path to ILIAS base folder."
81 );
82 }
83 if (!preg_match(self::REGEXP, $target)) {
84 throw new \InvalidArgumentException(
85 "'{$target}' is not a valid target path for public assets."
86 );
87 }
88
89 $this->purge($target, array_map(fn($v) => $target . "/" . $v, self::DONT_PURGE));
90 $this->makeDir($target);
91 $this->buildPublicFolderRecursivelyArray($ilias_base, $target, $this->assets);
92 }
buildPublicFolderRecursivelyArray(string $ilias_base, string $target, array $assets)
purge(string $path, array $dont_purge)

References ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursivelyArray(), ILIAS\Component\Resource\PublicAssetManager\makeDir(), and ILIAS\Component\Resource\PublicAssetManager\purge().

+ Here is the call graph for this function:

◆ buildPublicFolderRecursively()

ILIAS\Component\Resource\PublicAssetManager::buildPublicFolderRecursively ( string  $ilias_base,
string  $target,
PublicAsset|array  $asset 
)
protected

Definition at line 94 of file PublicAssetManager.php.

94 : void
95 {
96 if (is_array($asset)) {
97 $this->makeDir("$target");
98 $this->buildPublicFolderRecursivelyArray($ilias_base, $target, $asset);
99 } else {
100 $targets = explode("/", $asset->getTarget());
101 $this->copy("$ilias_base/{$asset->getSource()}", "$target");
102 }
103 }

References ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursivelyArray(), ILIAS\Component\Resource\PublicAssetManager\copy(), and ILIAS\Component\Resource\PublicAssetManager\makeDir().

Referenced by ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursivelyArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildPublicFolderRecursivelyArray()

ILIAS\Component\Resource\PublicAssetManager::buildPublicFolderRecursivelyArray ( string  $ilias_base,
string  $target,
array  $assets 
)
protected

Definition at line 105 of file PublicAssetManager.php.

105 : void
106 {
107 foreach ($assets as $key => $asset) {
108 $this->buildPublicFolderRecursively($ilias_base, "$target/$key", $asset);
109 }
110 }
buildPublicFolderRecursively(string $ilias_base, string $target, PublicAsset|array $asset)

References ILIAS\Component\Resource\PublicAssetManager\$assets, and ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursively().

Referenced by ILIAS\Component\Resource\PublicAssetManager\buildPublicFolder(), and ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursively().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy()

ILIAS\Component\Resource\PublicAssetManager::copy ( string  $source,
string  $target 
)
protected

Definition at line 112 of file PublicAssetManager.php.

112 : void
113 {
114 if (is_file($source)) {
115 copy($source, $target);
116 } elseif (is_dir($source)) {
117 $dir = new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS);
118 $this->makeDir($target);
119 foreach ($dir as $d) {
120 $name = $d->getBasename();
121 $this->copy("$source/$name", "$target/$name");
122 }
123 } else {
124 throw new \RuntimeException(
125 "Cannot copy $source, not a file or directory."
126 );
127 }
128 }

References Vendor\Package\$d, ILIAS\Component\Resource\PublicAssetManager\copy(), and ILIAS\Component\Resource\PublicAssetManager\makeDir().

Referenced by ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursively(), and ILIAS\Component\Resource\PublicAssetManager\copy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertInto()

ILIAS\Component\Resource\PublicAssetManager::insertInto ( array &  $assets,
array  $path,
PublicAsset  $asset 
)
protected

Definition at line 42 of file PublicAssetManager.php.

42 : void
43 {
44 $key = array_shift($path);
45 $key_exists = array_key_exists($key, $assets);
46 $target_reached = count($path) === 0;
47
48 if (!$key_exists && $target_reached) {
49 $assets[$key] = $asset;
50 return;
51 }
52
53 if (!$target_reached && (!$key_exists || is_array($assets[$key]))) {
54 if (!$key_exists) {
55 $assets[$key] = [];
56 }
57 $this->insertInto($assets[$key], $path, $asset);
58 return;
59 }
60
61 $first_asset = $assets[$key];
62 while (!$first_asset instanceof PublicAsset) {
63 $first_asset = array_shift($first_asset);
64 }
65
66 throw new \LogicException(
67 "There are (at least) two assets for the same target '{$asset->getTarget()}': " .
68 "'{$first_asset->getSource()}' and '{$asset->getSource()}'"
69 );
70 }
$path
Definition: ltiservices.php:30

References ILIAS\Component\Resource\PublicAssetManager\$assets, $path, and ILIAS\Component\Resource\PublicAssetManager\insertInto().

Referenced by ILIAS\Component\Resource\PublicAssetManager\addAssets(), and ILIAS\Component\Resource\PublicAssetManager\insertInto().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeDir()

ILIAS\Component\Resource\PublicAssetManager::makeDir ( string  $path)
protected

Definition at line 159 of file PublicAssetManager.php.

159 : void
160 {
161 if (!file_exists($path)) {
162 mkdir($path, 0755);
163 }
164 }

References $path.

Referenced by ILIAS\Component\Resource\PublicAssetManager\buildPublicFolder(), ILIAS\Component\Resource\PublicAssetManager\buildPublicFolderRecursively(), and ILIAS\Component\Resource\PublicAssetManager\copy().

+ Here is the caller graph for this function:

◆ purge()

ILIAS\Component\Resource\PublicAssetManager::purge ( string  $path,
array  $dont_purge 
)
protected

Definition at line 130 of file PublicAssetManager.php.

130 : bool
131 {
132 if (in_array($path, $dont_purge)) {
133 return false;
134 }
135
136 if (!file_exists($path)) {
137 return true;
138 }
139
140 if (is_file($path)) {
141 unlink($path);
142 return true;
143 }
144
145 if (is_dir($path)) {
146 $purged = true;
147 foreach (array_diff(scandir($path), ['.', '..']) as $item) {
148 $purged = $this->purge($path . "/" . $item, $dont_purge) && $purged;
149 }
150 if ($purged) {
151 rmdir($path);
152 }
153 return $purged;
154 }
155
156 throw new \LogicException("Don't know how to purge $path");
157 }

References $path, and ILIAS\Component\Resource\PublicAssetManager\purge().

Referenced by ILIAS\Component\Resource\PublicAssetManager\buildPublicFolder(), and ILIAS\Component\Resource\PublicAssetManager\purge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $assets

◆ DONT_PURGE

const ILIAS\Component\Resource\PublicAssetManager::DONT_PURGE = ["data", "Customizing"]

Definition at line 30 of file PublicAssetManager.php.

◆ REGEXP

const ILIAS\Component\Resource\PublicAssetManager::REGEXP = '%^(/\w+|\w+[\-.]\w+)+$%'

Definition at line 28 of file PublicAssetManager.php.


The documentation for this class was generated from the following file: